lib/bubbles/rest_client_resources.rb in bubbles-rest-client-0.6.0 vs lib/bubbles/rest_client_resources.rb in bubbles-rest-client-0.7.0

- old
+ new

@@ -49,25 +49,33 @@ # # Currently, only Authorization: Bearer is supported. # # @param [RestEnvironment] env The +RestEnvironment+ to use to execute the request # @param [Endpoint] endpoint The +Endpoint+ which should be requested - # @param [String] auth_token The authorization token to use for authentication. + # @param [Symbol] auth_type The authorization type to use (Bearer, or Basic) + # @param [String] auth_value The authorization token OR encoded value (login/password )to use for authentication. # @param [Hash] uri_params A +Hash+ of identifiers to values to replace in the URI string. # @param [Hash] additional_headers A +Hash+ of key-value pairs that will be sent as additional headers in the API # call. Defaults to an empty +Hash+. # @param [String] api_key (Optional) The API key to use to send to the host for unauthenticated requests. Defaults # to +nil+. # @param [String] api_key_name (Optional) The name of the header in which to send the API key. Defaults to # +"X-API-Key"+. # # @return [RestClient::Response] The +Response+ resulting from the execution of the GET call. # - def self.execute_get_authenticated(env, endpoint, auth_token, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') - composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) + def self.execute_get_authenticated(env, endpoint, auth_type, auth_value, uri_params, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') + if auth_type == :basic + composite_headers = RestClientResources.build_composite_headers(endpoint.additional_headers, { + Authorization: 'Basic ' + Base64.strict_encode64(auth_value) + }) + auth_value = nil + else + composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) + end - execute_rest_call(env, endpoint, nil, auth_token, composite_headers, uri_params) do |env, url, data, headers| + execute_rest_call(env, endpoint, nil, auth_value, composite_headers, uri_params) do |env, url, data, headers| next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE).get(headers) end end ## @@ -161,13 +169,20 @@ # @param [String] api_key_name (Optional) The name of the header in which to send the API key. Defaults to # +"X-API-Key"+. # # @return [RestClient::Response] The +Response+ resulting from the execution of the POST call. # - def self.execute_post_authenticated(env, endpoint, auth_token, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') - composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) + def self.execute_post_authenticated(env, endpoint, auth_type, auth_value, data, additional_headers = {}, api_key = nil, api_key_name = 'X-API-Key') + if auth_type == :basic + composite_headers = RestClientResources.build_composite_headers(endpoint.additional_headers, { + Authorization: 'Basic ' + Base64.strict_encode64(auth_value) + }) + auth_value = nil + else + composite_headers = self.get_headers_with_api_key(endpoint, api_key, api_key_name, additional_headers) + end - return execute_rest_call(env, endpoint, data, auth_token, composite_headers) do |env, url, data, headers| + execute_rest_call(env, endpoint, data, auth_value, composite_headers) do |env, url, data, headers| next RestClient::Resource.new(url.to_s, :verify_ssl => OpenSSL::SSL::VERIFY_NONE).post(data.to_json, headers) end end ##