试试这个 ruby 示例来使用日期过滤项目:
require 'rubygems'
require 'softlayer_api'
# Your SoftLayer API username.
SL_API_USERNAME = 'set me'
# Your SoftLayer API key.
SL_API_KEY = 'set me'
account_service = SoftLayer::Service.new('SoftLayer_Account',
:username => SL_API_USERNAME,
:api_key => SL_API_KEY)
begin
object_filter = SoftLayer::ObjectFilter.new
object_filter.set_criteria_for_key_path('invoices.createDate',
'operation' => 'betweenDate',
'options' => [{
'name' => 'startDate',
'value' => ["02/01/2014 0:0:0"]
},
{
'name' => 'endDate',
'value' => ["02/13/2014 0:0:0"]
}
]
)
result = account_service.object_filter(object_filter).getInvoices
puts result.inspect
rescue => e
$stdout.print(e.inspect)
end
一些参考资料:
https://github.com/softlayer/softlayer-ruby/blob/master/lib/softlayer/ObjectFilter.rb
https://www.omniref.com/ruby/gems/softlayer_api/3.0.b1/symbols/SoftLayer::ObjectFilter/set_criteria_for_key_path
https://coveralls.io/files/239537934
http://www.rubydoc.info/github/softlayer/softlayer-api-ruby-client/SoftLayer%2FObjectFilter%3Aset_criteria_for_key_path
https://github.com/softlayer/softlayer-ruby/issues/77
如果您仍在使用旧过滤器,可以尝试以下示例(但我建议更新 Softlayer ruby 客户端和 ruby 版本):
require 'rubygems'
require 'softlayer_api'
$SL_API_USERNAME = 'set me';
$SL_API_KEY = 'set me'
account_service = SoftLayer::Service.new('SoftLayer_Account',
:username => $SL_API_USERNAME,
:api_key => $SL_API_KEY)
begin
filter_instance = {
'invoices'=> {
'createDate'=> {
'operation'=> 'betweenDate',
'options'=> [
{
'name'=> 'startDate',
'value'=> [
'02/01/2014 0:0:0'
]
},
{
'name'=> 'endDate',
'value'=> [
'02/13/2014 0:0:0'
]
}
]
}
}
}
result = account_service.object_filter(filter_instance).getInvoices
puts result.inspect
rescue => e
$stdout.print(e.inspect)
end
我想在当前过滤器中使用更多过滤器条件,这是一个示例:
filter_instance = {
'invoices'=> {
'createDate'=> {
'operation'=> 'betweenDate',
'options'=> [
{
'name'=> 'startDate',
'value'=> [
'11/01/2015 0:0:0'
]
},
{
'name'=> 'endDate',
'value'=> [
'11/30/2015 23:59:59'
]
}
]
},
'typeCode'=> {
'operation'=> 'RECURRING'
}
}
}