gamache / hyperresource

A self-inflating Ruby client for hypermedia APIs. Not under active development.
http://hyperresource.com/doc
MIT License
304 stars 29 forks source link

Correctly pass headers to embedded objects #19

Closed fancyremarker closed 10 years ago

fancyremarker commented 10 years ago

The added test explains the problem case, but basically any headers set on the initial HyperResource object were not being passed to embedded objects. (Link objects got the headers just fine.)

I hit this when passing an OAuth 2.0 bearer token. It worked fine for link resources, but I was getting 401 Unauthorized for any embedded resources.

The situation affects other client headers, like Content-Type.

options = { headers: { 'Authorization' => "Bearer #{access_token}" } }
api = HyperResource.new(options)
api.get.things.get
# => (A-OK)
api.get.things.first.get
# !! HyperResource::ClientError: 401 (unauthorized)
gamache commented 10 years ago

This is wonderful. Great catch, and thanks for the patch!