Class: Twitter::OAuth

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/twitter/oauth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctoken, csecret, options = {}) ⇒ OAuth

Options

:sign_in => true to just sign in with twitter instead of doing oauth authorization
            (http://apiwiki.twitter.com/Sign-in-with-Twitter)


12
13
14
15
16
17
# File 'lib/twitter/oauth.rb', line 12

def initialize(ctoken, csecret, options={})
  @ctoken, @csecret, @consumer_options = ctoken, csecret, {}
  if options[:sign_in]
    @consumer_options[:authorize_path] =  '/oauth/authenticate'
  end
end

Instance Attribute Details

#consumer_optionsObject (readonly)

Returns the value of attribute consumer_options.



7
8
9
# File 'lib/twitter/oauth.rb', line 7

def consumer_options
  @consumer_options
end

#csecretObject (readonly)

Returns the value of attribute csecret.



7
8
9
# File 'lib/twitter/oauth.rb', line 7

def csecret
  @csecret
end

#ctokenObject (readonly)

Returns the value of attribute ctoken.



7
8
9
# File 'lib/twitter/oauth.rb', line 7

def ctoken
  @ctoken
end

Instance Method Details

#access_tokenObject



43
44
45
# File 'lib/twitter/oauth.rb', line 43

def access_token
  @access_token ||= ::OAuth::AccessToken.new(consumer, @atoken, @asecret)
end

#authorize_from_access(atoken, asecret) ⇒ Object



47
48
49
# File 'lib/twitter/oauth.rb', line 47

def authorize_from_access(atoken, asecret)
  @atoken, @asecret = atoken, asecret
end

#authorize_from_request(rtoken, rsecret, verifier_or_pin) ⇒ Object

For web apps use params, for desktop apps, use the verifier is the pin that twitter gives users.



37
38
39
40
41
# File 'lib/twitter/oauth.rb', line 37

def authorize_from_request(rtoken, rsecret, verifier_or_pin)
  request_token = ::OAuth::RequestToken.new(consumer, rtoken, rsecret)
  access_token = request_token.get_access_token(:oauth_verifier => verifier_or_pin)
  @atoken, @asecret = access_token.token, access_token.secret
end

#consumerObject



19
20
21
# File 'lib/twitter/oauth.rb', line 19

def consumer
  @consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => 'http://api.twitter.com'}.merge(consumer_options))
end

#request_token(options = {}) ⇒ Object

Note: If using oauth with a web app, be sure to provide :oauth_callback. Options:

:oauth_callback => String, url that twitter should redirect to


31
32
33
# File 'lib/twitter/oauth.rb', line 31

def request_token(options={})
  @request_token ||= consumer.get_request_token(options)
end

#set_callback_url(url) ⇒ Object



23
24
25
26
# File 'lib/twitter/oauth.rb', line 23

def set_callback_url(url)
  clear_request_token
  request_token(:oauth_callback => url)
end