3

I' am trying to create a simple wrapper for skyscanner API. The problems is that when try to get the sessionKey, what I get is <HTTParty::Response:0x10 parsed_response=nil, @response=#<Net::HTTPUnsupportedMediaType 415 Unsupported Media Type readbody=true>. I am not sure what is that I am doing wrong. I am new to rails and I will appreciate any direction on how to solve this problem?. Thanks

require 'httparty'

class Skyscanner
  include HTTParty
  format :json

  base_uri "http://partners.api.skyscanner.net/apiservices/pricing"


    def self.find(originplace, destinationplace)

        @options = { query:
             {
                :apiKey => "API_KEY",
                :country => "US",
                :currency => "USD",
                :locale => "en-us",
                :adults => 1,
                :children => 0,
                :infants => 0,
                :originplace => originplacea,
                :destinationplace => destinationplace,
                :outbounddate => "2017-02-20",
                :inbounddate => "2017-02-27",
                :locationschema => "iata",
                :cabinclass => "Economy"
            }
        }

        @headers = { 'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json'}

        @sessionkey_request = HTTParty.post("http://partners.api.skyscanner.net/apiservices/pricing/v1.0/",:body => @options,:headers => @headers)

        puts @sessionkey_request.inspect

        @get_sessionkey = @sessionkey_request.headers['location']
        @sessionkey = @get_sessionkey.to_s().split('/').last
        puts @sessionkey.inspect
    end

end

If anyone have a better way of approaching this wrapper, please advice me on how to. Thanks

Jose CC
  • 865
  • 11
  • 24
  • Try changing the headers content-type to `'application/json'` – Mat Jan 19 '17 at 21:46
  • no luck. Thanks anyways – Jose CC Jan 19 '17 at 21:52
  • 1
    based on documentation in [here](https://skyscanner.github.io/slate/#flights-live-prices) I think you have mistake on options, put all parameters outside `query` key, and you have typo `apiKey` should be `apikey` – rails_id Jan 20 '17 at 01:26

0 Answers0