lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.0.48 vs lib/soaspec/exchange_handlers/rest_handler.rb in soaspec-0.0.49

- old
+ new

@@ -1,10 +1,10 @@ require_relative 'exchange_handler' require_relative '../hash_methods' require_relative '../not_found_errors' -require_relative '../accessors' +require_relative 'handler_accessors' require_relative '../interpreter' require 'json' require 'jsonpath' require 'nori' @@ -32,22 +32,36 @@ 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 }, cache_control: 'no_cache', verify_ssl: false ) else RestClient.post( token_url, - { - grant_type: 'client_credentials', - client_id: client_id, - client_secret: client_secret - }, + { + 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'] @@ -56,21 +70,20 @@ # Pass path to YAML file containing OAuth2 parameters # @param [String] path_to_filename Will have Soaspec.credentials_folder appended to it if set def oauth2_file(path_to_filename) full_path = Soaspec.credentials_folder ? File.join(Soaspec.credentials_folder, path_to_filename + '.yml') : path_to_filename + '.yml' - file_hash = YAML.load_file(full_path) + file_hash = eval(ERB.new(YAML.load_file(full_path).to_s).result(binding)) raise 'File at ' + full_path + ' is not a hash ' unless file_hash.is_a? Hash oauth_hash = file_hash.transform_keys_to_symbols oauth2 **oauth_hash end end # Wraps around Savon client defining default values dependent on the soap request class RestHandler < ExchangeHandler extend Soaspec::RestAccessors - extend Soaspec::Accessors # Savon client used to make SOAP calls attr_accessor :client # SOAP Operation to use by default attr_accessor :operation \ No newline at end of file