The Real Adam Master of rectangles

Posted
30 July 2008 @ 7am

In
Code, Tumblin'

HTTP wrappers with ease

httparty looks really cool. It’s a little library for making writing tiny REST clients easier. From the examples (edited for length):

  1. class Twitter
  2.   include HTTParty
  3.   base_uri 'twitter.com'
  4.  
  5.   def initialize(user, pass)
  6.     self.class.basic_auth user, pass
  7.   end
  8.  
  9.   # which can be :friends, :user or :public
  10.   # options[:query] can be things like since, since_id, count, etc.
  11.   def timeline(which=:friends, options={})
  12.     self.class.get("/statuses/#{which}_timeline.xml", options)['statuses'].map { |s| s.to_struct }
  13.   end
  14. end
  15.  
  16. twitter = Twitter.new('bob@example.com', 'bobtime')
  17.  
  18. twitter.timeline.each do |s|
  19.   puts s.user.name, s.text, "#{s.created_at} #{s.id}", ''
  20. end

Great job, John!


1 Comment

Posted by
John nunemaker
30 July 2008 @ 6pm

Thanks! I thought it was cool but I’m amazed by the community response. Evidentally everyone was feeling the pain I was. :)


Leave a Comment

Comments will be sent to the moderation queue.

Agility course made of people House on water

Flickr View All » FredRubyConf Notes #3RubyConf Notes #2RubyConf Notes #1RubyConf Notes #0Dogs in the morningMy Day, YesterdayGetting aroundMolly lounging