Class: AuthTool::Client
- Inherits:
-
Object
- Object
- AuthTool::Client
- Defined in:
- lib/auth_tool/client.rb
Class Method Summary collapse
-
.refresh ⇒ Object
Attempts to refresh the access token of the client.
Instance Method Summary collapse
-
#has_params? ⇒ Boolean
Returns if the client has additional parameters.
-
#initialize(options, *args) ⇒ Client
constructor
Creates either a signet OAuth 1.0 or 2.0 client with additional params.
- #oauth1(config) ⇒ Object
- #oauth2(config) ⇒ Object
-
#oauth_version ⇒ Integer
Returns the OAuth version for this client.
-
#params ⇒ Hash
Returns the parameters hash for this client.
-
#signet ⇒ Signet::OAuth1::Client, Signet::OAuth2::Client
Returns the signet OAuth object for this client.
-
#token ⇒ Hash
Returns the final authentication token for the client.
-
#token=(token) ⇒ Object
Sets the final authentication token for the client.
Constructor Details
#initialize(options, *args) ⇒ Client
Creates either a signet OAuth 1.0 or 2.0 client with additional params.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/auth_tool/client.rb', line 12 def initialize(, *args) config = credentials = args[0] if args.length == 1 credentials ||= {} raise "Too many args" if args.length > 1 @has_params = config.has_key?('params') self.oauth_version = config.delete('oauth_version') self.params = config.delete('params') if @has_params if @oauth_version == 1 oauth1 config self.signet.token_credential_key = credentials["oauth_token"] if credentials.has_key? "oauth_token" self.signet.token_credential_secret = credentials["oauth_token_secret"] if credentials.has_key? "oauth_token_secret" elsif @oauth_version == 2 oauth2 config self.signet.access_token = credentials["oauth_token"] if credentials.has_key? "oauth_token" self.signet.refresh_token = credentials["refresh_token"] if credentialsl.has_key? "refresh_token" else raise "Unexpected oauth_version: #{@oauth_version}" end end |
Class Method Details
.refresh ⇒ Object
Attempts to refresh the access token of the client
47 48 49 50 51 |
# File 'lib/auth_tool/client.rb', line 47 def self.refresh raise "Incorrect OAuth Version" if @oauth_version != 2 raise "Missing Refresh Token" if self.signet.refresh_token == nil self.signet.refresh! end |
Instance Method Details
#has_params? ⇒ Boolean
Returns if the client has additional parameters.
98 99 100 |
# File 'lib/auth_tool/client.rb', line 98 def has_params? return @has_params end |
#oauth1(config) ⇒ Object
34 35 36 37 |
# File 'lib/auth_tool/client.rb', line 34 def oauth1 config config[:callback] = config.delete(:redirect_uri) if config.has_key?(:redirect_uri) self.signet = Signet::OAuth1::Client.new(config) end |
#oauth2(config) ⇒ Object
39 40 41 42 43 |
# File 'lib/auth_tool/client.rb', line 39 def oauth2 config config[:redirect_uri] = config.delete(:callback) if config.has_key?(:callback) self.signet = Signet::OAuth2::Client.new(config) @signet.additional_parameters = @params if @has_params end |
#oauth_version ⇒ Integer
Returns the OAuth version for this client.
57 58 59 |
# File 'lib/auth_tool/client.rb', line 57 def oauth_version return @oauth_version end |
#params ⇒ Hash
Returns the parameters hash for this client.
65 66 67 |
# File 'lib/auth_tool/client.rb', line 65 def params return @params end |
#signet ⇒ Signet::OAuth1::Client, Signet::OAuth2::Client
Returns the signet OAuth object for this client.
73 74 75 |
# File 'lib/auth_tool/client.rb', line 73 def signet return @signet end |
#token ⇒ Hash
Returns the final authentication token for the client.
81 82 83 |
# File 'lib/auth_tool/client.rb', line 81 def token @token end |
#token=(token) ⇒ Object
Sets the final authentication token for the client.
90 91 92 |
# File 'lib/auth_tool/client.rb', line 90 def token= token @token = token end |