Parsing a user object



I just started the twitter api I dont understand at all what they want me to do in lesson 2. I have literally no idea where to start, it feels like I missed some lessons, but I haven't. What do I need to do in lesson 2, could anybody fix my code?
This is also my first time using an api, so that might explain everything.
below is the unedited code from the exercise.

require 'rubygems'
require 'oauth'

Parse a response from the API and return a user object.

def parse_user_response(response)
user = nil

# Check for a successful request
if response.code == '200'
# Parse the response body, which is in JSON format.
user =

# Pretty-print the user object to see what data is available.
puts "Hello, #{user["screen_name"]}!"

# There was an error issuing the request.
puts "Expected a response of 200 but got #{response.code} instead"


All requests will be sent to this server.

baseurl = ""

Verify credentials returns the current user in the body of the response.

address = URI("#{baseurl}/1.1/account/verify_credentials.json")

Set up HTTP.

http =, address.port
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER

If you entered your credentials in the previous

exercise, no need to enter them again here. The

||= operator will only assign these values if

they are not already set.

consumer_key ||= "ENTER IN EXERCISE 1", ""
access_token ||= "ENTER IN EXERCISE 1", ""

Issue the request.

request = address.request_uri
request.oauth! http, consumer_key, access_token
response = http.request(request)
user = parse_user_response(response)


Before 'playing' around with an Application Progammable Interface
i would suggest to at least go through
for you to have a 'clue'
of what you are getting into......


Thanks, where did you find this course? I don't see it when browsing their main page.
(trying to find out if there are maybe more courses I can learn from)


How do I assign the parsed response to the user variable? I'm having problems figuring out that bit.
Help is appreciated. Thank you


Apparently all I had to do was:

user = JSON.parse(response.body)

That fixed the problem!