Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/app_monit/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo for response?


response
end

private

def environment(path)
params(path).fetch('environment', nil)
end

def api_key(path)
params(path).fetch('api_key', nil)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/app_monit/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module AppMonit
VERSION = "0.0.11"
VERSION = "0.0.12"
end
6 changes: 3 additions & 3 deletions spec/app_monit/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down