lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.0.49 vs lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.0.50
- old
+ new
@@ -21,51 +21,58 @@
end
end
# Will create access_token method based on passed parameters
def oauth2(client_id: nil, client_secret: nil, token_url: nil, username: nil, password: nil, security_token: nil)
- define_method('access_token') do
+ define_method('oauth_response') do
response = if password && username && security_token
RestClient.post(
- token_url,
+ token_url,
{
grant_type: 'password',
client_id: client_id,
client_secret: client_secret,
username: username,
password: (password + security_token),
multipart: true
- },
+ },
cache_control: 'no_cache',
verify_ssl: false
)
elsif password && username
RestClient.post(
token_url,
{
- grant_type: 'password',
- client_id: client_id,
- client_secret: client_secret,
- username: username,
- password: password,
- multipart: true
+ grant_type: 'password',
+ client_id: client_id,
+ client_secret: client_secret,
+ username: username,
+ password: password,
+ multipart: true
},
cache_control: 'no_cache',
verify_ssl: false
)
else
RestClient.post(
- token_url,
- {
- grant_type: 'client_credentials',
- client_id: client_id,
- client_secret: client_secret
- },
- cache_control: 'no_cache',
- verify_ssl: false
+ token_url,
+ {
+ grant_type: 'client_credentials',
+ client_id: client_id,
+ client_secret: client_secret
+ },
+ cache_control: 'no_cache',
+ verify_ssl: false
)
end
- JSON.parse(response)['access_token']
+ JSON.parse(response)
+ end
+
+ define_method('access_token') do
+ oauth_response['access_token']
+ end
+ define_method('instance_url') do
+ oauth_response['instance_url']
end
end
# Pass path to YAML file containing OAuth2 parameters
# @param [String] path_to_filename Will have Soaspec.credentials_folder appended to it if set
\ No newline at end of file