diff --git a/lib/emailable/client.rb b/lib/emailable/client.rb index e738740..29b87d9 100644 --- a/lib/emailable/client.rb +++ b/lib/emailable/client.rb @@ -17,8 +17,9 @@ def initialize end def request(method, endpoint, params = {}) - api_key = params.delete(:api_key) - access_token = params.delete(:access_token) + params_copy = params.dup + api_key = params_copy.delete(:api_key) + access_token = params_copy.delete(:access_token) uri = URI("#{@base_url}/#{endpoint}") headers = { @@ -30,12 +31,12 @@ def request(method, endpoint, params = {}) tries ||= 3 http_response = if method == :get - uri.query = URI.encode_www_form(params) unless params.empty? + uri.query = URI.encode_www_form(params_copy) if params_copy.any? request = Net::HTTP::Get.new(uri, headers) @connection.request(request) elsif method == :post request = Net::HTTP::Post.new(uri, headers) - request.body = params.to_json + request.body = params_copy.to_json @connection.request(request) end diff --git a/test/authentication_test.rb b/test/authentication_test.rb index 1692754..eaa5ef5 100644 --- a/test/authentication_test.rb +++ b/test/authentication_test.rb @@ -30,4 +30,12 @@ def test_request_time_authentication_takes_priority_over_global refute_nil Emailable.verify(@email, api_key: @api_key).domain end + def test_does_not_modify_params + params = { api_key: @api_key, email: @email } + Emailable.verify(params[:email], params) + + assert_equal @api_key, params[:api_key] + assert_equal @email, params[:email] + end + end