Use JSON result in query using Ruby, Sinatra and Posgresql -


i using ruby , plivo api create subaccount.

the code is:

auth_id = "my_id" auth_token = "my_token"  p = restapi.new(auth_id, auth_token) params = {'name' => 'thegreatone'} response = p.create_subaccount(params) 

// here fine , (without attempts below access json response) works , account created.

the json response :

[{"auth_token"=>"zjgxmgqwmty2ngy3nzk3zmm3zge3zmixmgqyzwyy",   "message"=>"created",   "api_id"=>"2c1eff4a-b955-11e2-8361-123141011ae6",   "auth_id"=>"samzbjogzkzdixmmexnj"}] 

i "extract" "auth_token" , "auht_id" can insert them database.

so have tried (among other things):

obj = json.parse(response) :user_key = obj['auth_token'] 

the message in terminal is:

syntax error, unexpected '=', expecting $end

:user_key = obj['auth_token'] 

how can extract these variables , pass them insert query?

i using postgres sequel, ruby , sinatra.

grateful help, thank you.

you're trying assign value symbol , response returns array:

obj = json.parse(response) :user_key = obj['auth_token']  

should be

obj = json.parse(response).first user_key = obj['auth_token']  

symbols not variables, constants.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -