diff --git a/lib/app_monit/http.rb b/lib/app_monit/http.rb index 1f87a2e..7484258 100644 --- a/lib/app_monit/http.rb +++ b/lib/app_monit/http.rb @@ -41,16 +41,21 @@ def request(method, path, body = nil) # set headers so event data ends up in the correct bucket on the other side # only add Appmonit-Api-Key header if there was no api_key configured in the params request.add_field('Appmonit-Api-Key', AppMonit::Config.api_key) unless api_key(path) - request.add_field('Appmonit-Env', AppMonit::Config.env) + # only add Appmonit-Env header if there was no env configured in the params + request.add_field('Appmonit-Env', AppMonit::Config.env) unless environment(path) response = client.request(request) - raise Error.new("Invalid response code: #{response.code} body: #{response.body}") unless SUCCESS_CODES.include?(response.code) + raise Error.new("Invalid response code: #{response.code} body: #{respose.body}") unless SUCCESS_CODES.include?(response.code) response end private + def environment(path) + params(path).fetch('environment', nil) + end + def api_key(path) params(path).fetch('api_key', nil) end diff --git a/lib/app_monit/version.rb b/lib/app_monit/version.rb index 40835f7..716a7a3 100644 --- a/lib/app_monit/version.rb +++ b/lib/app_monit/version.rb @@ -1,3 +1,3 @@ module AppMonit - VERSION = "0.0.11" + VERSION = "0.0.12" end diff --git a/spec/app_monit/query_spec.rb b/spec/app_monit/query_spec.rb index 60bb239..247c38a 100644 --- a/spec/app_monit/query_spec.rb +++ b/spec/app_monit/query_spec.rb @@ -26,18 +26,18 @@ end end - describe 'An api_key has been added to the params' do + describe 'An api_key and environment has been added to the params' do %w(count count_unique minimum maximum average sum funnel).each do |method_name| describe method_name do it 'gets the results with the given params' do stub_request(:get, /api.appmon.it\/v1\/queries\/#{method_name}/).to_return(body: {result: '0'}.to_json) - params = { valid: 'params', api_key: 'XXX' } + params = { valid: 'params', api_key: 'XXX', environment: 'accept' } subject.send(method_name, 'collection_name', params) params[:event_collection] = 'collection_name' - assert_requested(:get, /api.appmon.it\/v1\/queries\/#{method_name}\?api_key=XXX&query=#{params.to_json}/) + assert_requested(:get, /api.appmon.it\/v1\/queries\/#{method_name}\?api_key=XXX&environment=accept&query=#{params.to_json}/) end end end