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

Implement embedded object typing #23

Closed fancyremarker closed 10 years ago

fancyremarker commented 10 years ago

Hey @gamache! I'm interested in implementing automatic typing for embedded resources (in particular individual objects within a collection, much as you've done for response-level resources.

The existing approach of examining response headers (i.e., the type parameter of the Content-Type header) won't necessarily map well to the problem of typing embedded resources. Here I've somewhat arbitrarily chosen to examine the type field of each resource. It works for me, but I'd like to hear what you think is the most appropriate default for determining types of embedded resources.

Thanks!

gamache commented 10 years ago

Hi @fancyremarker! You have been busy lately! Thanks so much for your contributions.

I agree completely with the intent of this PR; supporting a type attribute is something I've been thinking about for a while. I am leaning toward implementing it differently, by turning HR.get_data_type_from_response into a more general HR.get_data_type method, which accepts a Faraday::Response, a HyperResource, or just a Hash. But I will definitely get this in for 0.9 (within the month), and I will leave this pull request open until I do.

Thanks again for submitting good features! Keep 'em coming! :)

fancyremarker commented 10 years ago

Thanks for the feedback, @gamache. I agree with the implementation you've suggested. What I've submitted here was more of a shortest-path hack.

Please let me know if I can help with any of the implementation.