Undefined method `options' for #<EventMachine::HttpClien

Hi , I am writing a rake task to consume twitter stream API. The task
contains the following code:

consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, :site =>
http://twitter.com’)
access_token =
OAuth::AccessToken.new(consumer,ACCESS_TOKEN,ACCESS_TOKEN_SECRET)
oauth_params = {:consumer => consumer, :token => access_token}
EventMachine.run do
# now, let’s subscribe to twitter site stream
# check informaiton on twitter site
http =
EventMachine::HttpRequest.new(‘http://stream.twitter.com/1/statuses/sample.json’).get
oauth_helper = OAuth::Client::Helper.new(http, oauth_params)
http.options[:head] = (http.options[:head] ||
{}).merge!({“Authorization” => oauth_helper.header})
http.callback {
p http.response

  EventMachine.stop

}

The rake gets aborted with the following error:
undefined method options' for #<EventMachine::HttpClient:0x42cf9f0> D:/ROR/LOCAL_TWEETS/lib/tasks/twitter.rake:40:inblock in <top
(required)>’
D:/Ruby192/lib/ruby/gems/1.9.1/gems/eventmachine-1.0.0.beta.4.1-x86-mingw32/lib/
eventmachine.rb:179:in `call’

I am working on Windows 7, x64, and the gems I use are
em-http-request (1.0.0)
oauth (0.4.5)
eventmachine (1.0.0.beta.4.1)

Any ideas on how to resolve this ??

Quoting Anait M. [email protected]:

      # check informaiton on twitter site
     http =

EventMachine::HttpRequest.new(‘http://stream.twitter.com/1/statuses/sample.json’).get

      oauth_helper = OAuth::Client::Helper.new(http, oauth_params)
     http.options[:head] = (http.options[:head] ||

{}).merge!({“Authorization” => oauth_helper.header})
http.callback {
p http.response

  EventMachine.stop

}

Not sure what you are trying to accomplish here, I’m not familiar with
OAuth.
A couple of points. The htpp = …get statements makes the request, no
point
in altering the GET request after the fact. Perhaps you want something
like:

url = '…
headers = {‘Authorization’ => oauth_helper.header}
http = EventMachine::HttpRequest.new(url, :head => headers).get
http.callback {
p http.response
EventMachine.stop
}

HTH,
Jeffrey

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs