Gautam
Gautam

Reputation: 1812

undefined local variable or method `http' for main:Object Ruby

I have a header and url as specified below:

header = { 'User-Agent' => 'SubDB/1.0 (Subtitle-Downloader /1.0; https://github.com/gautamsawhney/Subtitle-Downloader)' }
url = "http://sandbox.thesubdb.com/?action=download&hash=" + hash + "&language=en"

I am try to send an HTTP get request using send_request method in ruby. I am basically trying to access the SubDB API. I have written the following code to send a request :

res = http.send_request('GET', url, header)
puts res.body

I have also done this require net/http , but I get this error

undefined local variable or method `http' for main:Object (NameError)

Can someone tell me what's wrong and if can I use any other method for the same? The inclusion of the header is necessary.

Upvotes: 0

Views: 2663

Answers (1)

Saravanan
Saravanan

Reputation: 509

In your example, You need to instantiate the Net::Http before using that

   http = Net::HTTP.new "sandbox.thesubdb.com"
   res = http.send_request("GET", "/?action=download....", nil, headers)

Upvotes: 2

Related Questions