martincho
martincho

Reputation: 4717

Ruby connect to REST service

I need to access a REST JSon Service. It's just connecting to an HTTPS using Basic authentication and performing some GETs and POSTs. This is a Ruby script running from a crontab.

These are the requirements:

Should I use HTTParty? I tried to install the gem and use it from irb with no luck. Apparently it has some dependencies. Should I go for other library like net/http?

If HTTParty is the way to go, can you please include some instructions on how to get it to work in an IRB console?

Upvotes: 1

Views: 1037

Answers (2)

Pedro Rolo
Pedro Rolo

Reputation: 29960

ActiveResource might do the trick in a more elegant way than HTTParty.

Upvotes: 1

Justin Herrick
Justin Herrick

Reputation: 3011

Whenever I am connecting to a REST/JSON/API or just a site directly I go for HTTParty / Merhanize / Nokogiri depending on what exactly I need to do with the site. I also would be sure to check Ruby Toolbox in their HTTPClient category for other popular gems.

>> require "httparty"
=> true
>> response = HTTParty.get("http://justinherrick.com/posts/what-it-means-to-stay-dry.json")
=> #<HTTParty::Response:0x104ceac70 @parsed_response={"slug"=>"what-it-means-to-stay-dry", "pubdate"=>"2012-02-06", "created_at"=>"2012-02-06T22:08:05+00:00", "category"=>"Programming", "title"=>"What it means to stay DRY", "body"=>"A very common and useful programming idiom...

Upvotes: 2

Related Questions