restful_metrics 0.5.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/LICENSE +20 -0
- data/README.md +15 -0
- data/VERSION +1 -0
- data/lib/delayed/backend/mock.rb +25 -0
- data/lib/restful_metrics/client.rb +122 -0
- data/lib/restful_metrics/connection.rb +98 -0
- data/lib/restful_metrics/endpoint.rb +23 -0
- data/lib/restful_metrics/log_tools.rb +22 -0
- data/lib/restful_metrics/railtie/cookie_integration.rb +44 -0
- data/lib/restful_metrics.rb +35 -0
- data/spec/client_spec.rb +134 -0
- data/spec/cookie_integration_spec.rb +42 -0
- data/spec/endpoint_spec.rb +13 -0
- data/spec/spec_helper.rb +37 -0
- metadata +251 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Restful Labs LLC.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Restful Metrics Ruby Client #
|
2
|
+
|
3
|
+
Tracks your app's custom metrics.
|
4
|
+
|
5
|
+
## Status ##
|
6
|
+
|
7
|
+
This gem is currently unreleased.
|
8
|
+
|
9
|
+
## Copyright ##
|
10
|
+
|
11
|
+
Copyright (c) 2011 Restful Labs LLC. See LICENSE for details.
|
12
|
+
|
13
|
+
## Authors ##
|
14
|
+
|
15
|
+
* [Mauricio Gomes](http://github.com/mgomes)
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.5.1
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Used by Delayed::Job during testing
|
2
|
+
|
3
|
+
module Delayed
|
4
|
+
module Backend
|
5
|
+
module Mock
|
6
|
+
class Job
|
7
|
+
include Delayed::Backend::Base
|
8
|
+
|
9
|
+
@@job_count = 0
|
10
|
+
|
11
|
+
def self.create(params)
|
12
|
+
@@job_count += 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.count
|
16
|
+
@@job_count
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.reset
|
20
|
+
@@job_count = 0
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
module RestfulMetrics
|
2
|
+
|
3
|
+
class Client
|
4
|
+
|
5
|
+
extend LogTools
|
6
|
+
|
7
|
+
@@connection = nil
|
8
|
+
@@debug, @@async, @@disabled = false
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def set_credentials(api_key)
|
13
|
+
@@connection = Connection.new(api_key)
|
14
|
+
self.debug = @@debug
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def debug=(debug_flag)
|
19
|
+
@@debug = debug_flag
|
20
|
+
@@connection.debug = @@debug if @@connection
|
21
|
+
end
|
22
|
+
|
23
|
+
def debug
|
24
|
+
@@debug
|
25
|
+
end
|
26
|
+
|
27
|
+
def async=(async_flag)
|
28
|
+
@@async = async_flag && (defined?(Delayed) != nil)
|
29
|
+
@@connection.async = @@async if @@connection
|
30
|
+
end
|
31
|
+
|
32
|
+
def async?
|
33
|
+
@@async
|
34
|
+
end
|
35
|
+
|
36
|
+
def disabled=(disabled_flag)
|
37
|
+
@@disabled = disabled_flag
|
38
|
+
end
|
39
|
+
|
40
|
+
def disabled?
|
41
|
+
@@disabled
|
42
|
+
end
|
43
|
+
|
44
|
+
def add_metric(fqdn, name, value, distinct_id = nil)
|
45
|
+
params = Hash.new
|
46
|
+
params[:metric] = Hash.new
|
47
|
+
params[:metric][:fqdn] = fqdn
|
48
|
+
params[:metric][:name] = name
|
49
|
+
params[:metric][:value] = value
|
50
|
+
unless distinct_id.nil?
|
51
|
+
params[:metric][:distinct_id] = distinct_id
|
52
|
+
end
|
53
|
+
|
54
|
+
post(Endpoint.metrics, params)
|
55
|
+
end
|
56
|
+
|
57
|
+
def add_compound_metric(fqdn, name, values, distinct_id = nil)
|
58
|
+
params = Hash.new
|
59
|
+
params[:compound_metric] = Hash.new
|
60
|
+
params[:compound_metric][:fqdn] = fqdn
|
61
|
+
params[:compound_metric][:name] = name
|
62
|
+
params[:compound_metric][:values] = values
|
63
|
+
unless distinct_id.nil?
|
64
|
+
params[:compound_metric][:distinct_id] = distinct_id
|
65
|
+
end
|
66
|
+
|
67
|
+
post(Endpoint.compound_metrics, params)
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def post(endpoint, data=nil)
|
73
|
+
return false if disabled?
|
74
|
+
raise NoConnectionEstablished if @@connection.nil?
|
75
|
+
|
76
|
+
unless production_env?
|
77
|
+
logger "Skipping while not in production", :info
|
78
|
+
return false
|
79
|
+
end
|
80
|
+
|
81
|
+
if async?
|
82
|
+
self.delay.transmit endpoint, data
|
83
|
+
true
|
84
|
+
else
|
85
|
+
transmit endpoint, data
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def transmit(endpoint, data)
|
90
|
+
begin
|
91
|
+
@@connection.post(endpoint, data)
|
92
|
+
true
|
93
|
+
rescue
|
94
|
+
logger "There was an error communicating with the server"
|
95
|
+
false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def extract_options!(args)
|
100
|
+
if args.last.is_a?(Hash)
|
101
|
+
return args.pop
|
102
|
+
else
|
103
|
+
return {}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def production_env?
|
108
|
+
return true if defined?(RAILS_ENV) && RAILS_ENV == "production"
|
109
|
+
return true if defined?(RACK_ENV) && RACK_ENV == "production"
|
110
|
+
|
111
|
+
if defined?(Rails.env) && Rails.env == "production"
|
112
|
+
return true
|
113
|
+
end
|
114
|
+
|
115
|
+
false
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module RestfulMetrics
|
2
|
+
|
3
|
+
class Connection
|
4
|
+
|
5
|
+
include RestfulMetrics::LogTools
|
6
|
+
|
7
|
+
attr_accessor :debug, :async
|
8
|
+
attr_reader :api_key, :default_options
|
9
|
+
|
10
|
+
def initialize(api_key)
|
11
|
+
@api_key = api_key
|
12
|
+
@default_options = { :api_key => @api_key }
|
13
|
+
@debug = false
|
14
|
+
@async = false
|
15
|
+
end
|
16
|
+
|
17
|
+
def post(endpoint, data=nil)
|
18
|
+
request :post, endpoint, data
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def request(method, endpoint, data=nil)
|
24
|
+
headers = { 'User-Agent' => "Restful Metrics Ruby Client v#{VERSION}",
|
25
|
+
'Content-Type' => "application/json" }
|
26
|
+
|
27
|
+
if data.nil?
|
28
|
+
data = @default_options
|
29
|
+
else
|
30
|
+
data.merge!(@default_options)
|
31
|
+
end
|
32
|
+
|
33
|
+
if debug
|
34
|
+
puts "request: #{method.to_s.upcase} #{endpoint}"
|
35
|
+
puts "headers:"
|
36
|
+
headers.each do |key, value|
|
37
|
+
puts "#{key}=#{value}"
|
38
|
+
end
|
39
|
+
if [:post, :put].include?(method)
|
40
|
+
puts "data:"
|
41
|
+
puts Yajl::Encoder.encode data
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
begin
|
46
|
+
data = Yajl::Encoder.encode data
|
47
|
+
rescue
|
48
|
+
logger "there was an error encoding your submission: #{$!}"
|
49
|
+
return nil
|
50
|
+
end
|
51
|
+
|
52
|
+
response = send_request(method, endpoint, headers, data)
|
53
|
+
|
54
|
+
if debug
|
55
|
+
if response.nil?
|
56
|
+
puts "There was an error processing the response from Restful Metrics."
|
57
|
+
else
|
58
|
+
puts "\nresponse: #{response.code}"
|
59
|
+
puts "headers:"
|
60
|
+
response.header.each do |key, value|
|
61
|
+
puts "#{key}=#{value}"
|
62
|
+
end
|
63
|
+
puts "body:"
|
64
|
+
puts response.body
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
if response.nil? || response.body.empty?
|
69
|
+
content = nil
|
70
|
+
else
|
71
|
+
begin
|
72
|
+
content = Yajl::Parser.new.parse(response.body)
|
73
|
+
rescue
|
74
|
+
logger "received invalid response: #{$!}"
|
75
|
+
return "{}"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
content
|
80
|
+
end
|
81
|
+
|
82
|
+
def send_request(method, endpoint, headers, data=nil)
|
83
|
+
begin
|
84
|
+
response = RestClient::Request.execute(:method => :post,
|
85
|
+
:url => endpoint,
|
86
|
+
:payload => data,
|
87
|
+
:headers => headers)
|
88
|
+
rescue => e
|
89
|
+
logger "there was an error transmitting your entry: #{$!}"
|
90
|
+
return nil
|
91
|
+
end
|
92
|
+
|
93
|
+
response
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module RestfulMetrics
|
2
|
+
|
3
|
+
class Endpoint
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def metrics
|
8
|
+
endpoint_url "metrics.json"
|
9
|
+
end
|
10
|
+
|
11
|
+
def compound_metrics
|
12
|
+
endpoint_url "compound_metrics.json"
|
13
|
+
end
|
14
|
+
|
15
|
+
def endpoint_url(path)
|
16
|
+
[REALM, path].join('/')
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
unless defined?(Logger)
|
2
|
+
require 'logger'
|
3
|
+
end
|
4
|
+
|
5
|
+
module RestfulMetrics
|
6
|
+
|
7
|
+
module LogTools
|
8
|
+
|
9
|
+
def logger(msg, level = :warn)
|
10
|
+
msg = "#### Restful Metrics #### " + msg
|
11
|
+
if defined?(Rails) && defined?(Rails.logger)
|
12
|
+
log = Rails.logger
|
13
|
+
else
|
14
|
+
log = Logger.new(STDOUT)
|
15
|
+
end
|
16
|
+
|
17
|
+
level == :warn ? log.warn(msg) : log.info(msg)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module RestfulMetrics
|
2
|
+
|
3
|
+
module ControllerMethods # :nodoc:
|
4
|
+
|
5
|
+
module InstanceMethods # :nodoc:
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def restful_metrics_cookie
|
10
|
+
if cookies
|
11
|
+
if cookies[:analytico]
|
12
|
+
cookie_value = cookies[:analytico]
|
13
|
+
elsif cookies[:restful_metrics]
|
14
|
+
cookie_value = cookies[:restful_metrics]
|
15
|
+
else
|
16
|
+
cookie_value = generate_distinct_id
|
17
|
+
cookies[:restful_metrics] = {
|
18
|
+
:value => cookie_value,
|
19
|
+
:expires => 2.years.from_now,
|
20
|
+
:domain => request.host
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
cookie_value
|
25
|
+
else
|
26
|
+
nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def generate_distinct_id
|
31
|
+
digest = Digest::MD5.new
|
32
|
+
digest << "#{Time.now}-#{rand(999999)}"
|
33
|
+
digest.to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
if defined?(ActionController::Base)
|
39
|
+
ActionController::Base.send(:include, ControllerMethods::InstanceMethods)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'yajl'
|
3
|
+
require 'rest_client'
|
4
|
+
|
5
|
+
if !defined?(Logger)
|
6
|
+
require 'logger'
|
7
|
+
end
|
8
|
+
|
9
|
+
# Restful Metrics specific libs
|
10
|
+
require 'restful_metrics/log_tools'
|
11
|
+
require 'restful_metrics/connection'
|
12
|
+
require 'restful_metrics/endpoint'
|
13
|
+
require 'restful_metrics/client'
|
14
|
+
|
15
|
+
# Rails integration
|
16
|
+
require 'restful_metrics/railtie/cookie_integration'
|
17
|
+
|
18
|
+
module RestfulMetrics
|
19
|
+
|
20
|
+
REALM = "http://analytico.heroku.com"
|
21
|
+
VERSION = File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
|
22
|
+
|
23
|
+
class RestfulMetricsError < StandardError; end
|
24
|
+
class InsufficentArguments < RestfulMetricsError; end
|
25
|
+
class InvalidAPIKey < RestfulMetricsError; end
|
26
|
+
class NoConnectionEstablished < RestfulMetricsError; end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
# DelayedJob integration
|
31
|
+
begin
|
32
|
+
require 'delayed_job'
|
33
|
+
rescue LoadError
|
34
|
+
RestfulMetrics.logger 'Running in synchronous mode.'
|
35
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "A NON-initialized Restful Metrics client" do
|
4
|
+
|
5
|
+
it "should NOT send a metric if a connection is not initialized" do
|
6
|
+
lambda {
|
7
|
+
RestfulMetrics::Client.add_metric("foo.bar.org", "hit", 1)
|
8
|
+
}.should raise_error(RestfulMetrics::NoConnectionEstablished)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should NOT send a compound metric if a connection is not initialized" do
|
12
|
+
lambda {
|
13
|
+
RestfulMetrics::Client.add_compound_metric("foo.bar.org", "hit", [1,2,3])
|
14
|
+
}.should raise_error(RestfulMetrics::NoConnectionEstablished)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "A disabled Restful Metrics client" do
|
20
|
+
|
21
|
+
before(:each) do
|
22
|
+
RestfulMetrics::Client.disabled = true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should identify itself as disabled" do
|
26
|
+
RestfulMetrics::Client.disabled?.should == true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should NOT send a metric if the client is in disabled-mode" do
|
30
|
+
RestfulMetrics::Client.expects(:transmit).never
|
31
|
+
RestfulMetrics::Client.add_metric("foo.bar.org", "hit", 1).should == false
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should NOT send a compound metric if the client is in disabled-mode" do
|
35
|
+
RestfulMetrics::Client.expects(:transmit).never
|
36
|
+
RestfulMetrics::Client.add_compound_metric("foo.bar.org", "hit", [1,2,3]).should == false
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "An initialized Restful Metrics client" do
|
42
|
+
|
43
|
+
before(:each) do
|
44
|
+
@connection = RestfulMetrics::Connection
|
45
|
+
@connection.any_instance.stubs(:post).returns(true)
|
46
|
+
RestfulMetrics::Client.set_credentials('xyz123')
|
47
|
+
RestfulMetrics::Client.disabled = false
|
48
|
+
Delayed::Job.reset
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "initializing the client" do
|
52
|
+
|
53
|
+
it "should set the API key" do
|
54
|
+
RestfulMetrics::Client.set_credentials('4ed4ef44e44ed4').should be_true
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should set async mode when delayed_job is loaded" do
|
58
|
+
RestfulMetrics::Client.async = true
|
59
|
+
RestfulMetrics::Client.async?.should be_true
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "environment detection" do
|
65
|
+
|
66
|
+
it "should return false if NOT in production" do
|
67
|
+
rails_env "development" do
|
68
|
+
RestfulMetrics::Client.expects(:logger).returns('')
|
69
|
+
RestfulMetrics::Client.add_metric("foo.bar.org", "hit", 1).should be_false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should successfully send the request if in Rails production mode" do
|
74
|
+
rails_env "production" do
|
75
|
+
@connection.any_instance.stubs(:post).returns(100)
|
76
|
+
RestfulMetrics::Client.add_metric("foo.bar.org", "hit", 1).should be_true
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should successfully send the request if in Rack production mode" do
|
81
|
+
RACK_ENV = "production"
|
82
|
+
@connection.any_instance.stubs(:post).returns(100)
|
83
|
+
RestfulMetrics::Client.add_metric("foo.bar.org", "hit", 1).should be_true
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
describe "adding metrics synchronously" do
|
89
|
+
|
90
|
+
before(:all) do
|
91
|
+
RestfulMetrics::Client.async = false
|
92
|
+
RestfulMetrics::Client.async?.should be_false
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should send the metric to Restful Metrics" do
|
96
|
+
rails_env "production" do
|
97
|
+
@connection.any_instance.expects(:post).at_least_once.returns({})
|
98
|
+
RestfulMetrics::Client.add_metric("foo.bar.org", "hit", 1).should be_true
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should send the compound metric to Restful Metrics" do
|
103
|
+
rails_env "production" do
|
104
|
+
@connection.any_instance.expects(:post).at_least_once.returns({})
|
105
|
+
RestfulMetrics::Client.add_compound_metric("foo.bar.org", "hit", [1,2,3]).should be_true
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "adding metrics asynchronously" do
|
112
|
+
|
113
|
+
before(:all) do
|
114
|
+
RestfulMetrics::Client.async = true
|
115
|
+
RestfulMetrics::Client.async?.should be_true
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should create a delayed job for the metric" do
|
119
|
+
rails_env "production" do
|
120
|
+
RestfulMetrics::Client.add_metric("foo.bar.org", "hit", 1).should be_true
|
121
|
+
Delayed::Job.count.should == 1
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should create a delayed job for the compound metric" do
|
126
|
+
rails_env "production" do
|
127
|
+
RestfulMetrics::Client.add_compound_metric("foo.bar.org", "hit", [1,2,3]).should be_true
|
128
|
+
Delayed::Job.count.should == 1
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Rails controller integration" do
|
4
|
+
|
5
|
+
class ApplicationController < ActionController::Base
|
6
|
+
|
7
|
+
before_filter :track_impression
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def track_impression
|
12
|
+
RestfulMetrics::Client.add_metric("foo.bar.org", "impression", 1, restful_metrics_cookie)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
class TestController < ApplicationController
|
18
|
+
|
19
|
+
def index
|
20
|
+
@distinct_id = restful_metrics_cookie
|
21
|
+
RestfulMetrics::Client.add_metric("foo.bar.org", "custom", 1, @distinct_id)
|
22
|
+
render :text => "OK"
|
23
|
+
end
|
24
|
+
|
25
|
+
def rescue_action(e); raise(e); end
|
26
|
+
end
|
27
|
+
ActionController::Routing::Routes.draw {|map| map.resources :test }
|
28
|
+
|
29
|
+
before(:each) do
|
30
|
+
RestfulMetrics::Connection.any_instance.stubs(:post).returns(true)
|
31
|
+
RestfulMetrics::Client.set_credentials('xyz123')
|
32
|
+
@request = ActionController::TestRequest.new
|
33
|
+
@request.action = 'index'
|
34
|
+
@request.path = "/index"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should track all metrics in the stack" do
|
38
|
+
RestfulMetrics::Client.expects(:add_metric).twice.returns(true)
|
39
|
+
TestController.new.process(@request, ActionController::TestResponse.new).code.should == "200"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Endpoint generation" do
|
4
|
+
|
5
|
+
it "should generate endpoints for metrics" do
|
6
|
+
RestfulMetrics::Endpoint.metrics.should =~ /metrics.json/
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should generate endpoints for compound metrics" do
|
10
|
+
RestfulMetrics::Endpoint.compound_metrics.should =~ /compound_metrics.json/
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
require 'active_support'
|
5
|
+
require 'active_support/test_case'
|
6
|
+
require 'action_controller'
|
7
|
+
require 'action_controller/test_process'
|
8
|
+
|
9
|
+
require 'rspec'
|
10
|
+
require 'mocha'
|
11
|
+
require 'restful_metrics'
|
12
|
+
|
13
|
+
# Requires supporting files with custom matchers and macros, etc,
|
14
|
+
# in ./support/ and its subdirectories.
|
15
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.mock_framework = :mocha
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# Use a mock backend for testing
|
23
|
+
#
|
24
|
+
Delayed::Worker.backend = :mock
|
25
|
+
|
26
|
+
#
|
27
|
+
# Fake the rails environment for testing
|
28
|
+
#
|
29
|
+
class Rails; cattr_accessor :env; end
|
30
|
+
|
31
|
+
# Simulate Rails enviornments
|
32
|
+
def rails_env(env, &block)
|
33
|
+
old_env = Rails.env
|
34
|
+
Rails.env = env
|
35
|
+
yield
|
36
|
+
Rails.env = old_env
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,251 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: restful_metrics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.5.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mauricio Gomes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-07 00:00:00 -04:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: yajl-ruby
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.8.1
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.6.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: jeweler
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: i18n
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: actionpack
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 2.3.9
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: activesupport
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 2.3.9
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: *id006
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: delayed_job
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.0.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: *id007
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: rspec
|
95
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ~>
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 2.5.0
|
101
|
+
type: :development
|
102
|
+
prerelease: false
|
103
|
+
version_requirements: *id008
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: mocha
|
106
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: "0"
|
112
|
+
type: :development
|
113
|
+
prerelease: false
|
114
|
+
version_requirements: *id009
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: yajl-ruby
|
117
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ~>
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 0.8.2
|
123
|
+
type: :runtime
|
124
|
+
prerelease: false
|
125
|
+
version_requirements: *id010
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rest-client
|
128
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ~>
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 1.6.0
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: *id011
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: rack
|
139
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ">"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 1.0.0
|
145
|
+
type: :development
|
146
|
+
prerelease: false
|
147
|
+
version_requirements: *id012
|
148
|
+
- !ruby/object:Gem::Dependency
|
149
|
+
name: i18n
|
150
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: "0"
|
156
|
+
type: :development
|
157
|
+
prerelease: false
|
158
|
+
version_requirements: *id013
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: activesupport
|
161
|
+
requirement: &id014 !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: "0"
|
167
|
+
type: :development
|
168
|
+
prerelease: false
|
169
|
+
version_requirements: *id014
|
170
|
+
- !ruby/object:Gem::Dependency
|
171
|
+
name: delayed_job
|
172
|
+
requirement: &id015 !ruby/object:Gem::Requirement
|
173
|
+
none: false
|
174
|
+
requirements:
|
175
|
+
- - <
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: 2.1.0
|
178
|
+
type: :development
|
179
|
+
prerelease: false
|
180
|
+
version_requirements: *id015
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: rspec
|
183
|
+
requirement: &id016 !ruby/object:Gem::Requirement
|
184
|
+
none: false
|
185
|
+
requirements:
|
186
|
+
- - <
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: 2.0.0
|
189
|
+
type: :development
|
190
|
+
prerelease: false
|
191
|
+
version_requirements: *id016
|
192
|
+
description: Ruby client for the Restful Metrics service.
|
193
|
+
email: mgomes@geminisbs.com
|
194
|
+
executables: []
|
195
|
+
|
196
|
+
extensions: []
|
197
|
+
|
198
|
+
extra_rdoc_files:
|
199
|
+
- LICENSE
|
200
|
+
- README.md
|
201
|
+
files:
|
202
|
+
- LICENSE
|
203
|
+
- VERSION
|
204
|
+
- lib/delayed/backend/mock.rb
|
205
|
+
- lib/restful_metrics.rb
|
206
|
+
- lib/restful_metrics/client.rb
|
207
|
+
- lib/restful_metrics/connection.rb
|
208
|
+
- lib/restful_metrics/endpoint.rb
|
209
|
+
- lib/restful_metrics/log_tools.rb
|
210
|
+
- lib/restful_metrics/railtie/cookie_integration.rb
|
211
|
+
- README.md
|
212
|
+
- spec/client_spec.rb
|
213
|
+
- spec/cookie_integration_spec.rb
|
214
|
+
- spec/endpoint_spec.rb
|
215
|
+
- spec/spec_helper.rb
|
216
|
+
has_rdoc: true
|
217
|
+
homepage: http://github.com/geminisbs/restful_metrics-ruby
|
218
|
+
licenses: []
|
219
|
+
|
220
|
+
post_install_message:
|
221
|
+
rdoc_options: []
|
222
|
+
|
223
|
+
require_paths:
|
224
|
+
- lib
|
225
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
226
|
+
none: false
|
227
|
+
requirements:
|
228
|
+
- - ">="
|
229
|
+
- !ruby/object:Gem::Version
|
230
|
+
hash: -1672480690516068683
|
231
|
+
segments:
|
232
|
+
- 0
|
233
|
+
version: "0"
|
234
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
235
|
+
none: false
|
236
|
+
requirements:
|
237
|
+
- - ">="
|
238
|
+
- !ruby/object:Gem::Version
|
239
|
+
version: "0"
|
240
|
+
requirements: []
|
241
|
+
|
242
|
+
rubyforge_project:
|
243
|
+
rubygems_version: 1.5.2
|
244
|
+
signing_key:
|
245
|
+
specification_version: 3
|
246
|
+
summary: Ruby client for Restful Metrics
|
247
|
+
test_files:
|
248
|
+
- spec/client_spec.rb
|
249
|
+
- spec/cookie_integration_spec.rb
|
250
|
+
- spec/endpoint_spec.rb
|
251
|
+
- spec/spec_helper.rb
|