Skip to content

Commit

Permalink
mattmueller#79 Include x-headers in response hash
Browse files Browse the repository at this point in the history
  • Loading branch information
davetapley committed Jun 2, 2014
1 parent 2d15448 commit 0c8e1b8
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lib/foursquare2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def api_url

def return_error_or_body(response, response_body)
if response.body.meta.code == 200
response_body['x-headers'] = response.headers.select { |k,v| k.to_s.match(/^x-.*/) }
response_body
else
raise Foursquare2::APIError.new(response.body.meta, response.body.response)
Expand Down

1 comment on commit 0c8e1b8

@mattmueller
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the really late response on this. Something feels wrong about adding the headers in to this particular helper and tacking them on to the supposed body.

Two changes come to mind off the top of my head that could be implemented here to give you access to the headers:

  • We could do away with this helper generally and instead return either the full response object or an instance of Foursquare2::APIError. This has the downside of requiring more traversal of the response object for the integrator but gives complete transparency in to the response returned (unless it is not a 200)
  • We could return a hash that includes a formatted_body (the equivalent of the current response_body) as well as a raw_response (the complete raw response data). This would still allow for less traversal as the current method does but also give access to the full raw response for usecases like this one.

What do you think? I'm happy to help tag team this with you.

Please sign in to comment.