3

我正在尝试为 skyscanner API 创建一个简单的包装器。问题是当尝试获取 sessionKey 时,我得到的是<HTTParty::Response:0x10 parsed_response=nil, @response=#<Net::HTTPUnsupportedMediaType 415 Unsupported Media Type readbody=true>. 我不确定我做错了什么。我是 Rails 新手,我会很感激如何解决这个问题的任何方向?谢谢

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

如果有人有更好的方法来处理这个包装器,请告诉我如何去做。谢谢

4

0 回答 0