0

当我尝试运行以下程序时,对象过滤器似乎不起作用。我仍然收到不符合过滤条件的发票。有人可以帮我理解我做错了什么吗?不幸的是,我几乎找不到关于在 Ruby 中使用对象过滤器的文档

提前致谢

require 'rubygems'
require 'softlayer_api'
require 'pp'

begin
  date = DateTime.new(2015,11,1)
  account_service = SoftLayer::Service.new("SoftLayer_Account",:username => "USER", :api_key => "KEY", :timeout => 999)
  latest_invoices = account_service.result_limit(0,10).object_mask("mask[id]").getInvoices(filter={'invoices'=> {'createDate'=> {'>='=> date}}})
  pp latest_invoices

rescue Exception => exception
  puts "Unable to retrieve the invoice #{exception}"
end
4

1 回答 1

0

试试这个 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'
          }
      }
  }
于 2015-12-09T19:19:52.800 回答