Class: Twitter::OAuth
- Inherits:
-
Object
- Object
- Twitter::OAuth
- Defined in:
- lib/twitter/oauth.rb
Instance Attribute Summary collapse
-
#api_endpoint ⇒ Object
readonly
Returns the value of attribute api_endpoint.
-
#api_version ⇒ Object
readonly
Returns the value of attribute api_version.
-
#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
- #delete(path, headers = nil) ⇒ Object
- #get(path, headers = nil) ⇒ 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).
- #post(path, data = nil, headers = nil) ⇒ Object
- #put(path, data = nil, headers = nil) ⇒ Object
-
#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)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/twitter/oauth.rb', line 26 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 [:api_version] @api_version = "/#{[:api_version].to_s}" else @api_version = '' end 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.
21 22 23 |
# File 'lib/twitter/oauth.rb', line 21 def api_endpoint @api_endpoint end |
#api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
21 22 23 |
# File 'lib/twitter/oauth.rb', line 21 def api_version @api_version end |
#consumer_options ⇒ Object (readonly)
Returns the value of attribute consumer_options.
21 22 23 |
# File 'lib/twitter/oauth.rb', line 21 def @consumer_options end |
#csecret ⇒ Object (readonly)
Returns the value of attribute csecret.
21 22 23 |
# File 'lib/twitter/oauth.rb', line 21 def csecret @csecret end |
#ctoken ⇒ Object (readonly)
Returns the value of attribute ctoken.
21 22 23 |
# File 'lib/twitter/oauth.rb', line 21 def ctoken @ctoken end |
#signing_endpoint ⇒ Object (readonly)
Returns the value of attribute signing_endpoint.
21 22 23 |
# File 'lib/twitter/oauth.rb', line 21 def signing_endpoint @signing_endpoint end |
Instance Method Details
#access_token ⇒ Object
70 71 72 |
# File 'lib/twitter/oauth.rb', line 70 def access_token @access_token ||= ::OAuth::AccessToken.new(signing_consumer, @atoken, @asecret) end |
#authorize_from_access(atoken, asecret) ⇒ Object
74 75 76 |
# File 'lib/twitter/oauth.rb', line 74 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.
64 65 66 67 68 |
# File 'lib/twitter/oauth.rb', line 64 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
42 43 44 |
# File 'lib/twitter/oauth.rb', line 42 def consumer @consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => api_endpoint}.merge()) end |
#delete(path, headers = nil) ⇒ Object
4 5 6 |
# File 'lib/twitter/oauth.rb', line 4 def delete(path, headers=nil) access_token.delete(*[api_version + path, headers].compact) end |
#get(path, headers = nil) ⇒ Object
8 9 10 |
# File 'lib/twitter/oauth.rb', line 8 def get(path, headers=nil) access_token.get(*[api_version + path, headers].compact) end |
#post(path, data = nil, headers = nil) ⇒ Object
12 13 14 |
# File 'lib/twitter/oauth.rb', line 12 def post(path, data = nil, headers=nil) access_token.post(*[api_version + path, data, headers].compact) end |
#put(path, data = nil, headers = nil) ⇒ Object
16 17 18 |
# File 'lib/twitter/oauth.rb', line 16 def put(path, data = nil, headers=nil) access_token.put(*[api_version + path, data, headers].compact) 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
58 59 60 |
# File 'lib/twitter/oauth.rb', line 58 def request_token(={}) @request_token ||= signing_consumer.get_request_token() end |
#set_callback_url(url) ⇒ Object
50 51 52 53 |
# File 'lib/twitter/oauth.rb', line 50 def set_callback_url(url) clear_request_token request_token(:oauth_callback => url) end |
#signing_consumer ⇒ Object
46 47 48 |
# File 'lib/twitter/oauth.rb', line 46 def signing_consumer @signing_consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => signing_endpoint, :request_endpoint => api_endpoint }.merge()) end |