Closed steveklabnik closed 11 years ago
@steveklabnik It looks like an array is returned from https://api-sandbox.foxycart.com/ where a hash is expected.
Hence you're missing the required header, it should be:
api = HyperResource.new(root: "https://api-sandbox.foxycart.com/", headers: {'FOXYCART-API-VERSION' => '1'})
root = api.get
root.response_body # => {"_links"=>{"self"=>{"href"=>"https://api-sandbox.foxycart.com/", "title"=>"Your API starting point."}, "https://api.foxycart.com/rels/property_helpers"=>{"href"=>"https://api-sandbox.foxycart.com/property_helpers", "title"=>"Various helpers used for determing valid property values."}, "https://api.foxycart.com/rels"=>{"href"=>"https://api-sandbox.foxycart.com/rels", "title"=>"Custom Link Relationships supported by this API."}, "https://api.foxycart.com/rels/create_client"=>{"href"=>"https://api-sandbox.foxycart.com/clients", "title"=>"Create a client via POST."}, "https://api.foxycart.com/rels/token"=>{"href"=>"https://api-sandbox.foxycart.com/token", "title"=>"The OAuth endpoint for obtaining a new access_token using an existing refresh_token. Post www-form-url-encoded data as follows: grant_type=refresh_token&refresh_token={refresh_token}&client_id={client_id}&client_secret={client_secret}", "type"=>"application/json"}}, "message"=>"Welcome to the FoxyCart API! Our hope is to be as self-documenting and RESTful as possible. Please let us know if you have any questions by posting in our forum http://forum.foxycart.com or emailing us at helpdesk@foxycart.com. As a last resort, you could read the documentation at http://wiki.foxycart.com. Your first action should be to create an OAuth Client, then a user, followed by a store."}
Either way, it should raise if the response is not as expected.
Yes, right now error handling is nonexistent! I have some response code handling logic I'd like to push up later this week. I'll leave this issue open until I do.
Thanks for the eyes!
I added code to raise HR::ClientError or HR::ServerError, each of which is a HR::ResponseError subclass, upon 4xx/5xx errors. Closing this issue, thanks @steveklabnik and @pi3r!
I don't have time to investigate further right now, but