lib/frenchy/client.rb in frenchy-0.5.2 vs lib/frenchy/client.rb in frenchy-0.6.0
- old
+ new
@@ -49,11 +49,11 @@
def perform(method, path, params)
uri = URI(@host)
body = nil
headers = {
"User-Agent" => "Frenchy/#{Frenchy::VERSION}",
- "Accept" => "application/json",
+ "Accept" => Frenchy.accept_header,
}.merge(@headers)
# Set the URI path
uri.path = URI.encode(path)
@@ -101,11 +101,11 @@
# Return based on response
case resp.code.to_i
when 200...399
# Positive responses are expected to return JSON
begin
- JSON.parse(resp.body)
+ decode_response(resp)
rescue => ex
raise Frenchy::InvalidResponse.new(ex, reqinfo, resp)
end
when 400
# Explicitly handle bad request errors
@@ -122,8 +122,12 @@
end
end
def perform_request(http, req)
http.request(req)
+ end
+
+ def decode_response(resp)
+ Frenchy.find_content_type_handler(resp["Content-Type"]).call(resp.body)
end
end
end