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

create_json (err): undefined method `each' #9

Open
johanoskarsson opened this issue Feb 26, 2012 · 3 comments
Open

create_json (err): undefined method `each' #9

johanoskarsson opened this issue Feb 26, 2012 · 3 comments

Comments

@johanoskarsson
Copy link

Hi.

I'm using this gem to create playlists on Rdio. It works fine, the playlist is created correctly, but it does throw an error.

This is the error and stacktrace. I've removed some keys in the json just in case.

create_json (err): undefined method each' for "Johan Oskarsson":String create_json (str): {"status": "ok", "result": {"key": "...", "ownerKey": "...", "name": "Playlistify", "url": "/people/skr/playlists/611945/Playlistify/", "ownerIcon": "user/no-user-image-square.jpg", "owner": "Johan Oskarsson", "lastUpdated": 1330325975.0, "shortUrl": "http://rd.io/x/QFrCL0oJOw", "length": 50, "baseIcon": "album/b/9/5/000000000014f59b/square-200.jpg", "ownerUrl": "/people/skr/", "embedUrl": "http://rd.io/e/QFrCL0oJOw", "type": "p", "icon": "http://m.rdio.com/_is/?aid=237792,147201,216482,153219,23076,80461,221456,220187,4443&w=200&h=200"}} /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:152:infill'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:171:in block in fill' /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:152:ineach'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:152:in fill' /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:321:infill_obj'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:373:in _create_object' /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:327:increate_object'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:309:in return_object' /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/api.rb:57:increatePlaylist'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/types.rb:356:in create' /Users/johan/Dev/playlistify/lib/targets/rdio_target.rb:19:inadd_tracks'

The code used is something like this
r_tracks = tracks.map { |track| Rdio::Track.search(track[:artist] + " " + track[:track],nil,['name']).first }
if (!r_tracks.empty?)
pl = Rdio::Playlist.create("Playlistify","Description...", r_tracks)
end

@spudtrooper
Copy link
Owner

Change line 163 of base.rb:

if type

to

if type and (v.is_a? Array or v.is_a? Hash)

to make sure that the JSON used to create an ApiObj is an array or
hash. This is a little messy, but give it a try with whatever you
were doing before and let me know if this does it.

Jeff

On Sun, Feb 26, 2012 at 6:14 PM, Johan Oskarsson
[email protected]
wrote:

Hi.

I'm using this gem to create playlists on Rdio. It works fine, the playlist is created correctly, but it does throw an error.

This is the error and stacktrace. I've removed some keys in the json just in case.

create_json (err): undefined method each' for "Johan Oskarsson":String create_json (str): {"status": "ok", "result": {"key": "...", "ownerKey": "...", "name": "Playlistify", "url": "/people/skr/playlists/611945/Playlistify/", "ownerIcon": "user/no-user-image-square.jpg", "owner": "Johan Oskarsson", "lastUpdated": 1330325975.0, "shortUrl": "http://rd.io/x/QFrCL0oJOw", "length": 50, "baseIcon": "album/b/9/5/000000000014f59b/square-200.jpg", "ownerUrl": "/people/skr/", "embedUrl": "http://rd.io/e/QFrCL0oJOw", "type": "p", "icon": "http://m.rdio.com/_is/?aid=237792,147201,216482,153219,23076,80461,221456,220187,4443&w=200&h=200"}} /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:152:infill'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:171:in block in fill' /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:152:ineach'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:152:in fill' /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:321:infill_obj'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:373:in _create_object' /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:327:increate_object'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:309:in return_object' /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/api.rb:57:increatePlaylist'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/types.rb:356:in create' /Users/johan/Dev/playlistify/lib/targets/rdio_target.rb:19:inadd_tracks'

The code used is something like this
r_tracks = tracks.map { |track| Rdio::Track.search(track[:artist] + " " + track[:track],nil,['name']).first }
if (!r_tracks.empty?)
 pl = Rdio::Playlist.create("Playlistify","Description...", r_tracks)
end


Reply to this email directly or view it on GitHub:
#9

Jeffrey Palm --> http://jeffpalm.com

@spudtrooper
Copy link
Owner

If you have this installed from the gem you couldn't make this
change...duh. You could do the following after requiring the gem:

Rdio::symbols_to_types[:owner] = nil

This will ensure that we don't try to create a User object from JSON
objects with keys "owner". It could solve your problem. Again, let
me know. I'll look into further and see if it's causing more problems
and include the correct fix in the next release.

Jeff

On Sun, Feb 26, 2012 at 6:14 PM, Johan Oskarsson
[email protected]
wrote:

Hi.

I'm using this gem to create playlists on Rdio. It works fine, the playlist is created correctly, but it does throw an error.

This is the error and stacktrace. I've removed some keys in the json just in case.

create_json (err): undefined method each' for "Johan Oskarsson":String create_json (str): {"status": "ok", "result": {"key": "...", "ownerKey": "...", "name": "Playlistify", "url": "/people/skr/playlists/611945/Playlistify/", "ownerIcon": "user/no-user-image-square.jpg", "owner": "Johan Oskarsson", "lastUpdated": 1330325975.0, "shortUrl": "http://rd.io/x/QFrCL0oJOw", "length": 50, "baseIcon": "album/b/9/5/000000000014f59b/square-200.jpg", "ownerUrl": "/people/skr/", "embedUrl": "http://rd.io/e/QFrCL0oJOw", "type": "p", "icon": "http://m.rdio.com/_is/?aid=237792,147201,216482,153219,23076,80461,221456,220187,4443&w=200&h=200"}} /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:152:infill'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:171:in block in fill' /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:152:ineach'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:152:in fill' /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:321:infill_obj'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:373:in _create_object' /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:327:increate_object'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/base.rb:309:in return_object' /usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/api.rb:57:increatePlaylist'
/usr/local/rvm/gems/ruby-1.9.2-p290/gems/rdio-0.0.96/lib/rdio/types.rb:356:in create' /Users/johan/Dev/playlistify/lib/targets/rdio_target.rb:19:inadd_tracks'

The code used is something like this
r_tracks = tracks.map { |track| Rdio::Track.search(track[:artist] + " " + track[:track],nil,['name']).first }
if (!r_tracks.empty?)
 pl = Rdio::Playlist.create("Playlistify","Description...", r_tracks)
end


Reply to this email directly or view it on GitHub:
#9

Jeffrey Palm --> http://jeffpalm.com

@johanoskarsson
Copy link
Author

I tried out the last fix you mentioned (symbols_to_types..) and that fixed the issue! Thanks for the extremely speedy reply and thanks for the gem, very useful.

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

2 participants