class HomeAway::API::Adapters::FaradayAdapter
@private
Public Class Methods
call(site, opts, headers, method, uri, body, params)
click to toggle source
@private
# File lib/homeaway/api/adapters/faraday.rb, line 30 def self.call(site, opts, headers, method, uri, body, params) agent = Faraday::Connection.new(site, opts) do |conn| conn.headers = headers conn.adapter Faraday.default_adapter conn.options.params_encoder = Faraday::FlatParamsEncoder conn.use Faraday::HttpCache conn.use FaradayMiddleware::Mashify, :mash_class => HomeAway::API::Response conn.use FaradayMiddleware::ParseJson conn.use FaradayMiddleware::Instrumentation conn.use FaradayMiddleware::FollowRedirects end response = agent.send(method, uri) do |req| req.body = body.to_json unless body.empty? req.params = params unless params.empty? end self.transform response end
transform(response)
click to toggle source
@private
# File lib/homeaway/api/adapters/faraday.rb, line 49 def self.transform(response) mash = response.body mash = HomeAway::API::Response.new unless mash mash._metadata.headers = HomeAway::API::Response.new(response.headers.to_hash) if response.respond_to? :headers if response.respond_to? :status mash._metadata.status_code = response.status if mash._metadata.status_code.to_i >= 400 raise (HomeAway::API::Errors.for_http_code mash._metadata.status_code).new(mash) end end if response.respond_to? :env mash._metadata.request_headers = HomeAway::API::Response.new(response.env.request_headers.to_hash) if response.env.respond_to? :request_headers end mash end