I’m trying to use this article: https://github.com/Licensario/licensario-rest-protocol/blob/master/rest-api.md#feature-usage
so I wrote:
## get request
feature_allocation_req = Net::HTTP::Get.new("/api/v1/users/external/#{user_id}/features/VIEW_TASKSed8e919e60/alloc?paymentPlanId=SUBSCRIPTI33dbf5e82a");
## add the headers
feature_allocation_req.add_field('ISV_API_KEY', 'bcffa3335a9068ab37ad51a68b4b47ea72f32a49c8f0b4f299a629edad04cdc3');
feature_allocation_req.add_field('ISV_API_SECRET', '14c990f3d4ee6354ee86fffdb057b3584f885c0d79cd3b354123e1b9acdc2227');
## start the get request
feature_allocation_result = nil
Net::HTTP.start("localhost", 3000) {|http|
feature_allocation_result = http.request(feature_allocation_req)
}
## print the number of the response (I got 200 - OK)
puts feature_allocation_result.code
## deserialize JSON objects
feature_allocation_parameters = Yajl::Parser.parse(feature_allocation_result.body);
total_parameter = feature_allocation_parameters["total"];
used_parameter = feature_allocation_parameters["used"];
available_parameter = feature_allocation_parameters["available"];
## print them
puts "***********************"
puts total_parameter, used_parameter, available_parameter
but it prints nothing. did I write something wrong? (I think that if I have a problem, the problem is found in the step of “deserialize JSON objects”, but I tried: JSON.parse and it doesn’t work also)..
any help appreciated.
The first thing I would try is to print value of
feature_allocation_result.body. That would allow me to determine whether the other party sends correct JSON and error is mine. Sometimes I was getting an HTML error page instead of JSON, because my request was wrong. Printingbodyhelps to clarify this.Now that you did it, we see that the service sends you valid JSON, but all values are nil.
Our parsing is alright (but it might as well not be, if it were any more complex). Anyway, now we have to find out why the service doesn’t send us data we expect.