class Hover::Client::Static
Attributes
application[RW]
environment[RW]
Public Class Methods
new(application, environment, client_id, client_secret, site = 'http://localhost:3000', prefix = 'api/v1')
click to toggle source
Calls superclass method
Hover::Client::HMAC::new
# File lib/hover/client/static.rb, line 9 def initialize(application, environment, client_id, client_secret, site = 'http://localhost:3000', prefix = 'api/v1') super(client_id, client_secret, site, prefix) self.application = application self.environment = environment end
param_name(*args)
click to toggle source
# File lib/hover/client/static.rb, line 82 def self.param_name(*args) first = args.shift "#{first}" + args.map{ |arg| "[#{arg}]" }.join end
Public Instance Methods
add_unique_identifier(parameters)
click to toggle source
# File lib/hover/client/static.rb, line 55 def add_unique_identifier(parameters) sorted_array = parameters.to_a.sort_by(&:first) metric_identifier = Digest::SHA256.hexdigest(sorted_array.to_json) parameters['metric[identifier]'] = metric_identifier end
alooma_url()
click to toggle source
# File lib/hover/client/static.rb, line 32 def alooma_url @alooma_url ||= if Rails.env.staging? "https://inputs.alooma.com/rest/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGllbnROYW1lIjoiaG92ZXItc2YtMSIsImlucHV0TGFiZWwiOiJzdGF0aWNfc3RhZ2luZyIsImlucHV0VHlwZSI6IlJFU1RBUEkifQ.Iba3VM9GaOjzJEmUFPuHDA6oaQT7TBe9A0iMxfYW0x0" elsif Rails.env.production? "https://inputs.alooma.com/rest/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGllbnROYW1lIjoiaG92ZXItc2YtMSIsImlucHV0TGFiZWwiOiJzdGF0aWNfcHJvZHVjdGlvbiIsImlucHV0VHlwZSI6IlJFU1RBUEkifQ.jiuWVLDPDvZSv4bmiy54GVEpOre19bDqr9ZC7Y-HKwo" end end
create_metric(name:, value:, happened_at: Time.now.utc, tags: {}, remote_record_id: nil)
click to toggle source
# File lib/hover/client/static.rb, line 16 def create_metric(name:, value:, happened_at: Time.now.utc, tags: {}, remote_record_id: nil) return unless alooma_url parameters = { "metric[name]" => name, 'metric[value]' => value, 'metric[happened_at]' => happened_at.to_s, 'metric[environment]' => environment, 'metric[application]' => application }.merge(self.class.tags_to_params(tags)) parameters['metric[remote_record_id]'] = remote_record_id if remote_record_id add_unique_identifier(parameters) post_to_alooma(parameters, alooma_url) end
post_to_alooma(parameters, url)
click to toggle source
# File lib/hover/client/static.rb, line 40 def post_to_alooma(parameters, url) uri = URI.parse(url) request = Net::HTTP::Post.new(uri) request.set_form_data(parameters) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if 'https' == uri.scheme response = http.request(request) unless (200 .. 299).include?(response.code.to_i) raise AloomaReportingError.new("Error reporting to alooma. #{response.inspect}") end response end