metric 0.0.8 → 0.0.9

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.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
- def show
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
- def notify(users)
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
- To receive emails whenever a metric gets tracked pass in `trigger => true`
41
+ If you want to push old statistics into metric.io you can use the date
42
+ parameter:
47
43
 
48
44
  ``` ruby
49
- def register
50
- Metric.track("user_signup", {:trigger => true})
51
- end
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, [documentation](http://rdoc.info/github/bittersweet/metric/master/frames) is available via rdoc.info.
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 the awesome domainname!
63
+ [jeffkreeftmeijer](https://github.com/jeffkreeftmeijer) for providing me with
64
+ the awesome domainname!
@@ -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 metric_host is used for local debugging purposes.
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 :metric_host
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
- @metric_host = "https://api.metric.io"
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
@@ -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.metric_host + '/receive'
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.metric_host + '/track'
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
@@ -1,3 +1,3 @@
1
1
  module Metric
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -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.metric_host.should == "https://api.metric.io"
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.metric_host = "https://localhost:5000"
13
+ config.host = "localhost:5000"
18
14
  end
19
- Metric.configuration.metric_host.should == "https://localhost:5000"
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
@@ -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
@@ -10,5 +10,5 @@ def reset_config
10
10
  end
11
11
 
12
12
  RSpec.configure do |config|
13
- config.before(:all) { reset_config }
13
+ config.before(:each) { reset_config }
14
14
  end
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: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 8
10
- version: 0.0.8
9
+ - 9
10
+ version: 0.0.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mark Mulder