diff --git a/lib/dogapi/common.rb b/lib/dogapi/common.rb index b242fe2a..6129b5e4 100644 --- a/lib/dogapi/common.rb +++ b/lib/dogapi/common.rb @@ -117,7 +117,10 @@ def request(method, url, extra_params, body, send_json, with_app_key=true) connect do |conn| begin current_url = url + prepare_params(extra_params, with_app_key) + # current_url = url req = method.new(current_url) + req['DD-API-KEY'] = @api_key if @api_key + req['DD-APPLICATION_KEY'] = @application_key if @application_key if send_json req.content_type = 'application/json' @@ -133,8 +136,7 @@ def request(method, url, extra_params, body, send_json, with_app_key=true) end def prepare_params(extra_params, with_app_key) - params = { api_key: @api_key } - params[:application_key] = @application_key if with_app_key + params = {} params = extra_params.merge params unless extra_params.nil? qs_params = params.map { |k, v| CGI.escape(k.to_s) + '=' + CGI.escape(v.to_s) } qs = '?' + qs_params.join('&') diff --git a/spec/integration/comment_spec.rb b/spec/integration/comment_spec.rb index 91b84399..b5a3ef8e 100644 --- a/spec/integration/comment_spec.rb +++ b/spec/integration/comment_spec.rb @@ -18,9 +18,7 @@ stub_request(:put, /#{url}/).to_return(body: '{}').then.to_raise(StandardError) expect(dog.send(:update_comment, COMMENT_ID, options)).to eq ['200', {}] - expect(WebMock).to have_requested(:put, url).with( - query: default_query - ) + expect(WebMock).to have_requested(:put, url) end end diff --git a/spec/integration/common_spec.rb b/spec/integration/common_spec.rb index b4b0e3a8..bd0e95b2 100644 --- a/spec/integration/common_spec.rb +++ b/spec/integration/common_spec.rb @@ -12,9 +12,7 @@ stub_request(:get, /#{url}/).to_return(body: '{}').then.to_raise(StandardError) expect(service.request(Net::HTTP::Get, '/api/v1/awesome', nil, nil, true, true)).to eq(['200', {}]) - expect(WebMock).to have_requested(:get, url).with( - query: default_query - ) + expect(WebMock).to have_requested(:get, url) end end context 'and it is down' do @@ -22,9 +20,7 @@ stub_request(:get, /#{url}/).to_timeout expect(service.request(Net::HTTP::Get, '/api/v1/awesome', nil, nil, true, true)).to eq([-1, {}]) - expect(WebMock).to have_requested(:get, url).with( - query: default_query - ) + expect(WebMock).to have_requested(:get, url) end end end diff --git a/spec/integration/event_spec.rb b/spec/integration/event_spec.rb index 406ca3c2..12562bb5 100644 --- a/spec/integration/event_spec.rb +++ b/spec/integration/event_spec.rb @@ -37,7 +37,6 @@ body = MultiJson.dump(EVENT_OPTIONS) expect(WebMock).to have_requested(:post, url).with( - query: { 'api_key' => api_key }, body: body ) end @@ -63,7 +62,6 @@ params = STREAM_PARAMS.merge(start: EVENT_START, end: EVENT_END) params.each { |k, v| params[k] = v.join(',') if v.is_a? Array } - params.merge! default_query expect(WebMock).to have_requested(:get, url).with( query: params diff --git a/spec/integration/metric_spec.rb b/spec/integration/metric_spec.rb index e9fa4186..34a8df70 100644 --- a/spec/integration/metric_spec.rb +++ b/spec/integration/metric_spec.rb @@ -48,7 +48,6 @@ body = MultiJson.dump(body) expect(WebMock).to have_requested(:post, url).with( - query: { 'api_key' => api_key }, body: body ) end @@ -64,7 +63,6 @@ body = MultiJson.dump(EMIT_BODY) expect(WebMock).to have_requested(:post, url).with( - query: { 'api_key' => api_key }, body: body ) end @@ -89,7 +87,6 @@ body = MultiJson.dump(BATCH_BODY) expect(WebMock).to have_requested(:post, url).with( - query: { 'api_key' => api_key }, body: body ) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 48c41530..f5e271bc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,8 +25,6 @@ module SpecDog let(:old_api_url) { "#{DATADOG_HOST}/api" } let(:api_v2_url) { "#{DATADOG_HOST}/api/v2" } - let(:default_query) { { api_key: api_key, application_key: app_key } } - shared_examples 'an api method' do |command, args, request, endpoint, body| it 'queries the api' do url = api_url + endpoint @@ -37,7 +35,6 @@ module SpecDog body = MultiJson.dump(body) if body expect(WebMock).to have_requested(request, /#{url}|#{old_url}/).with( - query: default_query, body: body ) end @@ -55,7 +52,6 @@ module SpecDog body = MultiJson.dump(body ? (body.merge options) : options) expect(WebMock).to have_requested(request, /#{url}|#{old_url}/).with( - query: default_query, body: body ) end @@ -67,7 +63,7 @@ module SpecDog stub_request(request, /#{url}/).to_return(body: '{}').then.to_raise(StandardError) expect(dog.send(command, *args, *params.values)).to eq ['200', {}] params.each { |k, v| params[k] = v.join(',') if v.is_a? Array } - params = params.merge default_query + params = params expect(WebMock).to have_requested(request, url).with( query: params @@ -83,7 +79,7 @@ module SpecDog expect(dog.send(command, *args, opt_params)).to eq ['200', {}] opt_params.each { |k, v| opt_params[k] = v.join(',') if v.is_a? Array } - params = opt_params.merge default_query + params = opt_params expect(WebMock).to have_requested(request, url).with( query: params @@ -101,7 +97,6 @@ module SpecDog body = MultiJson.dump(body) if body expect(WebMock).to have_requested(request, url).with( - query: default_query, body: body ) end @@ -117,7 +112,6 @@ module SpecDog body = MultiJson.dump(body ? (body.merge options) : options) expect(WebMock).to have_requested(request, url).with( - query: default_query, body: body ) end @@ -129,7 +123,7 @@ module SpecDog stub_request(request, /#{url}/).to_return(body: '{}').then.to_raise(StandardError) expect(dog2.send(command, *args, *params.values)).to eq ['200', {}] params.each { |k, v| params[k] = v.join(',') if v.is_a? Array } - params = params.merge default_query + params = params expect(WebMock).to have_requested(request, url).with( query: params @@ -144,7 +138,7 @@ module SpecDog stub_request(request, /#{url}/).to_return(body: '{}').then.to_raise(StandardError) expect(dog2.send(command, *args, opt_params)).to eq ['200', {}] opt_params.each { |k, v| opt_params[k] = v.join(',') if v.is_a? Array } - params = opt_params.merge default_query + params = opt_params expect(WebMock).to have_requested(request, url).with( query: params