@@ -17,31 +17,32 @@ def initialize(session)
1717 raise InvalidSessionError . new ( "Session api_url cannot be nil" ) if session . api_url . nil?
1818 end
1919
20- def create ( code )
21- response , status = BeyondApi ::Request . token ( @session . api_url + "/oauth/token" ,
22- grant_type : "authorization_code" ,
23- code : code )
24-
25- handle_response ( response , status )
20+ def authorization_code ( code )
21+ handle_token_call ( "authorization_code" , code : code )
2622 end
2723
28- def refresh
29- response , status = BeyondApi ::Request . token ( @session . api_url + "/oauth/token" ,
30- grant_type : "refresh_token" ,
31- refresh_token : @session . refresh_token )
32-
33- handle_response ( response , status )
24+ def refresh_token
25+ handle_token_call ( "refresh_token" , refresh_token : @session . refresh_token )
3426 end
3527
3628 def client_credentials
29+ handle_token_call ( "client_credentials" )
30+ end
31+
32+ alias_method :refresh , :refresh_token
33+ alias_method :create , :authorization_code
34+
35+ private
36+
37+ def handle_token_call ( grant_type , params = { } )
38+ params . merge! ( grant_type : grant_type )
39+
3740 response , status = BeyondApi ::Request . token ( @session . api_url + "/oauth/token" ,
38- grant_type : "client_credentials" )
41+ params )
3942
4043 handle_response ( response , status )
4144 end
4245
43- private
44-
4546 def handle_response ( response , status )
4647 if status . between? ( 200 , 299 )
4748 @session . access_token = response [ "access_token" ]
0 commit comments