0

我正在对 Plivo 进行 API 调用。我想遍历结果并将它们打印为 HTML。

以下红宝石代码:

user_key = 'my_key'
 params = { 'account' => user_key }
 response = p.get_cdrs(params)
 obj = response.last

工作,在萤火虫控制台,我得到一堆数据,其中的例子是:

["objects", [{"bill_duration"=>2, "billed_duration"=>60, "call_direction"=>"outbound", "call_duration"=>2, "call_uuid"=>"7f1db12e-5a7b-11e3-9c03-c7a22946c980", 
              "end_time"=>"2013-12-01 20:27:08+09:00", "from_number"=>"185258081345", "parent_call_uuid"=>"7e6225d0-5a7b-11e3-9bd4-c7a22946c980",
              "resource_uri"=>"/v1/Account/MAMTE4MTHJNJRKODBIMD/Call/7f1db12e-5a7b-11e3-9c03-c7a22946c980/", 
              "to_number"=>"sip:hechan131129083410@phone.plivo.com", "total_amount"=>"0.00300", "total_rate"=>"0.00300"},

现在,当我尝试使用

obj.each do |item|
    bill_duration = item["objects"][0]["call_direction"] 
    halt 200, {:bill_duration => bill_duration}.to_json
   end

我在 heroku 日志中收到“TypeError - 没有将字符串隐式转换为整数:”错误。我认为无论如何我的方法可能是错误的。基本上,如果我不尝试循环,我只会得到一条记录。我要他们所有。我该怎么做?谢谢。

4

0 回答 0