Class: Qihu::Auth
- Inherits:
-
Object
- Object
- Qihu::Auth
- Defined in:
- lib/qihu/auth.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#expires_at ⇒ Object
readonly
Returns the value of attribute expires_at.
-
#expires_in ⇒ Object
readonly
Returns the value of attribute expires_in.
-
#oauth2 ⇒ Object
readonly
Returns the value of attribute oauth2.
-
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #authorize_url(options = {}) ⇒ Object
- #get_token(code, redirect_uri = '') ⇒ Object
- #get_token_from_hash(token = {}) ⇒ Object
-
#initialize(client_id, client_secret, token = {}, redirect_uri = 'oob', site = 'https://openapi.360.cn') ⇒ Auth
constructor
A new instance of Auth.
Constructor Details
#initialize(client_id, client_secret, token = {}, redirect_uri = 'oob', site = 'https://openapi.360.cn') ⇒ Auth
Returns a new instance of Auth.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/qihu/auth.rb', line 8 def initialize(client_id, client_secret, token={}, redirect_uri='oob', site='https://openapi.360.cn') @redirect_uri = redirect_uri @oauth2 = OAuth2::Client.new(client_id, client_secret, :site => site, :authorize_url => '/oauth2/authorize', :token_url => '/oauth2/access_token', :ssl => {:verify => false}, ) if token or !token.empty? @token = OAuth2::AccessToken.from_hash(@oauth2, token) end end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
5 6 7 |
# File 'lib/qihu/auth.rb', line 5 def access_token @access_token end |
#expires_at ⇒ Object (readonly)
Returns the value of attribute expires_at.
5 6 7 |
# File 'lib/qihu/auth.rb', line 5 def expires_at @expires_at end |
#expires_in ⇒ Object (readonly)
Returns the value of attribute expires_in.
5 6 7 |
# File 'lib/qihu/auth.rb', line 5 def expires_in @expires_in end |
#oauth2 ⇒ Object (readonly)
Returns the value of attribute oauth2.
5 6 7 |
# File 'lib/qihu/auth.rb', line 5 def oauth2 @oauth2 end |
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
6 7 8 |
# File 'lib/qihu/auth.rb', line 6 def redirect_uri @redirect_uri end |
#refresh_token ⇒ Object (readonly)
Returns the value of attribute refresh_token.
5 6 7 |
# File 'lib/qihu/auth.rb', line 5 def refresh_token @refresh_token end |
#token ⇒ Object
Returns the value of attribute token.
6 7 8 |
# File 'lib/qihu/auth.rb', line 6 def token @token end |
Instance Method Details
#authorize_url(options = {}) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/qihu/auth.rb', line 22 def (={}) @redirect_uri = [:redirect_uri] if [:redirect_uri] scope = [:scope] ? [:scope] : 'basic' display = [:display] ? [:display] : 'default' @oauth2.auth_code.(:redirect_uri => @redirect_uri, :scope => scope, :display => display) end |
#get_token(code, redirect_uri = '') ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/qihu/auth.rb', line 30 def get_token(code, redirect_uri='') @redirect_uri = redirect_uri unless redirect_uri.empty? @token = @oauth2.auth_code.get_token(code, :redirect_uri => @redirect_uri) @refresh_token = @token.refresh_token @expires_at = @token.expires_at @expires_in = @token.expires_in @access_token = @token.token return self end |
#get_token_from_hash(token = {}) ⇒ Object
42 43 44 45 |
# File 'lib/qihu/auth.rb', line 42 def get_token_from_hash(token={}) @token = OAuth2::AccessToken.from_hash(@oauth2, token) return self end |