metric 0.0.1 → 0.0.3
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/.travis.yml +17 -0
- data/Gemfile +4 -0
- data/README.markdown +56 -0
- data/Rakefile +0 -1
- data/lib/metric.rb +19 -4
- data/lib/metric/version.rb +1 -1
- data/metric.gemspec +0 -1
- data/spec/metric_spec.rb +17 -5
- data/spec/spec_helper.rb +1 -1
- metadata +6 -18
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.markdown
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Metric
|
2
|
+
|
3
|
+
Track simple metrics via [metric.io](metric.io).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add the following anywhere in your Gemfile and run `bundle install`.
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
gem 'metric'
|
11
|
+
```
|
12
|
+
|
13
|
+
And create the following initializer:
|
14
|
+
|
15
|
+
``` ruby
|
16
|
+
Metric.configure do |config|
|
17
|
+
config.api_key = "YOUR_API_KEY"
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
Now you are all set to start tracking some metrics!
|
22
|
+
|
23
|
+
Note: If you are using Rails it will only track events in Production mode.
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
You can track whatever metric you want, it will automatically show up in your
|
28
|
+
dashboard.
|
29
|
+
|
30
|
+
``` ruby
|
31
|
+
def show
|
32
|
+
@article = Article.find(params[:id])
|
33
|
+
Metric.track("article_view")
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
You can also add a custom amount to log multiple metrics in one go:
|
38
|
+
|
39
|
+
``` ruby
|
40
|
+
def notify(users)
|
41
|
+
# send mails to everyone involved
|
42
|
+
Metric.track("email_notifications", {:amount => users.count})
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
To receive emails whenever a metric gets tracked pass in `trigger => true`
|
47
|
+
|
48
|
+
``` ruby
|
49
|
+
def register
|
50
|
+
Metric.track("user_signup", {:trigger => true})
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
## Thanks
|
55
|
+
|
56
|
+
[jeffkreeftmeijer](https://github.com/jeffkreeftmeijer) for providing me with the awesome domainname!
|
data/Rakefile
CHANGED
data/lib/metric.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'metric/version'
|
2
1
|
require 'metric/configuration'
|
3
2
|
require 'open-uri'
|
4
3
|
require 'cgi'
|
@@ -12,10 +11,26 @@ module Metric
|
|
12
11
|
yield(configuration)
|
13
12
|
end
|
14
13
|
|
15
|
-
def
|
14
|
+
def compose(metric, options = {})
|
15
|
+
amount = options[:amount]
|
16
|
+
trigger = options[:trigger]
|
17
|
+
|
16
18
|
key = "?api_key=" + Metric.configuration.api_key
|
17
|
-
url = Metric.configuration.metric_host + '/track.js'
|
18
|
-
|
19
|
+
url = Metric.configuration.metric_host + '/track.js'
|
20
|
+
url << key
|
21
|
+
url << parse_metric(metric)
|
22
|
+
url << "&amount=#{amount}" if amount
|
23
|
+
url << "&trigger=1" if trigger
|
24
|
+
url
|
25
|
+
end
|
26
|
+
|
27
|
+
def track(metric, options = {})
|
28
|
+
return if defined?(Rails) && !Rails.env.production?
|
29
|
+
|
30
|
+
url = compose(metric, options)
|
31
|
+
Thread.new do
|
32
|
+
`curl "#{url}" 2>&1 ; `
|
33
|
+
end
|
19
34
|
end
|
20
35
|
|
21
36
|
def parse_metric(metric)
|
data/lib/metric/version.rb
CHANGED
data/metric.gemspec
CHANGED
data/spec/metric_spec.rb
CHANGED
@@ -5,15 +5,27 @@ describe Metric do
|
|
5
5
|
reset_config
|
6
6
|
end
|
7
7
|
|
8
|
-
it "
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
it "composes the request url" do
|
9
|
+
Metric.compose("hits").should == "http://metric.io/track.js?api_key=spec&metric=hits"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "gets correct url when tracking" do
|
13
|
+
Metric.should_receive(:compose).with("hits", {})
|
14
|
+
Metric.track("hits")
|
13
15
|
end
|
14
16
|
|
15
17
|
it "encodes the request url" do
|
16
18
|
Metric.parse_metric("hits and spaces").should == "&metric=hits+and+spaces"
|
17
19
|
end
|
20
|
+
|
21
|
+
it "sends trigger param" do
|
22
|
+
url = "http://metric.io/track.js?api_key=spec&metric=hits&trigger=1"
|
23
|
+
Metric.compose("hits", {:trigger => true}).should == url
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sends custom amount" do
|
27
|
+
url = "http://metric.io/track.js?api_key=spec&metric=hits&amount=42"
|
28
|
+
Metric.compose("hits", {:amount => 42}).should == url
|
29
|
+
end
|
18
30
|
end
|
19
31
|
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metric
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mark Mulder
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-08-16 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -46,20 +46,6 @@ dependencies:
|
|
46
46
|
version: "0"
|
47
47
|
type: :development
|
48
48
|
version_requirements: *id002
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: ruby-debug
|
51
|
-
prerelease: false
|
52
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
|
-
requirements:
|
55
|
-
- - ">="
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
hash: 3
|
58
|
-
segments:
|
59
|
-
- 0
|
60
|
-
version: "0"
|
61
|
-
type: :development
|
62
|
-
version_requirements: *id003
|
63
49
|
description: Track metrics via metric.io
|
64
50
|
email:
|
65
51
|
- markmulder@gmail.com
|
@@ -71,7 +57,9 @@ extra_rdoc_files: []
|
|
71
57
|
|
72
58
|
files:
|
73
59
|
- .gitignore
|
60
|
+
- .travis.yml
|
74
61
|
- Gemfile
|
62
|
+
- README.markdown
|
75
63
|
- Rakefile
|
76
64
|
- lib/metric.rb
|
77
65
|
- lib/metric/configuration.rb
|