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 33 |
# 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 puts 'SSLDKJFKLSDJFKLSDJFKLDSJKLFJDSKLFJDSJFKLDSJFKLDSF' 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
48 49 50 51 52 |
# File 'lib/auth_tool/client.rb', line 48 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.
99 100 101 |
# File 'lib/auth_tool/client.rb', line 99 def has_params? return @has_params end |
#oauth1(config) ⇒ Object
35 36 37 38 |
# File 'lib/auth_tool/client.rb', line 35 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
40 41 42 43 44 |
# File 'lib/auth_tool/client.rb', line 40 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.
58 59 60 |
# File 'lib/auth_tool/client.rb', line 58 def oauth_version return @oauth_version end |
#params ⇒ Hash
Returns the parameters hash for this client.
66 67 68 |
# File 'lib/auth_tool/client.rb', line 66 def params return @params end |
#signet ⇒ Signet::OAuth1::Client, Signet::OAuth2::Client
Returns the signet OAuth object for this client.
74 75 76 |
# File 'lib/auth_tool/client.rb', line 74 def signet return @signet end |
#token ⇒ Hash
Returns the final authentication token for the client.
82 83 84 |
# File 'lib/auth_tool/client.rb', line 82 def token @token end |
#token=(token) ⇒ Object
Sets the final authentication token for the client.
91 92 93 |
# File 'lib/auth_tool/client.rb', line 91 def token= token @token = token end |