Module: Chirpstream::Connect

Included in:
Chirpstream
Defined in:
lib/chirpstream/connect.rb

Defined Under Namespace

Classes: User

Instance Method Summary collapse

Instance Method Details

#get_connection(user, url, method, extras = nil) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/chirpstream/connect.rb', line 39

def get_connection(user, url, method, extras = nil)
  options = extras ? extras.merge(:timeout => 0) : {:timeout => 0}
  if user.oauth?
    request = EM::HttpRequest.new(url)
    request.send(method, options) do |client|
      twitter_oauth_consumer.sign!(client, twitter_oauth_access_token(user.access_token, user.access_secret))
    end
  else
    http = EM::HttpRequest.new(url).send(method, options.merge(:head => {'authorization' => [user.name, user.password]}))
  end
  
end

#twitter_oauth_access_token(token = nil, secret = nil) ⇒ Object



56
57
58
59
60
# File 'lib/chirpstream/connect.rb', line 56

def twitter_oauth_access_token(token=nil,secret=nil)
token ||= access_token
secret ||= access_secret
  @twitter_oauth_access_token ||= OAuth::AccessToken.new(twitter_oauth_consumer, token, secret)
end

#twitter_oauth_consumerObject



52
53
54
# File 'lib/chirpstream/connect.rb', line 52

def twitter_oauth_consumer
  @twitter_oauth_consumer ||= OAuth::Consumer.new(consumer_token, consumer_secret, :site => "http://twitter.com")
end