restful_metrics 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,15 +1,85 @@
1
- # Restful Metrics Ruby Client #
1
+ # Restful Metrics Ruby Client
2
2
 
3
- Tracks your app's custom metrics.
3
+ Tracks your app's custom business metrics in your Ruby apps.
4
4
 
5
- ## Status ##
5
+ For more detailed instructions, check out our [Dev Center](http://devcenter.restful-labs.com/metrics/ruby_initialize).
6
6
 
7
- This gem is currently unreleased.
7
+ ## Install
8
8
 
9
- ## Copyright ##
9
+ ```
10
+ gem install restful_metrics-ruby
11
+ ```
12
+
13
+ ## Configure
14
+
15
+ ### Setting your API Key
16
+
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
+
19
+ ``` ruby
20
+ RestfulMetrics::Client.set_credentials('214c7da8edd333abc78712313918ffe5')
21
+ ```
22
+
23
+ You can skip this step if you've installed the RESTful Metrics Heroku Addon.
24
+
25
+ ### Disable Flag
26
+
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
+
29
+ ``` ruby
30
+ RestfulMetrics::Client.disabled = true unless ENV == 'production'
31
+ ```
32
+
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.
34
+
35
+ ### Asynchronous Mode
36
+
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
+
39
+ ``` ruby
40
+ RestfulMetrics::Client.async = true
41
+ ```
42
+
43
+ ## Sending Data Points
44
+
45
+ ### Metrics
46
+
47
+ So given the following values for the attributes:
48
+
49
+ Attribute | Value
50
+ ------------- | -------------
51
+ Application Identifier | "myapp.com"
52
+ Metric Name | "impression"
53
+ Value | 1
54
+ Distinct User Identifier | "fe352fe23e823668e23e7"
55
+
56
+ You would transmit this data point with the following:
57
+
58
+ ``` ruby
59
+ RestfulMetrics::Client.add_metric("myapp.com", "impression", 1, "fe352fe23e823668e23e7")
60
+ ```
61
+
62
+ ### Compound Metrics
63
+
64
+ So given the following values for the attributes:
65
+
66
+ Attribute | Value
67
+ ------------- | -------------
68
+ Application Identifier | "myapp.com"
69
+ Compound Metric Name | "beverage_search"
70
+ Values | ["apple juice", "orange juice", "soda"]
71
+ Distinct User Identifier | "fe352fe23e823668e23e7"
72
+
73
+ You would transmit this data point with the following:
74
+
75
+ ``` ruby
76
+ RestfulMetrics::Client.add_compound_metric("myapp.com", "impression", ["apple juice", "orange juice", "soda"], "fe352fe23e823668e23e7")
77
+ ```
78
+
79
+ ## Copyright
10
80
 
11
81
  Copyright (c) 2011 Restful Labs LLC. See LICENSE for details.
12
82
 
13
- ## Authors ##
83
+ ## Authors
14
84
 
15
85
  * [Mauricio Gomes](http://github.com/mgomes)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -74,7 +74,13 @@ module RestfulMetrics
74
74
 
75
75
  def post(endpoint, data=nil)
76
76
  return false if disabled?
77
- raise NoConnectionEstablished if @@connection.nil?
77
+ if @@connection.nil?
78
+ if ENV["RESTFUL_METRICS_API_KEY"]
79
+ @@connection = Connection.new(ENV["RESTFUL_METRICS_API_KEY"])
80
+ else
81
+ raise NoConnectionEstablished
82
+ end
83
+ end
78
84
 
79
85
  unless production_env?
80
86
  logger "Skipping while not in production", :info
data/spec/client_spec.rb CHANGED
@@ -2,18 +2,39 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "A NON-initialized Restful Metrics client" do
4
4
 
5
- it "should NOT send a metric if a connection is not initialized" do
5
+ it "should NOT send a metric data point" do
6
6
  lambda {
7
7
  RestfulMetrics::Client.add_metric("foo.bar.org", "hit", 1)
8
8
  }.should raise_error(RestfulMetrics::NoConnectionEstablished)
9
9
  end
10
10
 
11
- it "should NOT send a compound metric if a connection is not initialized" do
11
+ it "should NOT send a compound metric data point" do
12
12
  lambda {
13
13
  RestfulMetrics::Client.add_compound_metric("foo.bar.org", "hit", [1,2,3])
14
14
  }.should raise_error(RestfulMetrics::NoConnectionEstablished)
15
15
  end
16
16
 
17
+ describe "in a Heroku environment" do
18
+
19
+ before(:each) do
20
+ ENV["RESTFUL_METRICS_API_KEY"] = "xyz123"
21
+ RestfulMetrics::Connection.any_instance.stubs(:post).returns(100)
22
+ end
23
+
24
+ it "should send a metric data point" do
25
+ rails_env "production" do
26
+ RestfulMetrics::Client.add_metric("foo.bar.org", "hit", 1).should be_true
27
+ end
28
+ end
29
+
30
+ it "should send a compound metric data point" do
31
+ rails_env "production" do
32
+ RestfulMetrics::Client.add_compound_metric("foo.bar.org", "hit", [1,2,3]).should be_true
33
+ end
34
+ end
35
+
36
+ end
37
+
17
38
  end
18
39
 
19
40
  describe "A disabled Restful Metrics client" do
data/spec/spec_helper.rb CHANGED
@@ -9,6 +9,7 @@ require 'action_controller/test_process'
9
9
  require 'rspec'
10
10
  require 'mocha'
11
11
  require 'restful_metrics'
12
+ require 'delayed_job'
12
13
 
13
14
  # Requires supporting files with custom matchers and macros, etc,
14
15
  # in ./support/ and its subdirectories.
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restful_metrics
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
4
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 0
10
- version: 1.0.0
5
+ version: 1.0.1
11
6
  platform: ruby
12
7
  authors:
13
8
  - Mauricio Gomes
@@ -15,257 +10,187 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-06-29 00:00:00 -04:00
13
+ date: 2011-09-12 00:00:00 -04:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
- type: :runtime
17
+ name: yajl-ruby
24
18
  requirement: &id001 !ruby/object:Gem::Requirement
25
19
  none: false
26
20
  requirements:
27
21
  - - ~>
28
22
  - !ruby/object:Gem::Version
29
- hash: 61
30
- segments:
31
- - 0
32
- - 8
33
- - 1
34
23
  version: 0.8.1
35
- name: yajl-ruby
24
+ type: :runtime
25
+ prerelease: false
36
26
  version_requirements: *id001
37
27
  - !ruby/object:Gem::Dependency
38
- prerelease: false
39
- type: :runtime
28
+ name: rest-client
40
29
  requirement: &id002 !ruby/object:Gem::Requirement
41
30
  none: false
42
31
  requirements:
43
32
  - - ~>
44
33
  - !ruby/object:Gem::Version
45
- hash: 15
46
- segments:
47
- - 1
48
- - 6
49
- - 0
50
34
  version: 1.6.0
51
- name: rest-client
35
+ type: :runtime
36
+ prerelease: false
52
37
  version_requirements: *id002
53
38
  - !ruby/object:Gem::Dependency
54
- prerelease: false
55
- type: :development
39
+ name: jeweler
56
40
  requirement: &id003 !ruby/object:Gem::Requirement
57
41
  none: false
58
42
  requirements:
59
43
  - - ">="
60
44
  - !ruby/object:Gem::Version
61
- hash: 3
62
- segments:
63
- - 0
64
45
  version: "0"
65
- name: jeweler
46
+ type: :development
47
+ prerelease: false
66
48
  version_requirements: *id003
67
49
  - !ruby/object:Gem::Dependency
68
- prerelease: false
69
- type: :development
50
+ name: i18n
70
51
  requirement: &id004 !ruby/object:Gem::Requirement
71
52
  none: false
72
53
  requirements:
73
54
  - - ">="
74
55
  - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 0
78
56
  version: "0"
79
- name: i18n
57
+ type: :development
58
+ prerelease: false
80
59
  version_requirements: *id004
81
60
  - !ruby/object:Gem::Dependency
82
- prerelease: false
83
- type: :development
61
+ name: actionpack
84
62
  requirement: &id005 !ruby/object:Gem::Requirement
85
63
  none: false
86
64
  requirements:
87
- - - ">="
65
+ - - ~>
88
66
  - !ruby/object:Gem::Version
89
- hash: 17
90
- segments:
91
- - 2
92
- - 3
93
- - 9
94
67
  version: 2.3.9
95
- name: actionpack
68
+ type: :development
69
+ prerelease: false
96
70
  version_requirements: *id005
97
71
  - !ruby/object:Gem::Dependency
98
- prerelease: false
99
- type: :development
72
+ name: activesupport
100
73
  requirement: &id006 !ruby/object:Gem::Requirement
101
74
  none: false
102
75
  requirements:
103
- - - ">="
76
+ - - ~>
104
77
  - !ruby/object:Gem::Version
105
- hash: 17
106
- segments:
107
- - 2
108
- - 3
109
- - 9
110
78
  version: 2.3.9
111
- name: activesupport
79
+ type: :development
80
+ prerelease: false
112
81
  version_requirements: *id006
113
82
  - !ruby/object:Gem::Dependency
114
- prerelease: false
115
- type: :development
83
+ name: delayed_job
116
84
  requirement: &id007 !ruby/object:Gem::Requirement
117
85
  none: false
118
86
  requirements:
119
87
  - - ~>
120
88
  - !ruby/object:Gem::Version
121
- hash: 15
122
- segments:
123
- - 2
124
- - 0
125
- - 0
126
89
  version: 2.0.0
127
- name: delayed_job
90
+ type: :development
91
+ prerelease: false
128
92
  version_requirements: *id007
129
93
  - !ruby/object:Gem::Dependency
130
- prerelease: false
131
- type: :development
94
+ name: rspec
132
95
  requirement: &id008 !ruby/object:Gem::Requirement
133
96
  none: false
134
97
  requirements:
135
98
  - - ~>
136
99
  - !ruby/object:Gem::Version
137
- hash: 27
138
- segments:
139
- - 2
140
- - 5
141
- - 0
142
100
  version: 2.5.0
143
- name: rspec
101
+ type: :development
102
+ prerelease: false
144
103
  version_requirements: *id008
145
104
  - !ruby/object:Gem::Dependency
146
- prerelease: false
147
- type: :development
105
+ name: mocha
148
106
  requirement: &id009 !ruby/object:Gem::Requirement
149
107
  none: false
150
108
  requirements:
151
109
  - - ">="
152
110
  - !ruby/object:Gem::Version
153
- hash: 3
154
- segments:
155
- - 0
156
111
  version: "0"
157
- name: mocha
112
+ type: :development
113
+ prerelease: false
158
114
  version_requirements: *id009
159
115
  - !ruby/object:Gem::Dependency
160
- prerelease: false
161
- type: :runtime
116
+ name: yajl-ruby
162
117
  requirement: &id010 !ruby/object:Gem::Requirement
163
118
  none: false
164
119
  requirements:
165
120
  - - ~>
166
121
  - !ruby/object:Gem::Version
167
- hash: 59
168
- segments:
169
- - 0
170
- - 8
171
- - 2
172
122
  version: 0.8.2
173
- name: yajl-ruby
123
+ type: :runtime
124
+ prerelease: false
174
125
  version_requirements: *id010
175
126
  - !ruby/object:Gem::Dependency
176
- prerelease: false
177
- type: :runtime
127
+ name: rest-client
178
128
  requirement: &id011 !ruby/object:Gem::Requirement
179
129
  none: false
180
130
  requirements:
181
131
  - - ~>
182
132
  - !ruby/object:Gem::Version
183
- hash: 15
184
- segments:
185
- - 1
186
- - 6
187
- - 0
188
133
  version: 1.6.0
189
- name: rest-client
134
+ type: :runtime
135
+ prerelease: false
190
136
  version_requirements: *id011
191
137
  - !ruby/object:Gem::Dependency
192
- prerelease: false
193
- type: :development
138
+ name: rack
194
139
  requirement: &id012 !ruby/object:Gem::Requirement
195
140
  none: false
196
141
  requirements:
197
142
  - - ">"
198
143
  - !ruby/object:Gem::Version
199
- hash: 23
200
- segments:
201
- - 1
202
- - 0
203
- - 0
204
144
  version: 1.0.0
205
- name: rack
145
+ type: :development
146
+ prerelease: false
206
147
  version_requirements: *id012
207
148
  - !ruby/object:Gem::Dependency
208
- prerelease: false
209
- type: :development
149
+ name: i18n
210
150
  requirement: &id013 !ruby/object:Gem::Requirement
211
151
  none: false
212
152
  requirements:
213
153
  - - ">="
214
154
  - !ruby/object:Gem::Version
215
- hash: 3
216
- segments:
217
- - 0
218
155
  version: "0"
219
- name: i18n
156
+ type: :development
157
+ prerelease: false
220
158
  version_requirements: *id013
221
159
  - !ruby/object:Gem::Dependency
222
- prerelease: false
223
- type: :development
160
+ name: activesupport
224
161
  requirement: &id014 !ruby/object:Gem::Requirement
225
162
  none: false
226
163
  requirements:
227
164
  - - ">="
228
165
  - !ruby/object:Gem::Version
229
- hash: 3
230
- segments:
231
- - 0
232
166
  version: "0"
233
- name: activesupport
167
+ type: :development
168
+ prerelease: false
234
169
  version_requirements: *id014
235
170
  - !ruby/object:Gem::Dependency
236
- prerelease: false
237
- type: :development
171
+ name: delayed_job
238
172
  requirement: &id015 !ruby/object:Gem::Requirement
239
173
  none: false
240
174
  requirements:
241
175
  - - <
242
176
  - !ruby/object:Gem::Version
243
- hash: 11
244
- segments:
245
- - 2
246
- - 1
247
- - 0
248
177
  version: 2.1.0
249
- name: delayed_job
178
+ type: :development
179
+ prerelease: false
250
180
  version_requirements: *id015
251
181
  - !ruby/object:Gem::Dependency
252
- prerelease: false
253
- type: :development
182
+ name: rspec
254
183
  requirement: &id016 !ruby/object:Gem::Requirement
255
184
  none: false
256
185
  requirements:
257
186
  - - <
258
187
  - !ruby/object:Gem::Version
259
- hash: 15
260
- segments:
261
- - 2
262
- - 0
263
- - 0
264
188
  version: 2.0.0
265
- name: rspec
189
+ type: :development
190
+ prerelease: false
266
191
  version_requirements: *id016
267
- description: Ruby client for the Restful Metrics service.
268
- email: mgomes@geminisbs.com
192
+ description: Ruby client for the RESTful Metrics service.
193
+ email: mauricio@restful-labs.com
269
194
  executables: []
270
195
 
271
196
  extensions: []
@@ -275,6 +200,7 @@ extra_rdoc_files:
275
200
  - README.md
276
201
  files:
277
202
  - LICENSE
203
+ - README.md
278
204
  - VERSION
279
205
  - lib/delayed/backend/mock.rb
280
206
  - lib/restful_metrics.rb
@@ -283,13 +209,12 @@ files:
283
209
  - lib/restful_metrics/endpoint.rb
284
210
  - lib/restful_metrics/log_tools.rb
285
211
  - lib/restful_metrics/railtie/cookie_integration.rb
286
- - README.md
287
212
  - spec/client_spec.rb
288
213
  - spec/cookie_integration_spec.rb
289
214
  - spec/endpoint_spec.rb
290
215
  - spec/spec_helper.rb
291
216
  has_rdoc: true
292
- homepage: http://github.com/geminisbs/restful_metrics-ruby
217
+ homepage: http://restfulmetrics.com
293
218
  licenses: []
294
219
 
295
220
  post_install_message:
@@ -302,7 +227,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
302
227
  requirements:
303
228
  - - ">="
304
229
  - !ruby/object:Gem::Version
305
- hash: 3
230
+ hash: 174319405052663915
306
231
  segments:
307
232
  - 0
308
233
  version: "0"
@@ -311,17 +236,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
311
236
  requirements:
312
237
  - - ">="
313
238
  - !ruby/object:Gem::Version
314
- hash: 3
315
- segments:
316
- - 0
317
239
  version: "0"
318
240
  requirements: []
319
241
 
320
242
  rubyforge_project:
321
- rubygems_version: 1.6.2
243
+ rubygems_version: 1.5.2
322
244
  signing_key:
323
245
  specification_version: 3
324
- summary: Ruby client for Restful Metrics
246
+ summary: Ruby client for RESTful Metrics
325
247
  test_files:
326
248
  - spec/client_spec.rb
327
249
  - spec/cookie_integration_spec.rb