restful_metrics 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +2 -2
- data/VERSION +1 -1
- data/lib/restful_metrics/client.rb +3 -9
- data/lib/restful_metrics/connection.rb +19 -19
- data/restful_metrics.gemspec +1 -1
- data/spec/client_spec.rb +62 -10
- metadata +18 -18
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# RESTful Metrics Ruby Client
|
2
2
|
|
3
3
|
Tracks your app's custom business metrics in your Ruby apps.
|
4
4
|
|
@@ -78,7 +78,7 @@ You would transmit this data point with the following:
|
|
78
78
|
|
79
79
|
## Copyright
|
80
80
|
|
81
|
-
Copyright (c) 2011
|
81
|
+
Copyright (c) 2011-2012 RESTful Labs LLC. See LICENSE for details.
|
82
82
|
|
83
83
|
## Authors
|
84
84
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.1.1
|
@@ -20,7 +20,7 @@ module RestfulMetrics
|
|
20
20
|
@@connection.debug = @@debug if @@connection
|
21
21
|
end
|
22
22
|
|
23
|
-
def debug
|
23
|
+
def debug?
|
24
24
|
@@debug
|
25
25
|
end
|
26
26
|
|
@@ -78,13 +78,7 @@ module RestfulMetrics
|
|
78
78
|
return false
|
79
79
|
end
|
80
80
|
|
81
|
-
if @@connection.nil?
|
82
|
-
if ENV["RESTFUL_METRICS_API_KEY"]
|
83
|
-
@@connection = Connection.new(ENV["RESTFUL_METRICS_API_KEY"])
|
84
|
-
else
|
85
|
-
raise NoConnectionEstablished
|
86
|
-
end
|
87
|
-
end
|
81
|
+
raise NoConnectionEstablished if @@connection.nil?
|
88
82
|
|
89
83
|
if async?
|
90
84
|
self.delay.transmit(endpoint, data)
|
@@ -99,7 +93,7 @@ module RestfulMetrics
|
|
99
93
|
@@connection.post(endpoint, data)
|
100
94
|
true
|
101
95
|
rescue
|
102
|
-
logger "There was an error communicating with the server"
|
96
|
+
logger "There was an error communicating with the server: #{$!}"
|
103
97
|
false
|
104
98
|
end
|
105
99
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module RestfulMetrics
|
2
2
|
|
3
3
|
class Connection
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
extend LogTools
|
6
6
|
|
7
7
|
attr_accessor :debug, :async
|
8
8
|
attr_reader :api_key, :default_options
|
@@ -23,7 +23,7 @@ module RestfulMetrics
|
|
23
23
|
def request(method, endpoint, data=nil)
|
24
24
|
headers = { 'User-Agent' => "Restful Metrics Ruby Client v#{VERSION}",
|
25
25
|
'Content-Type' => "application/json" }
|
26
|
-
|
26
|
+
|
27
27
|
if data.nil?
|
28
28
|
data = @default_options
|
29
29
|
else
|
@@ -31,14 +31,14 @@ module RestfulMetrics
|
|
31
31
|
end
|
32
32
|
|
33
33
|
if debug
|
34
|
-
|
35
|
-
|
34
|
+
logger "request: #{method.to_s.upcase} #{endpoint}"
|
35
|
+
logger "headers:"
|
36
36
|
headers.each do |key, value|
|
37
|
-
|
37
|
+
logger "#{key}=#{value}"
|
38
38
|
end
|
39
39
|
if [:post, :put].include?(method)
|
40
|
-
|
41
|
-
|
40
|
+
logger "data:"
|
41
|
+
logger Yajl::Encoder.encode data
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -48,20 +48,20 @@ module RestfulMetrics
|
|
48
48
|
logger "there was an error encoding your submission: #{$!}"
|
49
49
|
return nil
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
response = send_request(method, endpoint, headers, data)
|
53
53
|
|
54
54
|
if debug
|
55
55
|
if response.nil?
|
56
|
-
|
56
|
+
logger "There was an error processing the response from Restful Metrics."
|
57
57
|
else
|
58
|
-
|
59
|
-
|
58
|
+
logger "\nresponse: #{response.code}"
|
59
|
+
logger "headers:"
|
60
60
|
response.header.each do |key, value|
|
61
|
-
|
61
|
+
logger "#{key}=#{value}"
|
62
62
|
end
|
63
|
-
|
64
|
-
|
63
|
+
logger "body:"
|
64
|
+
logger response.body
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
@@ -79,11 +79,11 @@ module RestfulMetrics
|
|
79
79
|
content
|
80
80
|
end
|
81
81
|
|
82
|
-
def send_request(method, endpoint, headers, data=nil)
|
82
|
+
def send_request(method, endpoint, headers, data=nil)
|
83
83
|
begin
|
84
|
-
response = RestClient::Request.execute(:method => :post,
|
85
|
-
:url => endpoint,
|
86
|
-
:payload => data,
|
84
|
+
response = RestClient::Request.execute(:method => :post,
|
85
|
+
:url => endpoint,
|
86
|
+
:payload => data,
|
87
87
|
:headers => headers)
|
88
88
|
rescue => e
|
89
89
|
logger "there was an error transmitting your entry: #{$!}"
|
data/restful_metrics.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.summary = %q{Ruby client for the RESTful Metrics service.}
|
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
|
-
s.version =
|
9
|
+
s.version = File.read(File.join(File.dirname(__FILE__), 'VERSION'))
|
10
10
|
s.authors = ["Mauricio Gomes"]
|
11
11
|
s.email = "mauricio@restful-labs.com"
|
12
12
|
|
data/spec/client_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe "A NON-initialized
|
3
|
+
describe "A NON-initialized RESTful Metrics client" do
|
4
4
|
|
5
5
|
it "should NOT send a metric data point" do
|
6
6
|
lambda {
|
@@ -21,19 +21,23 @@ describe "A NON-initialized Restful Metrics client" do
|
|
21
21
|
RestfulMetrics::Connection.any_instance.stubs(:post).returns(100)
|
22
22
|
end
|
23
23
|
|
24
|
-
it "should send a metric data point" do
|
25
|
-
|
24
|
+
it "should NOT send a metric data point" do
|
25
|
+
lambda {
|
26
|
+
RestfulMetrics::Client.add_metric("foo.bar.org", "hit", 1).should be_true
|
27
|
+
}.should raise_error(RestfulMetrics::NoConnectionEstablished)
|
26
28
|
end
|
27
29
|
|
28
|
-
it "should send a compound metric data point" do
|
29
|
-
|
30
|
+
it "should NOT send a compound metric data point" do
|
31
|
+
lambda {
|
32
|
+
RestfulMetrics::Client.add_compound_metric("foo.bar.org", "hit", [1,2,3]).should be_true
|
33
|
+
}.should raise_error(RestfulMetrics::NoConnectionEstablished)
|
30
34
|
end
|
31
35
|
|
32
36
|
end
|
33
37
|
|
34
38
|
end
|
35
39
|
|
36
|
-
describe "A disabled
|
40
|
+
describe "A disabled RESTful Metrics client" do
|
37
41
|
|
38
42
|
before(:each) do
|
39
43
|
RestfulMetrics::Client.disabled = true
|
@@ -55,18 +59,58 @@ describe "A disabled Restful Metrics client" do
|
|
55
59
|
|
56
60
|
end
|
57
61
|
|
58
|
-
describe "An initialized
|
62
|
+
describe "An initialized RESTful Metrics client" do
|
59
63
|
|
60
64
|
before(:each) do
|
61
65
|
@connection = RestfulMetrics::Connection
|
62
|
-
@connection.any_instance.stubs(:post).returns(true)
|
63
66
|
RestfulMetrics::Client.set_credentials('xyz123')
|
64
67
|
RestfulMetrics::Client.disabled = false
|
65
68
|
Delayed::Job.delete_all
|
66
69
|
end
|
67
70
|
|
71
|
+
describe "in debug mode" do
|
72
|
+
|
73
|
+
class SampleRequest
|
74
|
+
|
75
|
+
def body
|
76
|
+
'{ "test": "success" }'
|
77
|
+
end
|
78
|
+
|
79
|
+
def code
|
80
|
+
200
|
81
|
+
end
|
82
|
+
|
83
|
+
def header
|
84
|
+
{ "one" => "test", "two" => "test" }
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
before(:all) do
|
90
|
+
RestfulMetrics::Client.debug = true
|
91
|
+
RestfulMetrics::Client.debug?.should be_true
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should send a metric to RESTful Metrics while outputting debug info" do
|
95
|
+
@connection.any_instance.expects(:logger).at_least_once
|
96
|
+
@connection.any_instance.expects(:send_request).once.returns(SampleRequest.new)
|
97
|
+
RestfulMetrics::Client.add_metric("foo.bar.org", "hit", 1).should == true
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should send the compound metric to RESTful Metrics while outputting debug info" do
|
101
|
+
@connection.any_instance.expects(:logger).at_least_once
|
102
|
+
@connection.any_instance.expects(:send_request).once.returns(SampleRequest.new)
|
103
|
+
RestfulMetrics::Client.add_compound_metric("foo.bar.org", "hit", [1,2,3]).should be_true
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
68
108
|
describe "initializing the client" do
|
69
109
|
|
110
|
+
before(:each) do
|
111
|
+
@connection.any_instance.stubs(:post).returns(true)
|
112
|
+
end
|
113
|
+
|
70
114
|
it "should set the API key" do
|
71
115
|
RestfulMetrics::Client.set_credentials('4ed4ef44e44ed4').should be_true
|
72
116
|
end
|
@@ -80,17 +124,21 @@ describe "An initialized Restful Metrics client" do
|
|
80
124
|
|
81
125
|
describe "adding metrics synchronously" do
|
82
126
|
|
127
|
+
before(:each) do
|
128
|
+
@connection.any_instance.stubs(:post).returns(true)
|
129
|
+
end
|
130
|
+
|
83
131
|
before(:all) do
|
84
132
|
RestfulMetrics::Client.async = false
|
85
133
|
RestfulMetrics::Client.async?.should be_false
|
86
134
|
end
|
87
135
|
|
88
|
-
it "should send the metric to
|
136
|
+
it "should send the metric to RESTful Metrics" do
|
89
137
|
@connection.any_instance.expects(:post).at_least_once.returns({})
|
90
138
|
RestfulMetrics::Client.add_metric("foo.bar.org", "hit", 1).should be_true
|
91
139
|
end
|
92
140
|
|
93
|
-
it "should send the compound metric to
|
141
|
+
it "should send the compound metric to RESTful Metrics" do
|
94
142
|
@connection.any_instance.expects(:post).at_least_once.returns({})
|
95
143
|
RestfulMetrics::Client.add_compound_metric("foo.bar.org", "hit", [1,2,3]).should be_true
|
96
144
|
end
|
@@ -99,6 +147,10 @@ describe "An initialized Restful Metrics client" do
|
|
99
147
|
|
100
148
|
describe "adding metrics asynchronously" do
|
101
149
|
|
150
|
+
before(:each) do
|
151
|
+
@connection.any_instance.stubs(:post).returns(true)
|
152
|
+
end
|
153
|
+
|
102
154
|
before(:all) do
|
103
155
|
RestfulMetrics::Client.async = true
|
104
156
|
RestfulMetrics::Client.async?.should be_true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restful_metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yajl-ruby
|
16
|
-
requirement: &
|
16
|
+
requirement: &70322334817280 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.8.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70322334817280
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rest-client
|
27
|
-
requirement: &
|
27
|
+
requirement: &70322334816280 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.6.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70322334816280
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70322334831700 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.8.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70322334831700
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: mocha
|
49
|
-
requirement: &
|
49
|
+
requirement: &70322334831000 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.10.4
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70322334831000
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: actionpack
|
60
|
-
requirement: &
|
60
|
+
requirement: &70322334830300 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 3.0.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70322334830300
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rack
|
71
|
-
requirement: &
|
71
|
+
requirement: &70322334829500 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 1.2.5
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70322334829500
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: activesupport
|
82
|
-
requirement: &
|
82
|
+
requirement: &70322334828920 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: 3.0.0
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70322334828920
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: delayed_job
|
93
|
-
requirement: &
|
93
|
+
requirement: &70322334828280 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ~>
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: 3.0.1
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70322334828280
|
102
102
|
description: Ruby client for the RESTful Metrics service.
|
103
103
|
email: mauricio@restful-labs.com
|
104
104
|
executables: []
|