class Stackdriver::Client
Client
for Stackdriver
API
Constants
- STACKDRIVER_HOST
Public Instance Methods
clear()
click to toggle source
# File lib/stackdriver/client.rb, line 20 def clear @last_response = nil end
last_response()
click to toggle source
# File lib/stackdriver/client.rb, line 16 def last_response @last_response end
Private Instance Methods
api_key()
click to toggle source
# File lib/stackdriver/client.rb, line 53 def api_key @api_key ||= ENV.fetch('STACKDRIVER_API_KEY', 'NullApiKey') end
conn()
click to toggle source
# File lib/stackdriver/client.rb, line 26 def conn @conn ||= Faraday.new(url: STACKDRIVER_HOST) do |faraday| faraday.adapter Faraday.default_adapter end end
request(method, endpoint, data)
click to toggle source
Send the metrics/event and return success boolean.
# File lib/stackdriver/client.rb, line 35 def request(method, endpoint, data) begin @last_response = conn.send(method) do |req| req.url endpoint req.body = MultiJson.dump(data) req.headers['Content-Type'] = 'application/json' req.headers['x-stackdriver-apikey'] = api_key req.options[:timeout] = 2 req.options[:open_timeout] = 2 end # TODO: Confirm whether 201 is the only success response. @last_response.status == 201 rescue false end end