Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON-API representer does not work with Roar::Client #119

Closed
ekosz opened this issue Jan 6, 2015 · 2 comments
Closed

JSON-API representer does not work with Roar::Client #119

ekosz opened this issue Jan 6, 2015 · 2 comments

Comments

@ekosz
Copy link

ekosz commented Jan 6, 2015

Given the code

module SongsRepresenter
  include Roar::JSON::JSONAPI
  type :songs

  property :id
  property :name
end

class Song < OpenStruct
  include Roar::JSON::JSONAPI
  include SongRepresenter
  include Roar::Client
end

When I run

Song.new.get(uri: 'http://example.com/songs/1', as: 'application/json')

I get the error

NoMethodError: undefined method `deserialize' for #<Song>
    from /roar-1.0.0/lib/roar/http_verbs.rb:65:in `handle_response'
    from /roar-1.0.0/lib/roar/http_verbs.rb:40:in `get'

I then tried replacing Roar::JSON::JSONAPI with Roar::JSON in the client (as it does have #deserialize there) but I then got this error instead:

TypeError: no implicit conversion of String into Integer
    from /roar-1.0.0/lib/roar/json/json_api.rb:45:in `[]'
    from /roar-1.0.0/lib/roar/json/json_api.rb:45:in `from_hash'
    from /roar-1.0.0/lib/roar/json/json_api.rb:126:in `from_hash'
    from /representable-2.1.3/lib/representable/json.rb:30:in `from_json'
    from /roar-1.0.0/lib/roar/json.rb:21:in `from_json'
    from /roar-1.0.0/lib/roar/json.rb:30:in `deserialize'
    from /roar-1.0.0/lib/roar/http_verbs.rb:65:in `handle_response'
    from /roar-1.0.0/lib/roar/http_verbs.rb:40:in `get'

As an aside, I also noticed the current README is out of date in a few locations regarding JSON-API. For example the README refers to the JSON-API module as Roar::JSON::JsonApi but in the source its Roar::JSON::JSONAPI.

@ekosz ekosz changed the title JSON-API representer does not work with Client side JSON-API representer does not work with Roar::Client Jan 6, 2015
@apotonick
Copy link
Member

@ekosz Can you add a test to client_test.rb? What happens if you include Roar::JSON and then Roar::JSON::JSONAPI?

Feel free to PR fixed README, that would be greatly appreciated! ❤️

@myabc
Copy link
Contributor

myabc commented Dec 10, 2016

This issue was moved to trailblazer/roar-jsonapi#15

@myabc myabc closed this as completed Dec 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants