class GiantClient::PatronAdapter
Public Instance Methods
normalize_response(response)
click to toggle source
# File lib/giant_client/patron_adapter.rb, line 30 def normalize_response(response) status_code = response.status headers = normalize_header_hash(response.headers) body = response.body Response.new(status_code, headers, body) end
request(method, opts)
click to toggle source
# File lib/giant_client/patron_adapter.rb, line 7 def request(method, opts) if BODYLESS_METHODS.include?(method) raise GiantClient::Error::NotImplemented unless opts[:body] == '' end url = url_from_opts(opts) http = Patron::Session.new http.timeout = opts[:timeout] http.connect_timeout = opts[:timeout] # TODO support all extra options extra_opts = {} extra_opts[:data] = opts[:body] begin response = http.request(method, url, opts[:headers], extra_opts) rescue Patron::TimeoutError raise GiantClient::Error::Timeout, "the request timed out (timeout: #{opts[:timeout]}" end normalize_response(response) end