Class: Weibo::OAuth
- Inherits:
-
Object
- Object
- Weibo::OAuth
- Extended by:
- Forwardable
- Defined in:
- lib/weibo/oauth.rb
Instance Attribute Summary collapse
-
#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.
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
A new instance of OAuth.
-
#request_token(options = {}) ⇒ Object
Note: If using oauth with a web app, be sure to provide :oauth_callback.
- #set_callback_url(url) ⇒ Object
Constructor Details
#initialize(ctoken, csecret, options = {}) ⇒ OAuth
Returns a new instance of OAuth.
8 9 10 11 12 13 14 |
# File 'lib/weibo/oauth.rb', line 8 def initialize(ctoken, csecret, ={}) @ctoken, @csecret, @consumer_options = ctoken, csecret, {} if [:sign_in] @consumer_options[:authorize_path] = '/oauth/authorize' end end |
Instance Attribute Details
#consumer_options ⇒ Object (readonly)
Returns the value of attribute consumer_options.
6 7 8 |
# File 'lib/weibo/oauth.rb', line 6 def @consumer_options end |
#csecret ⇒ Object (readonly)
Returns the value of attribute csecret.
6 7 8 |
# File 'lib/weibo/oauth.rb', line 6 def csecret @csecret end |
#ctoken ⇒ Object (readonly)
Returns the value of attribute ctoken.
6 7 8 |
# File 'lib/weibo/oauth.rb', line 6 def ctoken @ctoken end |
Instance Method Details
#access_token ⇒ Object
40 41 42 |
# File 'lib/weibo/oauth.rb', line 40 def access_token @access_token ||= ::OAuth::AccessToken.new(consumer, @atoken, @asecret) end |
#authorize_from_access(atoken, asecret) ⇒ Object
44 45 46 |
# File 'lib/weibo/oauth.rb', line 44 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.
34 35 36 37 38 |
# File 'lib/weibo/oauth.rb', line 34 def (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 |
#consumer ⇒ Object
16 17 18 |
# File 'lib/weibo/oauth.rb', line 16 def consumer @consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => 'http://api.t.sina.com.cn'}.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
28 29 30 |
# File 'lib/weibo/oauth.rb', line 28 def request_token(={}) @request_token ||= consumer.get_request_token() end |
#set_callback_url(url) ⇒ Object
20 21 22 23 |
# File 'lib/weibo/oauth.rb', line 20 def set_callback_url(url) clear_request_token request_token(:oauth_callback => url) end |