Parsing an object within an object

Hello,

I’m using ruby and the switchvox gem to pull data from an Asterisk box.
I’m having a little trouble with the response I get back for the
switchvox.callQueues.getCurrentStatus method call. I’m trying to pull
the waiting_callers info from the response (seen below in the response
as an object in the response object). No problem pulling the other info.
The gem requests and returns a json response. I’m not having much luck
accessing/parsing it. Am I missing something obvious?

Thanks so much

cq = switchvox.request(“switchvox.callQueues.getCurrentStatus”,
{“account_id”: “1390”})
puts cq.inspect

td@noc:~/ruby_workspace$ ruby voxtest.rb
#<Object:0x000000021322f0 @call_queue=#<Object:0x00000002132250
@extension=“651”, @strategy=“ring_all”, @account_id=“1390”,
@queue_members=#<Object:0x00000002131e18
@queue_member=[{“paused_time”=>“3516”, “completed_calls”=>“5”,
“paused_since”=>"", “talking_to_name”=>"", “login_type”=>“login”,
“order”=>“1”, “login_time”=>“28614”, “extension”=>“108”,
“max_talk_time”=>“988”, “time_of_last_call”=>“2015-04-01 03:59:47”,
“paused”=>“0”, “account_id”=>“1132”, “missed_calls”=>“0”,
“logged_in_status”=>“logged_off”, “fullname”=>“Employee X”,
“talking_to_number”=>"", “avg_talk_time”=>“344.20”},

]>, @waiting_callers=#Object:0x00000002190a58,
@call_queue_name=“Technical Support”>>

puts cw = cq.waiting_callers.inspect
#Object:0x00000002498818

Tony De wrote in post #1171386:

Hello,

I’m using ruby and the switchvox gem to pull data from an Asterisk box.
I’m having a little trouble with the response I get back for the
switchvox.callQueues.getCurrentStatus method call. I’m trying to pull
the waiting_callers info from the response (seen below in the response
as an object in the response object). No problem pulling the other info.
The gem requests and returns a json response. I’m not having much luck
accessing/parsing it. Am I missing something obvious?

This is parsed already. Why are you asking how to parse this?

Thanks so much

cq = switchvox.request(“switchvox.callQueues.getCurrentStatus”,
{“account_id”: “1390”})
puts cq.inspect

td@noc:~/ruby_workspace$ ruby voxtest.rb
#<Object:0x000000021322f0 @call_queue=#<Object:0x00000002132250
@extension=“651”, @strategy=“ring_all”, @account_id=“1390”,
@queue_members=#<Object:0x00000002131e18
@queue_member=[{“paused_time”=>“3516”, “completed_calls”=>“5”,
“paused_since”=>"", “talking_to_name”=>"", “login_type”=>“login”,
“order”=>“1”, “login_time”=>“28614”, “extension”=>“108”,
“max_talk_time”=>“988”, “time_of_last_call”=>“2015-04-01 03:59:47”,
“paused”=>“0”, “account_id”=>“1132”, “missed_calls”=>“0”,
“logged_in_status”=>“logged_off”, “fullname”=>“Employee X”,
“talking_to_number”=>"", “avg_talk_time”=>“344.20”},

]>, @waiting_callers=#Object:0x00000002190a58,
@call_queue_name=“Technical Support”>>

puts cw = cq.waiting_callers.inspect
#Object:0x00000002498818

It’s a bit difficult to decipher. You could try to output it like this:

require ‘pp’
pp cq

Maybe that gives a clearer picture because it prints nested structures
better than #inspect.

Hi, it’s only partially parsed… There’s an object in the “parsed”
json that I can’t access.

@waiting_callers=#Object:0x00000002190a58

]>, @waiting_callers=#Object:0x00000002190a58,
@call_queue_name=“Technical Support”>>

puts cw = cq.waiting_callers.inspect
#Object:0x00000002498818

Ok, I got a response from the Vendor on the API. The object that I
couldn’t parse needed to be accessed as follows. The @waiting_callers
object is sometimes returned as an Array or Hashes, a Hash, or an empty
Object. That’s messed up, but anyway…

Thanks again for your response…

count = cq.waiting_callers.waiting_caller.length