Skip to content

Commit

Permalink
Serialize to JSON when content type is set to JSON
Browse files Browse the repository at this point in the history
Until now, the request body is only serialized if it's a Hash.
But it could be an Array, or any other serializable type,
and those bodies are serialized. See #129, probably #141 as well.

I am not sure if this wouldn't break use cases where
the body is already expected to be serialized.
  • Loading branch information
Romain d'Alverny committed Aug 4, 2017
1 parent 9175995 commit 5ae25f8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/airborne/rest_client_requester.rb
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ def make_request(method, url, options = {})
res = if method == :post || method == :patch || method == :put
begin
request_body = options[:body].nil? ? '' : options[:body]
request_body = request_body.to_json if options[:body].is_a?(Hash)
request_body = request_body.to_json if is_json_request(headers)
RestClient.send(method, get_url(url), request_body, headers)
rescue RestClient::Exception => e
e.response
@@ -24,6 +24,10 @@ def make_request(method, url, options = {})

private

def is_json_request(headers)
headers.fetch(:content_type) == :json
end

def base_headers
{ content_type: :json }.merge(Airborne.configuration.headers || {})
end

0 comments on commit 5ae25f8

Please sign in to comment.