views:

22

answers:

2

Forgive me if this is a really stupid question, but how do I get individual items from a JSON GET with HTTParty? For example:

require 'rubygems'
require 'httparty'
require 'pp'

player = pp HTTParty.get('http://api.dribbble.com/players/1')

will return this:

{"name"=>"Dan Cederholm",
 "avatar_url"=>
  "http://dribbble.com/system/users/1/avatars/thumb/dancederholm-peek.jpg?1261060245",
 "twitter_screen_name"=>"simplebits",
 "shots_count"=>148,
 "location"=>"Salem, MA",
 "created_at"=>"2009/07/07 21:51:22 -0400",
 "following_count"=>375,
 "draftees_count"=>103,
 "url"=>"http://dribbble.com/players/simplebits",
 "id"=>1,
 "followers_count"=>2119,
 "drafted_by_player_id"=>nil}

How do I get an individual item, like, say the name?

A: 

player.name seems like a most natural thing to try. And in general, you can check player.class to determine result type.

Nikita Rybak
+1  A: 
player["name"]

The returned object is a Hash

Chubas
Worked perfectly, thanks a lot.
Ethan Turkeltaub