metric 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +18 -14
- data/lib/metric/configuration.rb +12 -3
- data/lib/metric/receive.rb +1 -1
- data/lib/metric/track.rb +1 -1
- data/lib/metric/version.rb +1 -1
- data/spec/metric/configuration_spec.rb +10 -7
- data/spec/metric/track_spec.rb +7 -0
- data/spec/spec_helper.rb +1 -1
- metadata +3 -3
data/README.markdown
CHANGED
@@ -15,6 +15,7 @@ And create the following initializer:
|
|
15
15
|
``` ruby
|
16
16
|
Metric.configure do |config|
|
17
17
|
config.api_key = "YOUR_API_KEY"
|
18
|
+
config.secret_key = "YOUR_SECRET_KEY"
|
18
19
|
end
|
19
20
|
```
|
20
21
|
|
@@ -28,33 +29,36 @@ You can track whatever metric you want, it will automatically show up in your
|
|
28
29
|
dashboard.
|
29
30
|
|
30
31
|
``` ruby
|
31
|
-
|
32
|
-
@article = Article.find(params[:id])
|
33
|
-
Metric.track("article_view")
|
34
|
-
end
|
32
|
+
Metric.track("article_view")
|
35
33
|
```
|
36
34
|
|
37
35
|
You can also add a custom amount to log multiple metrics in one go:
|
38
36
|
|
39
37
|
``` ruby
|
40
|
-
|
41
|
-
# send mails to everyone involved
|
42
|
-
Metric.track("email_notifications", {:amount => users.count})
|
43
|
-
end
|
38
|
+
Metric.track("email_notifications", {:amount => 301})
|
44
39
|
```
|
45
40
|
|
46
|
-
|
41
|
+
If you want to push old statistics into metric.io you can use the date
|
42
|
+
parameter:
|
47
43
|
|
48
44
|
``` ruby
|
49
|
-
|
50
|
-
|
51
|
-
|
45
|
+
Metric.track("signup", {:date => "20120101"})
|
46
|
+
```
|
47
|
+
|
48
|
+
To give the live event view in your dashboard some more context you can pass in
|
49
|
+
meta information:
|
50
|
+
|
51
|
+
``` ruby
|
52
|
+
Metric.track("email", {:meta => "user 1021"})
|
52
53
|
```
|
53
54
|
|
54
55
|
## Documentation
|
55
56
|
|
56
|
-
Although the code is pretty lightweight and self-explanatory,
|
57
|
+
Although the code is pretty lightweight and self-explanatory,
|
58
|
+
[documentation](http://rdoc.info/github/bittersweet/metric/master/frames)
|
59
|
+
is available via rdoc.info.
|
57
60
|
|
58
61
|
## Thanks
|
59
62
|
|
60
|
-
[jeffkreeftmeijer](https://github.com/jeffkreeftmeijer) for providing me with
|
63
|
+
[jeffkreeftmeijer](https://github.com/jeffkreeftmeijer) for providing me with
|
64
|
+
the awesome domainname!
|
data/lib/metric/configuration.rb
CHANGED
@@ -2,21 +2,30 @@ module Metric
|
|
2
2
|
|
3
3
|
# Used for configuration of the Metric gem. The only required option is
|
4
4
|
# api_key, secret_key is only used if you want to pull data out from the API
|
5
|
-
# and
|
5
|
+
# and host is used for local debugging purposes.
|
6
6
|
|
7
7
|
class Configuration
|
8
8
|
# Key used to identify the website
|
9
9
|
attr_accessor :api_key
|
10
10
|
|
11
11
|
# Allows setting a different host to send data to, used for development purposes
|
12
|
-
attr_accessor :
|
12
|
+
attr_accessor :host
|
13
13
|
|
14
14
|
# Used to generate a hash for getting data out
|
15
15
|
attr_accessor :secret_key
|
16
16
|
|
17
|
+
# Setting SSL on or off
|
18
|
+
attr_accessor :ssl
|
19
|
+
|
17
20
|
# Sets defaults
|
18
21
|
def initialize
|
19
|
-
@
|
22
|
+
@host = "api.metric.io"
|
23
|
+
@ssl = true
|
24
|
+
end
|
25
|
+
|
26
|
+
# Protocol to use
|
27
|
+
def protocol
|
28
|
+
@ssl ? "https" : "http"
|
20
29
|
end
|
21
30
|
end
|
22
31
|
end
|
data/lib/metric/receive.rb
CHANGED
@@ -22,7 +22,7 @@ module Metric
|
|
22
22
|
# @return [String]
|
23
23
|
def self.compose(metric, range)
|
24
24
|
key = "?api_key=" + Metric.configuration.api_key
|
25
|
-
url = Metric.configuration.
|
25
|
+
url = Metric.configuration.protocol + "://" + Metric.configuration.host + '/receive'
|
26
26
|
url << key
|
27
27
|
url << "&token=" + generate_token(metric)
|
28
28
|
url << parse_metric(metric)
|
data/lib/metric/track.rb
CHANGED
@@ -19,7 +19,7 @@ module Metric
|
|
19
19
|
meta = options[:meta]
|
20
20
|
|
21
21
|
key = "?api_key=" + Metric.configuration.api_key
|
22
|
-
url = Metric.configuration.
|
22
|
+
url = Metric.configuration.protocol + "://" + Metric.configuration.host + '/track'
|
23
23
|
url << key
|
24
24
|
url << "&metric=#{CGI.escape(metric)}"
|
25
25
|
url << "&amount=#{amount}" if amount
|
data/lib/metric/version.rb
CHANGED
@@ -1,22 +1,18 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Metric::Configuration do
|
4
|
-
after do
|
5
|
-
reset_config
|
6
|
-
end
|
7
|
-
|
8
4
|
it "uses configuration defaults" do
|
9
5
|
Metric.configure do |config|
|
10
6
|
config.api_key = "test"
|
11
7
|
end
|
12
|
-
Metric.configuration.
|
8
|
+
Metric.configuration.host.should == "api.metric.io"
|
13
9
|
end
|
14
10
|
|
15
11
|
it "configures metric host" do
|
16
12
|
Metric.configure do |config|
|
17
|
-
config.
|
13
|
+
config.host = "localhost:5000"
|
18
14
|
end
|
19
|
-
Metric.configuration.
|
15
|
+
Metric.configuration.host.should == "localhost:5000"
|
20
16
|
end
|
21
17
|
|
22
18
|
it "configures api_key" do
|
@@ -32,4 +28,11 @@ describe Metric::Configuration do
|
|
32
28
|
end
|
33
29
|
Metric.configuration.secret_key.should == "random_string"
|
34
30
|
end
|
31
|
+
|
32
|
+
it "configures ssl" do
|
33
|
+
Metric.configure do |config|
|
34
|
+
config.ssl = false
|
35
|
+
end
|
36
|
+
Metric.configuration.ssl.should == false
|
37
|
+
end
|
35
38
|
end
|
data/spec/metric/track_spec.rb
CHANGED
@@ -11,6 +11,13 @@ describe Metric::Track do
|
|
11
11
|
Metric::Track.track("hits")
|
12
12
|
end
|
13
13
|
|
14
|
+
it "uses http when ssl is false" do
|
15
|
+
Metric.configure do |config|
|
16
|
+
config.ssl = false
|
17
|
+
end
|
18
|
+
Metric::Track.compose("hits").should == "http://api.metric.io/track?api_key=spec&metric=hits"
|
19
|
+
end
|
20
|
+
|
14
21
|
it "encodes the input" do
|
15
22
|
url = "https://api.metric.io/track?api_key=spec&metric=hits+and+spaces"
|
16
23
|
Metric::Track.compose("hits and spaces").should == url
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED