Class: Metric::Track
- Inherits:
-
Object
- Object
- Metric::Track
- Defined in:
- lib/metric/track.rb
Overview
Used to track metrics
Class Method Summary collapse
-
.compose(metric, options = {}) ⇒ String
Generate the url with query strings.
-
.track(metric, options = {}) ⇒ nil
Track the metric.
Class Method Details
.compose(metric, options = {}) ⇒ String
Generate the url with query strings
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/metric/track.rb', line 15 def self.compose(metric, = {}) amount = [:amount] trigger = [:trigger] date = [:date] = [:meta] key = "?api_key=" + Metric.configuration.api_key url = Metric.configuration.protocol + "://" + Metric.configuration.host + '/track' url << key url << "&metric=#{CGI.escape(metric)}" url << "&amount=#{amount}" if amount url << "&date=#{date}" if date url << "&meta=#{CGI.escape()}" if url << "&trigger=1" if trigger url end |
.track(metric, options = {}) ⇒ nil
Note:
curl is called in a seperate thread so this won’t block execution
Track the metric
37 38 39 40 41 42 43 |
# File 'lib/metric/track.rb', line 37 def self.track(metric, = {}) return if quit_early?() url = compose(metric, ) Thread.new do `curl "#{url}" 2>&1 ; ` end end |