Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在SoftLayer Ruby API中使用对象过滤器_Ruby_Ibm Cloud Infrastructure - Fatal编程技术网

在SoftLayer Ruby API中使用对象过滤器

在SoftLayer Ruby API中使用对象过滤器,ruby,ibm-cloud-infrastructure,Ruby,Ibm Cloud Infrastructure,当我尝试运行以下程序时,对象过滤器似乎不起作用。我仍然收到不符合筛选条件的发票。有人能帮我理解我做错了什么吗?不幸的是,在Ruby中几乎找不到使用对象过滤器的文档 提前谢谢 require 'rubygems' require 'softlayer_api' require 'pp' begin date = DateTime.new(2015,11,1) account_service = SoftLayer::Service.new("SoftLayer_Account",:use

当我尝试运行以下程序时,对象过滤器似乎不起作用。我仍然收到不符合筛选条件的发票。有人能帮我理解我做错了什么吗?不幸的是,在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

尝试以下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版本):

如果您想在当前筛选器中使用更多筛选器条件,以下是一个示例:

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'
          }
      }
  }

你使用的是什么版本的Ruby?自从Ruby1.9以来,我们就不必使用
require'rubygems'
。另外,不要捕获一般的
异常
,而是捕获特定的异常。有很多关于为什么的页面,但这是一个好的开始:mcruz,你知道为什么我每天运行这个时会收到多张发票吗?我得到的结果比我预期的多得多。谢谢。使用过滤器时,项目数量不应受到影响。我使用短距离执行了一些测试,效果很好。我建议您减少日期范围,以查看是否影响项目数量。例如,我的日期范围是:startDate='02/04/2014 0:0:0',endDate='02/04/2014 23:59:59'(1天),并使用此脚本和仅使用不带过滤器的“getInvoices”来验证值是否相同。你好,再次谢谢你。然而,我的问题可能太含糊了。我用你显示的过滤器打了电话,但我每天收到多张发票。类型代码为“新”或“一次性收费”。我不知道我为什么会看到这些。这是一份更详细的文件吗?老实说,我只是希望每月有一张发票。再次感谢你!我正在通过门户查看一些过滤器;我可以看到一些情况,过滤器在1个月的范围内检索到多个项目。当我们选择typeCode=“Recurrential”时,过滤器每月检索1个项目。您是否希望获取typeCode=“Recurrential”的项目?@haunm,我在上一个筛选器(typeCode=“Recurrential”)中添加了其他筛选器条件:
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'
          }
      }
  }