require_relative 'rest_accessors_defaults' module Soaspec # Accessors specific to REST handler module RestAccessors # Defines method 'base_url_value' containing base URL used in REST requests # @param [String] url Base Url to use in REST requests. Suburl is appended to this def base_url(url) define_method('base_url_value') do url end end # Will create access_token method based on passed parameters # @param [Hash] params OAuth 2 parameters # @param_value [token_url] URL to retrieve OAuth token from. @Note this can be set globally instead of here # @param_value [client_id] Client ID # @param_value [client_secret] Client Secret # @param_value [username] Username used in password grant # @param_value [password] Password used in password grant # @param_value [security_token] Security Token used in password grant def oauth2(params) # @!method oauth_obj Object to handle oauth2 define_method('oauth_obj') { OAuth2.new(params, api_username) } # @!method access_token Retrieve OAuth2 access token define_method('access_token') { oauth_obj.access_token } # @!method instance_url Retrieve instance url from OAuth request define_method('instance_url') { oauth_obj.response['instance_url'] } end # 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) : path_to_filename full_path += '.yml' unless full_path.end_with?('.yml') file_hash = YAML.load_file(full_path) raise 'File at ' + full_path + ' is not a hash ' unless file_hash.is_a? Hash oauth2 file_hash end # @param [Hash] headers Hash of REST headers used in RestClient def headers(headers) define_method('rest_client_headers') do headers end end # Convert each key from snake_case to PascalCase def pascal_keys(set) define_method('pascal_keys?') do set end end end end