metric 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/Rakefile +4 -0
- data/lib/metric.rb +26 -0
- data/lib/metric/configuration.rb +12 -0
- data/lib/metric/version.rb +3 -0
- data/metric.gemspec +23 -0
- data/spec/metric/configuration_spec.rb +24 -0
- data/spec/metric_spec.rb +19 -0
- data/spec/spec_helper.rb +11 -0
- metadata +120 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/lib/metric.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'metric/version'
|
2
|
+
require 'metric/configuration'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
module Metric
|
7
|
+
class << self
|
8
|
+
attr_accessor :configuration
|
9
|
+
|
10
|
+
def configure
|
11
|
+
self.configuration ||= Metric::Configuration.new
|
12
|
+
yield(configuration)
|
13
|
+
end
|
14
|
+
|
15
|
+
def track(metric)
|
16
|
+
key = "?api_key=" + Metric.configuration.api_key
|
17
|
+
url = Metric.configuration.metric_host + '/track.js' + key + parse_metric(metric)
|
18
|
+
open(url).read
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_metric(metric)
|
22
|
+
"&metric=#{CGI.escape(metric)}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
data/metric.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/metric/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Mark Mulder"]
|
6
|
+
gem.email = ["markmulder@gmail.com"]
|
7
|
+
gem.description = "Track metrics via metric.io"
|
8
|
+
gem.summary = "Companion gem to the metric.io site to track metrics"
|
9
|
+
gem.homepage = 'http://github.com/bittersweet/metric'
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "metric"
|
15
|
+
gem.require_paths = ['lib']
|
16
|
+
gem.version = Metric::VERSION
|
17
|
+
|
18
|
+
# Tests
|
19
|
+
gem.add_development_dependency 'rspec'
|
20
|
+
gem.add_development_dependency 'webmock'
|
21
|
+
gem.add_development_dependency 'ruby-debug'
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Metric::Configuration do
|
4
|
+
it "uses configuration defaults" do
|
5
|
+
Metric.configure do |config|
|
6
|
+
config.api_key = "test"
|
7
|
+
end
|
8
|
+
Metric.configuration.metric_host.should == "http://metric.io"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "configures api_key" do
|
12
|
+
Metric.configure do |config|
|
13
|
+
config.api_key = "test"
|
14
|
+
end
|
15
|
+
Metric.configuration.api_key.should == "test"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "configures metric host" do
|
19
|
+
Metric.configure do |config|
|
20
|
+
config.metric_host = "http://localhost:5000"
|
21
|
+
end
|
22
|
+
Metric.configuration.metric_host.should == "http://localhost:5000"
|
23
|
+
end
|
24
|
+
end
|
data/spec/metric_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Metric do
|
4
|
+
before do
|
5
|
+
reset_config
|
6
|
+
end
|
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}"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "encodes the request url" do
|
16
|
+
Metric.parse_metric("hits and spaces").should == "&metric=hits+and+spaces"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: metric
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Mark Mulder
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-07-03 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rspec
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: webmock
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
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
|
+
description: Track metrics via metric.io
|
64
|
+
email:
|
65
|
+
- markmulder@gmail.com
|
66
|
+
executables: []
|
67
|
+
|
68
|
+
extensions: []
|
69
|
+
|
70
|
+
extra_rdoc_files: []
|
71
|
+
|
72
|
+
files:
|
73
|
+
- .gitignore
|
74
|
+
- Gemfile
|
75
|
+
- Rakefile
|
76
|
+
- lib/metric.rb
|
77
|
+
- lib/metric/configuration.rb
|
78
|
+
- lib/metric/version.rb
|
79
|
+
- metric.gemspec
|
80
|
+
- spec/metric/configuration_spec.rb
|
81
|
+
- spec/metric_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
has_rdoc: true
|
84
|
+
homepage: http://github.com/bittersweet/metric
|
85
|
+
licenses: []
|
86
|
+
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
requirements: []
|
111
|
+
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.3.7
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: Companion gem to the metric.io site to track metrics
|
117
|
+
test_files:
|
118
|
+
- spec/metric/configuration_spec.rb
|
119
|
+
- spec/metric_spec.rb
|
120
|
+
- spec/spec_helper.rb
|