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

Mogli with latest httparty versions #150

Closed
sergiopatricio opened this issue May 16, 2014 · 2 comments
Closed

Mogli with latest httparty versions #150

sergiopatricio opened this issue May 16, 2014 · 2 comments

Comments

@sergiopatricio
Copy link

Using mogli with httparty version '>= 0.12.0' gives me the following error when using Mogli::Client.create_from_code_and_authenticator:

NoMethodError - undefined method 'has_key?' for #<String:0x007fb1e5b71c88>:
   .../mogli/lib/mogli/user.rb:11:in 'recognize?'
   .../mogli/lib/mogli/client.rb:235:in 'block in determine_class'
   .../mogli/lib/mogli/client.rb:235:in 'determine_class'
   .../mogli/lib/mogli/client.rb:214:in 'create_instance'
   .../mogli/lib/mogli/client.rb:209:in 'map_to_class'
   .../mogli/lib/mogli/client.rb:169:in 'map_data'
   .../mogli/lib/mogli/client.rb:153:in 'get_and_map'
   .../mogli/lib/mogli/model.rb:173:in 'find'

From my analysis the problem is caused because of the commit jnunemaker/httparty@b7d4e21 in httparty. Basically before this commit the response with content type text/javascript was parsed as json, and now with httparty version '>= 0.12.0' is parsed as plain text.
In lib/mogli/user.rb where it should have an hash it has a string with the hash inside, and this causes the error above.

One possible solution is to update the gemspec dependencies to limit httparty, With this https://github.com/sergiopatricio/mogli/tree/httparty-fix-dependency it works.

Another possible solution is to add :format=>:json to the line in https://github.com/mmangino/mogli/blob/master/lib/mogli/client.rb#L153 like this:

def get_and_map(path,klass=nil,body_args = {})
  data = self.class.get(api_path(path),:query=>default_params.merge(body_args),:format=>:json)

The problem here is that I don't know the consequences of this because get_and_map is used in a few places.
I only use mogli to make user posts so it's hard to see if anything breaks with this change.

Do you have an opinion on the best approach to solve this problem?

(Note: this may be related with #142)

@mmangino
Copy link
Owner

I vote for format json, but I’ll do whatever you recommend.

Mike

On May 16, 2014, at 1:52 PM, Sérgio Patrício [email protected] wrote:

Using mogli with httparty version '>= 0.12.0' gives me the following error when using Mogli::Client.create_from_code_and_authenticator:

NoMethodError - undefined method 'has_key?' for #String:0x007fb1e5b71c88:

.../mogli/lib/mogli/user.rb:11:in 'recognize?'

.../mogli/lib/mogli/client.rb:235:in 'block in determine_class'

.../mogli/lib/mogli/client.rb:235:in 'determine_class'

.../mogli/lib/mogli/client.rb:214:in 'create_instance'

.../mogli/lib/mogli/client.rb:209:in 'map_to_class'

.../mogli/lib/mogli/client.rb:169:in 'map_data'

.../mogli/lib/mogli/client.rb:153:in 'get_and_map'

.../mogli/lib/mogli/model.rb:173:in 'find'
From my analysis the problem is caused because of the commit jnunemaker/httparty@b7d4e21 in httparty. Basically before this commit the response with content type text/javascript was parsed as json, and now with httparty version '>= 0.12.0' is parsed as plain text.
In lib/mogli/user.rb where it should have an hash it has a string with the hash inside, and this causes the error above.

One possible solution is to update the gemspec dependencies to limit httparty, With this https://github.com/sergiopatricio/mogli/tree/httparty-fix-dependency it works.

Another possible solution is to add :format=>:json to the line in https://github.com/mmangino/mogli/blob/master/lib/mogli/client.rb#L153 like this:

def get_and_map(path,klass=nil,body_args = {})

data = self.class.get(api_path(path),:query=>default_params.merge(body_args),:format=>:json)
The problem here is that I don't know the consequences of this because get_and_map is used in a few places.
I only use mogli to make user posts so it's hard to see if anything breaks with this change.

Do you have an opinion on the best approach to solve this problem?

(Note: this may be related with #142)


Reply to this email directly or view it on GitHub.

@sergiopatricio
Copy link
Author

Forget this, I was using mogli '0.0.44'. With version '0.0.46' this was solved in 0ce0969

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