stack1
stack1

Reputation: 1022

syntax error - unexpected tASSOC

I am trying to learn some ruby http request response code from this tutorial -

http://danknox.github.io/2013/01/27/using-rubys-native-nethttp-library/

Code so far -

require "net/http"
require "uri"

uri = URI.parse("http://api.random.com")
http = Net::HTTP.new(uri.host, uri.port)

# Continuing our example from above

request = Net::HTTP::Get.new("/search?question=somequestion")
response = http.request(request)

response.code
=>"200"
response.body
=> # Raw response body would go here needing to be parsed

error -

Test.rb:13: syntax error, unexpected tASSOC, expecting $end
=> "200"
  ^

I don't know why this happens. I removed the space and the error remains. I saw 3-4 Stack overflow posts on this, but they did not help.

Upvotes: 0

Views: 931

Answers (1)

David Grayson
David Grayson

Reputation: 87386

You should comment out the two lines in your code that start with =>. Those are meant to be comments explaining what the return value of the method should be, but somehow they got uncommented and the Ruby interpreter tried to parse them as code.

puts response.code  # => "200"
puts repsonse.body  # => Raw response body

Upvotes: 1

Related Questions