metric 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ bundler_args: --binstubs
2
+
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - ree
7
+
8
+ script: "bundle exec rspec spec"
9
+
10
+ notifications:
11
+ recipients:
12
+ - markmulder@gmail.com
13
+
14
+ branches:
15
+ only:
16
+ - master
17
+
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
+ gem "ruby-debug", :platform => :ruby_18
4
+ gem "linecache19", :platform => :ruby_19
5
+ gem "ruby-debug19", :platform => :ruby_19
6
+
3
7
  gemspec
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
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  require 'rubygems'
3
2
  require 'bundler'
4
3
  Bundler::GemHelper.install_tasks
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 track(metric)
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' + key + parse_metric(metric)
18
- open(url).read
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)
@@ -1,3 +1,3 @@
1
1
  module Metric
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
data/metric.gemspec CHANGED
@@ -18,6 +18,5 @@ Gem::Specification.new do |gem|
18
18
  # Tests
19
19
  gem.add_development_dependency 'rspec'
20
20
  gem.add_development_dependency 'webmock'
21
- gem.add_development_dependency 'ruby-debug'
22
21
  end
23
22
 
data/spec/metric_spec.rb CHANGED
@@ -5,15 +5,27 @@ describe Metric do
5
5
  reset_config
6
6
  end
7
7
 
8
- it "calls metric.io" do
9
- stub_request(:get, "http://metric.io/track.js").
10
- with(:query => {"api_key" => "spec", "metric" => "hits"}).
11
- to_return(:status => 200, :body => "{\"total\":1}", :headers => {})
12
- Metric.track("hits").should == "{\"total\":1}"
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
@@ -1,4 +1,4 @@
1
- require File.join(File.dirname(__FILE__), "../lib", "metric")
1
+ require File.expand_path('../../lib/metric', __FILE__)
2
2
  require 'ruby-debug'
3
3
  require 'webmock/rspec'
4
4
 
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: 29
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
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-07-03 00:00:00 +02:00
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