使用Ruby的Sofflayer Billing API-提取每个用户的账单详细信息



有关于Softlayer计费API的问题。当我试图运行API代码将数据提取到对象掩码中时,我收到一个错误,如下所示:

/Library/Ruby/Gems/2.0.0/Gems/softlayer_api-3.2.1/lib/softlayer/APIParameterFilter.rb:82:inobject_mask': object_mask expects strings (ArgumentError) from /Library/Ruby/Gems/2.0.0/gems/softlayer_api-3.2.1/lib/softlayer/Service.rb:156:inobject_mask'来自testAuthentication_old.rb:53:在`'

require 'softlayer_api'
require 'pp'
user_id = "your user id"
api_key = "your API key"
object_mask = {"orderItem" => {"order" => {"userRecord" => {"username" =>   ""}}},
"invoiceItem" => {"totalRecurringAmount" => ""}}
billing = SoftLayer::Service.new("SoftLayer_Account",:username => user_id,:api_key => api_key)
user_bill=billing.object_mask(object_mask).getNextInvoiceTopLevelBillingItems
pp user_bill
for item in user_bill do
if item.key?("orderItem") &&
item["orderItem"]["order"]["userRecord"]["username"] == ""
pp("User " + "" + " has an invoice item of " +
item["invoiceItem"]["totalRecurringAmount"].to_s())
end`

身份验证工作正常,但不知何故,它抱怨对象掩码。你能提供一些见解吗。在Softlayer上的另一篇帖子中提到了更改计费API。如果是,我是否需要以不同的方式定义对象遮罩?你能告诉我吗?如有任何帮助,我们将不胜感激。

Ruby的SoftLayer API似乎在object_mask中需要一个字符串,而不是这里指定的示例中显示的对象。

不管怎样,请试试这个口罩:

object_mask = "mask[orderItem[order[userRecord[username]]], invoiceItem[totalRecurringAmount]]"
billing = SoftLayer::Service.new("SoftLayer_Account",:username => user_id,:api_key => api_key)
user_bill=billing.object_mask(object_mask).getNextInvoiceTopLevelBillingItems

如果客户端不再支持其他掩码(对象类型),我会通知您。

最新更新