Class: Metric::Track
- Inherits:
-
Object
- Object
- Metric::Track
- Defined in:
- lib/metric/track.rb
Overview
Used to track metrics
Class Method Summary (collapse)
-
+ (String) compose(metric, options = {})
Generate the url with query strings.
-
+ (String) parse_metric(metric)
CGI escape the metric name so spaces and characters are allowed.
-
+ (nil) track(metric, options = {})
Uses a thread to perform the request.
Class Method Details
+ (String) compose(metric, options = {})
Generate the url with query strings
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/metric/track.rb', line 13 def self.compose(metric, = {}) amount = [:amount] trigger = [:trigger] key = "?api_key=" + Metric.configuration.api_key url = Metric.configuration.metric_host + '/track' url << key url << parse_metric(metric) url << "&amount=#{amount}" if amount url << "&trigger=1" if trigger url end |
+ (String) parse_metric(metric)
CGI escape the metric name so spaces and characters are allowed
45 46 47 |
# File 'lib/metric/track.rb', line 45 def self.parse_metric(metric) "&metric=#{CGI.escape(metric)}" end |
+ (nil) track(metric, options = {})
Note:
If this gem is used with Rails it will only track data in the production environment
Uses a thread to perform the request
31 32 33 34 35 36 37 38 39 |
# File 'lib/metric/track.rb', line 31 def self.track(metric, = {}) return if defined?(Rails) && !Rails.env.production? return if [:amount] && [:amount] == 0 url = compose(metric, ) Thread.new do `curl "#{url}" 2>&1 ; ` end end |