Class: Metric::Track

Inherits:
Object
  • Object
show all
Defined in:
lib/metric/track.rb

Overview

Used to track metrics

Class Method Summary collapse

Class Method Details

.compose(metric, options = {}) ⇒ String

Generate the url with query strings

Parameters:

  • metric (String)

    Metric identifier

  • options (Hash) (defaults to: {})

    Options

Options Hash (options):

  • :amount (Symbol)

    Amount to track

  • :date (Symbol)

    Override the default date (today)

  • :meta (Symbol)

    Pass in custom meta data about the metric

Returns:

  • (String)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/metric/track.rb', line 14

def self.compose(metric, options = {})
  amount = options[:amount]
  date = options[:date]
  meta = options[:meta]
  customer = options[:customer]

  parameters = {"metric" => metric, "amount" => amount, "date" => date,
                "meta" => meta, "customer" => customer}

  api_key = Metric.configuration.api_key
  url = Metric.configuration.protocol + "://" + Metric.configuration.host
  url << "/v1/sites/#{api_key}/track?"
  url << Metric::Util.build_query_string(parameters)
  url
end

.track(metric, options = {}) ⇒ nil

Note:

curl is called in a seperate thread so this won’t block execution

Track the metric

Parameters:

  • (String, Hash)

Returns:

  • (nil)


35
36
37
38
39
40
41
# File 'lib/metric/track.rb', line 35

def self.track(metric, options = {})
  return if quit_early?(options)
  url = compose(metric, options)
  Thread.new do
    `curl "#{url}" 2>&1 ; `
  end
end