Question

I'm having a very difficult time trying to get HTTParty working. I'm on Ubuntu 12.10 and using Ruby 2.0.

I've bundled the HTTParty gem and am trying to test on the console but am getting a "NoMethod Error".

Loading development environment (Rails 3.2.13)

2.0.0-p353 :001 > require 'httparty'
 => false 

2.0.0-p353 :002 > httparty "http://twitter.com/statuses/public_timeline.json"
NoMethodError: undefined method `httparty' for main:Object
    from (irb):2
    from /home/kyle/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
    from /home/kyle/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
    from /home/kyle/.rvm/gems/ruby-2.0.0-p353/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

2.0.0-p353 :003 > 

What's going on here?

Was it helpful?

Solution

Looks like your syntax is incorrect.

The first step where you tried to require httparty seems to failed. You can use the require dependencies in console to get around this:

require_dependency 'httparty'

you should then see a return of true when it is successful

Then to exec Httparty commands you can use the following :

HTTParty.get(url, options_hash)

Example:

HTTParty.get('http://twitter.com/statuses/public_timeline.json', {})

#<HTTParty::Response:0x3a624e0 parsed_response={"error"=>"Could not authenticate you.", "request"=>"/statuses/public_timeline.json"},

...   

You may not need to load the dependency if you have the gem installed, you can probably just go right to the HTTParty class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top