class Proz::OAuth
Attributes
client_id[R]
client_secret[R]
redirect_uri[R]
Public Class Methods
new(client_id:, client_secret:, redirect_uri:)
click to toggle source
# 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
Public Instance Methods
exchange_code_for_token(code)
click to toggle source
# 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()
click to toggle source
# File lib/proz/oauth.rb, line 14 def link client.auth_code.authorize_url(:redirect_uri => redirect_uri) end
request_new_token_with_refresh_token(refresh_token)
click to toggle source
# 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
Private Instance Methods
client()
click to toggle source
# File lib/proz/oauth.rb, line 40 def client @client ||= OAuth2::Client.new(client_id, client_secret, :site => 'https://www.proz.com') end
token(code)
click to toggle source
# File lib/proz/oauth.rb, line 36 def token(code) @token ||= self.class.post('https://www.proz.com/oauth/token', :body => { :code => code, :redirect_uri => redirect_uri, :client_id => client_id, :client_secret => client_secret, :grant_type => 'authorization_code' }) end