Class: Proz::OAuth
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
readonly
Returns the value of attribute client_secret.
-
#redirect_uri ⇒ Object
readonly
Returns the value of attribute redirect_uri.
Instance Method Summary collapse
- #exchange_code_for_token(code) ⇒ Object
-
#initialize(client_id:, client_secret:, redirect_uri:) ⇒ OAuth
constructor
A new instance of OAuth.
- #link ⇒ Object
- #request_new_token_with_refresh_token(refresh_token) ⇒ Object
Constructor Details
#initialize(client_id:, client_secret:, redirect_uri:) ⇒ OAuth
Returns a new instance of OAuth.
8 9 10 11 12 |
# File 'lib/proz/oauth.rb', line 8 def initialize(client_id:, client_secret:, redirect_uri:) @client_id = client_id @client_secret = client_secret @redirect_uri = redirect_uri end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
7 8 9 |
# File 'lib/proz/oauth.rb', line 7 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
Returns the value of attribute client_secret.
7 8 9 |
# File 'lib/proz/oauth.rb', line 7 def client_secret @client_secret end |
#redirect_uri ⇒ Object (readonly)
Returns the value of attribute redirect_uri.
7 8 9 |
# File 'lib/proz/oauth.rb', line 7 def redirect_uri @redirect_uri end |
Instance Method Details
#exchange_code_for_token(code) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/proz/oauth.rb', line 18 def exchange_code_for_token(code) if token(code).has_key?('error') if token(code)['error'].eql?('invalid_grant') raise "Authorization code doesn't exist or is invalid for the client" else raise 'Invalid Request' end else token(code) end end |
#link ⇒ Object
14 15 16 |
# File 'lib/proz/oauth.rb', line 14 def link client.auth_code.(:redirect_uri => redirect_uri) end |
#request_new_token_with_refresh_token(refresh_token) ⇒ Object
30 31 32 |
# File 'lib/proz/oauth.rb', line 30 def request_new_token_with_refresh_token(refresh_token) @refreshed_token ||= self.class.post('https://www.proz.com/oauth/token', :body => { :refresh_token => refresh_token, :redirect_uri => redirect_uri, :client_id => client_id, :client_secret => client_secret, :grant_type => 'refresh_token' }) end |