0

I am making an API call to Plivo. I would like to loop through the results and print them out as HTML.

The following ruby code:

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

works and, in the firebug console, I get a bunch of data, example of which is:

["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"},

Now when I try to loop though the data with

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

I get "TypeError - no implicit conversion of String into Integer:" error in heroku logs. I think my approach may be wrong anyway. Basically, if I don't try to loop, I just get one record. I want them all. How can I do it? Thanks.

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
user1903663
  • 1,713
  • 2
  • 22
  • 44

0 Answers0