How to retrieve Session key from Skyscanner API post request - Ruby -
in app want fetch live price flight details have used skyscanner api. have read documentation before obtained data have create live pricing service session. can created post request api , provide sessionkey
using sessionkey
, apikey
can retrived data. how can sessionkey understood must provided api server.
here try:
require 'json' require 'net/http' require 'uri' post_params = { :apikey => "[api_key]", :country => "gb", :currency => "gbp", :locale => "en-gb", :adults =>1, :children => 0, :infants => 0, :originplace => '11235', :destinationplace => '13554', :outbounddate => '2015-05-19', :inbounddate => '2015-05-26', :locationschema => 'default', :cabinclass => 'economy', :grouppricing => true } sessionkey_request = net::http.post_form(uri.parse('http://partners.api.skyscanner.net/apiservices/pricing/v1.0'), post_params ) get_data= "http://partners.api.skyscanner.net/apiservices/pricing/v1.0/?apikey=[api_key]" puts sessionkey_request.inspect temp = net::http.get_response(uri.parse(get_data)).body # puts temp
in console
<net::httpcreated 201 created readbody=true> # sessionkey_request.inspect
not getting sessionkey in response without can not retrieved data. please guide me mistake. appreciate solution.
fore more details , live result check demo api
note: have check gem 'skyscanner ' doesn't provide method live price. provide browse cache methods.
as per doc:
a successful response contains no content. url poll booking details specified in location header of response
so try this:
sessionkey_request["location"]
i have test on system , returns me:
http://partners.api.skyscanner.net/apiservices/pricing/v1.0/8e28260becd3441ca4e865396e224e7d_ecilpojl_ec71481935cebb7eaf661bc24940d01d
last part sessionkey
can use get
request. if want last part(sessionkey) can retrieved by:
> url = "http://partners.api.skyscanner.net/apiservices/pricing/v1.0/8e28260becd3441ca4e865396e224e7d_ecilpojl_ec71481935cebb7eaf661bc24940d01d" > url.split('/').last => "8e28260becd3441ca4e865396e224e7d_ecilpojl_ec71481935cebb7eaf661bc24940d01d"
Comments
Post a Comment