restful_metrics 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,7 +7,7 @@ For more detailed instructions, check out our [Dev Center](http://devcenter.rest
7
7
  ## Install
8
8
 
9
9
  ```
10
- gem install restful_metrics-ruby
10
+ gem install restful_metrics-ruby
11
11
  ```
12
12
 
13
13
  ## Configure
@@ -17,7 +17,7 @@ For more detailed instructions, check out our [Dev Center](http://devcenter.rest
17
17
  The only step required for initialization is setting your API key. Once it's set, it's stored in memory while your Ruby program runs. You set your API key with the following command:
18
18
 
19
19
  ``` ruby
20
- RestfulMetrics::Client.set_credentials('214c7da8edd333abc78712313918ffe5')
20
+ RestfulMetrics::Client.set_credentials('214c7da8edd333abc78712313918ffe5')
21
21
  ```
22
22
 
23
23
  You can skip this step if you've installed the RESTful Metrics Heroku Addon.
@@ -27,7 +27,7 @@ You can skip this step if you've installed the RESTful Metrics Heroku Addon.
27
27
  The client also has an optional flag that prevents the client from actually sending data points to the server. This allows you to keep your RESTful Metrics tracking code in place even in your test enviornments. You can disable the client with the following (by default the client is enabled):
28
28
 
29
29
  ``` ruby
30
- RestfulMetrics::Client.disabled = true unless ENV == 'production'
30
+ RestfulMetrics::Client.disabled = true unless ENV == 'production'
31
31
  ```
32
32
 
33
33
  We added the optional conditional check in the above example to illustrate how the flag can be set dynamically during your application's launch.
@@ -37,9 +37,43 @@ We added the optional conditional check in the above example to illustrate how t
37
37
  The client currently has built-in support for Delayed::Job. If you enable the asynchronous flag the client will automatically queue the data point for transmission to the server at a later time. This is highly recommended for applications that are sensitive to latency.
38
38
 
39
39
  ``` ruby
40
- RestfulMetrics::Client.async = true
40
+ RestfulMetrics::Client.async = true
41
41
  ```
42
-
42
+
43
+ If you use a worker library other than Delayed::Job, you can wrap all your RESTful Metrics calls. For example, if we were using Resque we might add this to an initializer:
44
+
45
+ ``` ruby
46
+ module CompoundMetric
47
+ @queue = :metrics
48
+
49
+ def self.perform(fqdn, name, values, distinct_id = nil)
50
+ RestfulMetrics::Client.add_compound_metric(fqdn, name, values, distinct_id)
51
+ end
52
+ end
53
+
54
+ module Metric
55
+ @queue = :metrics
56
+
57
+ def self.perform(fqdn, name, value, distinct_id = nil)
58
+ RestfulMetrics::Client.add_metric(fqdn, name, value, distinct_id)
59
+ end
60
+ end
61
+
62
+ def restful_metrics_add_data_point(metric_type, app, metric, value, distinct_id=nil)
63
+ unless RestfulMetrics::Client.disabled?
64
+ Resque.enqueue(metric_type, app, metric, value, distinct_id)
65
+ end
66
+ end
67
+ ```
68
+
69
+ We've now separated the metrics and compound metrics into their own queue called `metrics`. To add a compound metric data point, we call:
70
+
71
+ ``` ruby
72
+ restful_metrics_add_data_point(CompoundMetric, "myapp.com", "impression", ["apple juice", "orange juice", "soda"], "fe352fe23e823668e23e7")
73
+ ```
74
+
75
+ Make sure that the `async` flag is set to off. This flag only applies to the built-in Delayed::Job support.
76
+
43
77
  ## Sending Data Points
44
78
 
45
79
  ### Metrics
@@ -56,7 +90,7 @@ Distinct User Identifier | "fe352fe23e823668e23e7"
56
90
  You would transmit this data point with the following:
57
91
 
58
92
  ``` ruby
59
- RestfulMetrics::Client.add_metric("myapp.com", "impression", 1, "fe352fe23e823668e23e7")
93
+ RestfulMetrics::Client.add_metric("myapp.com", "impression", 1, "fe352fe23e823668e23e7")
60
94
  ```
61
95
 
62
96
  ### Compound Metrics
@@ -73,7 +107,7 @@ Distinct User Identifier | "fe352fe23e823668e23e7"
73
107
  You would transmit this data point with the following:
74
108
 
75
109
  ``` ruby
76
- RestfulMetrics::Client.add_compound_metric("myapp.com", "impression", ["apple juice", "orange juice", "soda"], "fe352fe23e823668e23e7")
110
+ RestfulMetrics::Client.add_compound_metric("myapp.com", "impression", ["apple juice", "orange juice", "soda"], "fe352fe23e823668e23e7")
77
111
  ```
78
112
 
79
113
  ## Copyright
@@ -83,3 +117,4 @@ Copyright (c) 2011-2012 RESTful Labs LLC. See LICENSE for details.
83
117
  ## Authors
84
118
 
85
119
  * [Mauricio Gomes](http://github.com/mgomes)
120
+ * [Dan Porter](http://github.com/wolfpakz)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.3
1
+ 1.1.4
@@ -44,29 +44,41 @@ module RestfulMetrics
44
44
  @@disabled
45
45
  end
46
46
 
47
- def add_metric(fqdn, name, value, distinct_id = nil)
47
+ def add_metric(fqdn, name, value, distinct_id=nil, timestamp=nil)
48
48
  params = Hash.new
49
49
  params[:metric] = Hash.new
50
50
  params[:metric][:fqdn] = fqdn
51
51
  params[:metric][:name] = name
52
52
  params[:metric][:value] = value
53
+
53
54
  unless distinct_id.nil?
54
55
  params[:metric][:distinct_id] = distinct_id
55
56
  end
56
57
 
58
+ unless timestamp.nil?
59
+ raise InvalidTimestamp unless timestamp.respond_to?(:to_i)
60
+ params[:metric][:occurred_at] = timestamp.to_i
61
+ end
62
+
57
63
  post(Endpoint.metrics, params)
58
64
  end
59
65
 
60
- def add_compound_metric(fqdn, name, values, distinct_id = nil)
66
+ def add_compound_metric(fqdn, name, values, distinct_id=nil, timestamp=nil)
61
67
  params = Hash.new
62
68
  params[:compound_metric] = Hash.new
63
69
  params[:compound_metric][:fqdn] = fqdn
64
70
  params[:compound_metric][:name] = name
65
71
  params[:compound_metric][:values] = values
72
+
66
73
  unless distinct_id.nil?
67
74
  params[:compound_metric][:distinct_id] = distinct_id
68
75
  end
69
76
 
77
+ unless timestamp.nil?
78
+ raise InvalidTimestamp unless timestamp.respond_to?(:to_i)
79
+ params[:compound_metric][:occurred_at] = timestamp.to_i
80
+ end
81
+
70
82
  post(Endpoint.compound_metrics, params)
71
83
  end
72
84
 
@@ -13,16 +13,17 @@ require 'restful_metrics/endpoint'
13
13
  require 'restful_metrics/client'
14
14
 
15
15
  # Rails integration
16
- require 'restful_metrics/railtie/cookie_integration'
16
+ require 'restful_metrics/railtie/cookie_integration'
17
17
 
18
18
  module RestfulMetrics
19
-
20
- REALM = "http://track.restfulmetrics.com"
19
+
20
+ REALM = "https://track.restfulmetrics.com"
21
21
  VERSION = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
22
22
 
23
23
  class RestfulMetricsError < StandardError; end
24
24
  class InsufficentArguments < RestfulMetricsError; end
25
25
  class InvalidAPIKey < RestfulMetricsError; end
26
26
  class NoConnectionEstablished < RestfulMetricsError; end
27
-
27
+ class InvalidTimestamp < RestfulMetricsError; end
28
+
28
29
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.description = %q{Ruby client for the RESTful Metrics service.}
8
8
  s.homepage = %q{http://github.com/restful-labs/resetful_metrics-ruby}
9
9
  s.version = File.read(File.join(File.dirname(__FILE__), 'VERSION'))
10
- s.authors = ["Mauricio Gomes"]
10
+ s.authors = ["Mauricio Gomes", "Dan Porter"]
11
11
  s.email = "mauricio@restful-labs.com"
12
12
 
13
13
  s.add_dependency "yajl-ruby", ">= 0.8.1"
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restful_metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mauricio Gomes
9
+ - Dan Porter
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-05-15 00:00:00.000000000 Z
13
+ date: 2012-05-31 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: yajl-ruby