Class: Twitter::OAuth
- Inherits:
-
Object
- Object
- Twitter::OAuth
- Extended by:
- Forwardable
- Defined in:
- lib/twitter/oauth.rb
Instance Attribute Summary collapse
-
#api_endpoint ⇒ Object
readonly
Returns the value of attribute api_endpoint.
-
#consumer_options ⇒ Object
readonly
Returns the value of attribute consumer_options.
-
#csecret ⇒ Object
readonly
Returns the value of attribute csecret.
-
#ctoken ⇒ Object
readonly
Returns the value of attribute ctoken.
-
#signing_endpoint ⇒ Object
readonly
Returns the value of attribute signing_endpoint.
Instance Method Summary collapse
- #access_token ⇒ Object
- #authorize_from_access(atoken, asecret) ⇒ Object
-
#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.
- #consumer ⇒ Object
-
#initialize(ctoken, csecret, options = {}) ⇒ OAuth
constructor
Options :sign_in => true to just sign in with twitter instead of doing oauth authorization (apiwiki.twitter.com/Sign-in-with-Twitter).
-
#request_token(options = {}) ⇒ Object
Note: If using oauth with a web app, be sure to provide :oauth_callback.
- #set_callback_url(url) ⇒ Object
- #signing_consumer ⇒ Object
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 18 19 |
# File 'lib/twitter/oauth.rb', line 12 def initialize(ctoken, csecret, ={}) @ctoken, @csecret, @consumer_options = ctoken, csecret, {} @api_endpoint = [:api_endpoint] || 'http://api.twitter.com' @signing_endpoint = [:signing_endpoint] || 'http://api.twitter.com' if [:sign_in] @consumer_options[:authorize_path] = '/oauth/authenticate' end end |
Instance Attribute Details
#api_endpoint ⇒ Object (readonly)
Returns the value of attribute api_endpoint.
7 8 9 |
# File 'lib/twitter/oauth.rb', line 7 def api_endpoint @api_endpoint end |
#consumer_options ⇒ Object (readonly)
Returns the value of attribute consumer_options.
7 8 9 |
# File 'lib/twitter/oauth.rb', line 7 def @consumer_options end |
#csecret ⇒ Object (readonly)
Returns the value of attribute csecret.
7 8 9 |
# File 'lib/twitter/oauth.rb', line 7 def csecret @csecret end |
#ctoken ⇒ Object (readonly)
Returns the value of attribute ctoken.
7 8 9 |
# File 'lib/twitter/oauth.rb', line 7 def ctoken @ctoken end |
#signing_endpoint ⇒ Object (readonly)
Returns the value of attribute signing_endpoint.
7 8 9 |
# File 'lib/twitter/oauth.rb', line 7 def signing_endpoint @signing_endpoint end |
Instance Method Details
#access_token ⇒ Object
49 50 51 |
# File 'lib/twitter/oauth.rb', line 49 def access_token @access_token ||= ::OAuth::AccessToken.new(signing_consumer, @atoken, @asecret) end |
#authorize_from_access(atoken, asecret) ⇒ Object
53 54 55 |
# File 'lib/twitter/oauth.rb', line 53 def (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.
43 44 45 46 47 |
# File 'lib/twitter/oauth.rb', line 43 def (rtoken, rsecret, verifier_or_pin) request_token = ::OAuth::RequestToken.new(signing_consumer, rtoken, rsecret) access_token = request_token.get_access_token(:oauth_verifier => verifier_or_pin) @atoken, @asecret = access_token.token, access_token.secret end |
#consumer ⇒ Object
21 22 23 |
# File 'lib/twitter/oauth.rb', line 21 def consumer @consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => api_endpoint}.merge()) 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
37 38 39 |
# File 'lib/twitter/oauth.rb', line 37 def request_token(={}) @request_token ||= signing_consumer.get_request_token() end |
#set_callback_url(url) ⇒ Object
29 30 31 32 |
# File 'lib/twitter/oauth.rb', line 29 def set_callback_url(url) clear_request_token request_token(:oauth_callback => url) end |
#signing_consumer ⇒ Object
25 26 27 |
# File 'lib/twitter/oauth.rb', line 25 def signing_consumer @signing_consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => signing_endpoint, :request_endpoint => api_endpoint }.merge()) end |