statsmix 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -1
- data/VERSION +1 -1
- data/lib/statsmix.rb +50 -62
- data/statsmix.gemspec +6 -4
- data/test/test_statsmix.rb +57 -6
- data/test/vcr_setup.rb +18 -0
- metadata +6 -4
data/README.rdoc
CHANGED
@@ -4,6 +4,10 @@ A Ruby gem for the StatsMix API - http://www.statsmix.com/developers
|
|
4
4
|
|
5
5
|
WARNING: This is currently experimental and not recommend for production use.
|
6
6
|
|
7
|
+
StatsMix makes it easy to track, chart, and share application and business metrics.
|
8
|
+
|
9
|
+
To get started, you'll need a API key for StatsMix. You can get a free developer account here: http://www.statsmix.com/try?plan=developer
|
10
|
+
|
7
11
|
|
8
12
|
== Contributing to statsmix
|
9
13
|
|
@@ -15,6 +19,7 @@ WARNING: This is currently experimental and not recommend for production use.
|
|
15
19
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
16
20
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
17
21
|
|
22
|
+
|
18
23
|
== Copyright
|
19
24
|
|
20
|
-
Copyright (c) 2011 StatsMix, Inc. See LICENSE.txt for further details.
|
25
|
+
Copyright (c) 2011 StatsMix, Inc. See LICENSE.txt for further details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.6
|
data/lib/statsmix.rb
CHANGED
@@ -3,6 +3,7 @@ require 'net/http'
|
|
3
3
|
class StatsMix
|
4
4
|
|
5
5
|
BASE_URI = 'http://www.statsmix.com/api/v2/'
|
6
|
+
# BASE_URI = 'http://localhost:3000/api/v2/'
|
6
7
|
|
7
8
|
GEM_VERSION = File.exist?('../VERSION') ? File.read('../VERSION') : ""
|
8
9
|
|
@@ -12,17 +13,22 @@ class StatsMix
|
|
12
13
|
@user_agent = "StatsMix Ruby Gem " + GEM_VERSION
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
+
def connect(resource)
|
17
|
+
# Resources available: stats, metrics, TODO: profiles
|
18
|
+
@url = URI.parse(BASE_URI + resource)
|
19
|
+
@connection = Net::HTTP.new(@url.host, @url.port)
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
# Stats
|
16
24
|
|
17
25
|
# List stats (index)
|
18
26
|
#
|
19
27
|
# Required: metric_id
|
20
28
|
# Optional: limit
|
21
29
|
def list_stats(metric_id, limit = nil)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
request = Net::HTTP::Get.new(url.path + '.' + @format)
|
30
|
+
connect('stats')
|
31
|
+
request = Net::HTTP::Get.new(@url.path + '.' + @format)
|
26
32
|
request["User-Agent"] = @user_agent
|
27
33
|
|
28
34
|
form_hash = Hash.new
|
@@ -34,8 +40,8 @@ class StatsMix
|
|
34
40
|
|
35
41
|
request.set_form_data(form_hash)
|
36
42
|
|
37
|
-
response =
|
38
|
-
|
43
|
+
response = @connection.request(request)
|
44
|
+
return response.body
|
39
45
|
end
|
40
46
|
|
41
47
|
# Get stat
|
@@ -43,16 +49,14 @@ class StatsMix
|
|
43
49
|
# Required: stat_id
|
44
50
|
# Optional: none
|
45
51
|
def get_stat(stat_id)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
request = Net::HTTP::Get.new(url.path + '/' + stat_id.to_s + '.' + @format)
|
52
|
+
connect('stats')
|
53
|
+
request = Net::HTTP::Get.new(@url.path + '/' + stat_id.to_s + '.' + @format)
|
50
54
|
request["User-Agent"] = @user_agent
|
51
55
|
|
52
56
|
request.set_form_data({"api_key" => @api_key})
|
53
57
|
|
54
|
-
response =
|
55
|
-
|
58
|
+
response = @connection.request(request)
|
59
|
+
return response.body
|
56
60
|
end
|
57
61
|
|
58
62
|
# Create stat
|
@@ -60,10 +64,8 @@ class StatsMix
|
|
60
64
|
# Required: metric_id
|
61
65
|
# Optional: value, generated_at, meta
|
62
66
|
def create_stat(metric_id, value = 1, generated_at = Time.now, meta = nil)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
request = Net::HTTP::Post.new(url.path + '.' + @format)
|
67
|
+
connect('stats')
|
68
|
+
request = Net::HTTP::Post.new(@url.path + '.' + @format)
|
67
69
|
request["User-Agent"] = @user_agent
|
68
70
|
|
69
71
|
form_hash = Hash.new
|
@@ -77,8 +79,8 @@ class StatsMix
|
|
77
79
|
|
78
80
|
request.set_form_data(form_hash)
|
79
81
|
|
80
|
-
response =
|
81
|
-
|
82
|
+
response = @connection.request(request)
|
83
|
+
return response.body
|
82
84
|
end
|
83
85
|
|
84
86
|
# Update stat
|
@@ -86,10 +88,8 @@ class StatsMix
|
|
86
88
|
# Required: stat_id
|
87
89
|
# Optional: value, generated_at, meta
|
88
90
|
def update_stat(stat_id, value = nil, generated_at = nil, meta = nil)
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
request = Net::HTTP::Put.new(url.path + '/' + stat_id.to_s + '.' + @format)
|
91
|
+
connect('stats')
|
92
|
+
request = Net::HTTP::Put.new(@url.path + '/' + stat_id.to_s + '.' + @format)
|
93
93
|
request["User-Agent"] = @user_agent
|
94
94
|
|
95
95
|
form_hash = Hash.new
|
@@ -106,8 +106,8 @@ class StatsMix
|
|
106
106
|
|
107
107
|
request.set_form_data(form_hash)
|
108
108
|
|
109
|
-
response =
|
110
|
-
|
109
|
+
response = @connection.request(request)
|
110
|
+
return response.body
|
111
111
|
end
|
112
112
|
|
113
113
|
# Delete stat
|
@@ -115,29 +115,25 @@ class StatsMix
|
|
115
115
|
# Required: stat_id
|
116
116
|
# Optional: none
|
117
117
|
def delete_stat(stat_id)
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
request = Net::HTTP::Delete.new(url.path + '/' + stat_id.to_s + '.' + @format)
|
118
|
+
connect('stats')
|
119
|
+
request = Net::HTTP::Delete.new(@url.path + '/' + stat_id.to_s + '.' + @format)
|
122
120
|
request["User-Agent"] = @user_agent
|
123
121
|
|
124
122
|
request.set_form_data({"api_key" => @api_key})
|
125
123
|
|
126
|
-
response =
|
127
|
-
|
124
|
+
response = @connection.request(request)
|
125
|
+
return response.body
|
128
126
|
end
|
129
127
|
|
130
|
-
#
|
128
|
+
# Metrics
|
131
129
|
|
132
130
|
# List metrics
|
133
131
|
#
|
134
132
|
# Required: none
|
135
133
|
# Optional: profile_id, limit
|
136
134
|
def list_metrics(profile_id = nil, limit = nil)
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
request = Net::HTTP::Get.new(url.path + '.' + @format)
|
135
|
+
connect('metrics')
|
136
|
+
request = Net::HTTP::Get.new(@url.path + '.' + @format)
|
141
137
|
request["User-Agent"] = @user_agent
|
142
138
|
|
143
139
|
form_hash = Hash.new
|
@@ -151,8 +147,8 @@ class StatsMix
|
|
151
147
|
|
152
148
|
request.set_form_data(form_hash)
|
153
149
|
|
154
|
-
response =
|
155
|
-
|
150
|
+
response = @connection.request(request)
|
151
|
+
return response.body
|
156
152
|
end
|
157
153
|
|
158
154
|
# Get metric
|
@@ -160,16 +156,14 @@ class StatsMix
|
|
160
156
|
# Required: metric_id
|
161
157
|
# Optional: none
|
162
158
|
def get_metric(metric_id)
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
request = Net::HTTP::Get.new(url.path + '/' + metric_id.to_s + '.' + @format)
|
159
|
+
connect('metrics')
|
160
|
+
request = Net::HTTP::Get.new(@url.path + '/' + metric_id.to_s + '.' + @format)
|
167
161
|
request["User-Agent"] = @user_agent
|
168
162
|
|
169
163
|
request.set_form_data({"api_key" => @api_key})
|
170
164
|
|
171
|
-
response =
|
172
|
-
|
165
|
+
response = @connection.request(request)
|
166
|
+
return response.body
|
173
167
|
end
|
174
168
|
|
175
169
|
# Create metric
|
@@ -177,10 +171,8 @@ class StatsMix
|
|
177
171
|
# Required: name
|
178
172
|
# Optional: profile_id, generated_at
|
179
173
|
def create_metric(name, profile_id = nil)
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
request = Net::HTTP::Post.new(url.path + '.' + @format)
|
174
|
+
connect('metrics')
|
175
|
+
request = Net::HTTP::Post.new(@url.path + '.' + @format)
|
184
176
|
request["User-Agent"] = @user_agent
|
185
177
|
|
186
178
|
form_hash = Hash.new
|
@@ -192,8 +184,8 @@ class StatsMix
|
|
192
184
|
|
193
185
|
request.set_form_data(form_hash)
|
194
186
|
|
195
|
-
response =
|
196
|
-
|
187
|
+
response = @connection.request(request)
|
188
|
+
return response.body
|
197
189
|
end
|
198
190
|
|
199
191
|
# Update metric
|
@@ -201,10 +193,8 @@ class StatsMix
|
|
201
193
|
# Required: metric_id
|
202
194
|
# Optional: name, sharing, include_in_email
|
203
195
|
def update_metric(metric_id, name = nil, sharing = nil, include_in_email = nil)
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
request = Net::HTTP::Put.new(url.path + '/' + metric_id.to_s + '.' + @format)
|
196
|
+
connect('metrics')
|
197
|
+
request = Net::HTTP::Put.new(@url.path + '/' + metric_id.to_s + '.' + @format)
|
208
198
|
request["User-Agent"] = @user_agent
|
209
199
|
|
210
200
|
form_hash = Hash.new
|
@@ -221,8 +211,8 @@ class StatsMix
|
|
221
211
|
|
222
212
|
request.set_form_data(form_hash)
|
223
213
|
|
224
|
-
response =
|
225
|
-
|
214
|
+
response = @connection.request(request)
|
215
|
+
return response.body
|
226
216
|
end
|
227
217
|
|
228
218
|
# Delete metric
|
@@ -230,15 +220,13 @@ class StatsMix
|
|
230
220
|
# Required: metric_id
|
231
221
|
# Optional: none
|
232
222
|
def delete_metric(metric_id)
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
request = Net::HTTP::Delete.new(url.path + '/' + metric_id.to_s + '.' + @format)
|
223
|
+
connect('metrics')
|
224
|
+
request = Net::HTTP::Delete.new(@url.path + '/' + metric_id.to_s + '.' + @format)
|
237
225
|
request["User-Agent"] = @user_agent
|
238
226
|
|
239
227
|
request.set_form_data({"api_key" => @api_key})
|
240
228
|
|
241
|
-
response =
|
242
|
-
|
229
|
+
response = @connection.request(request)
|
230
|
+
return response.body
|
243
231
|
end
|
244
232
|
end
|
data/statsmix.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{statsmix}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Tom Markiewicz"]
|
12
|
-
s.date = %q{2011-06-
|
12
|
+
s.date = %q{2011-06-22}
|
13
13
|
s.description = %q{A Ruby gem for the StatsMix API - http://www.statsmix.com/developers}
|
14
14
|
s.email = %q{tmarkiewicz@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,7 +27,8 @@ Gem::Specification.new do |s|
|
|
27
27
|
"lib/statsmix.rb",
|
28
28
|
"statsmix.gemspec",
|
29
29
|
"test/helper.rb",
|
30
|
-
"test/test_statsmix.rb"
|
30
|
+
"test/test_statsmix.rb",
|
31
|
+
"test/vcr_setup.rb"
|
31
32
|
]
|
32
33
|
s.homepage = %q{http://github.com/tmarkiewicz/statsmix}
|
33
34
|
s.licenses = ["MIT"]
|
@@ -36,7 +37,8 @@ Gem::Specification.new do |s|
|
|
36
37
|
s.summary = %q{A Ruby gem for the StatsMix API.}
|
37
38
|
s.test_files = [
|
38
39
|
"test/helper.rb",
|
39
|
-
"test/test_statsmix.rb"
|
40
|
+
"test/test_statsmix.rb",
|
41
|
+
"test/vcr_setup.rb"
|
40
42
|
]
|
41
43
|
|
42
44
|
if s.respond_to? :specification_version then
|
data/test/test_statsmix.rb
CHANGED
@@ -1,11 +1,62 @@
|
|
1
1
|
require 'helper'
|
2
2
|
require 'statsmix'
|
3
3
|
|
4
|
-
class TestStatsmix < Test::Unit::TestCase
|
4
|
+
class TestStatsmix < Test::Unit::TestCase
|
5
|
+
|
6
|
+
# TODO use fakwweb gem for testing
|
7
|
+
# http://technicalpickles.com/posts/stop-net-http-dead-in-its-tracks-with-fakeweb/
|
8
|
+
# https://github.com/chrisk/fakeweb
|
9
|
+
# http://fakeweb.rubyforge.org/
|
10
|
+
|
11
|
+
# TODO use VCR for tests
|
12
|
+
# http://www.rubyinside.com/vcr-a-recorder-for-all-your-tests-http-interactions-4169.html
|
13
|
+
# https://github.com/myronmarston/vcr
|
14
|
+
|
5
15
|
should "initialize StatsMix API" do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# statsmix.list_metrics(11, 3)
|
16
|
+
statsmix = StatsMix.new('59f08613db2691f28afe', 'xml')
|
17
|
+
response = statsmix.list_metrics
|
18
|
+
puts response
|
10
19
|
end
|
11
|
-
|
20
|
+
|
21
|
+
# # metrics
|
22
|
+
# should "create metric" do
|
23
|
+
#
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# should "get metric" do
|
27
|
+
#
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# should "list metrics" do
|
31
|
+
#
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# should "update metric" do
|
35
|
+
#
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# should "delete metric" do
|
39
|
+
#
|
40
|
+
# end
|
41
|
+
|
42
|
+
# # stats
|
43
|
+
# should "create stat" do
|
44
|
+
#
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# should "get stat" do
|
48
|
+
#
|
49
|
+
# end
|
50
|
+
#
|
51
|
+
# should "list stats" do
|
52
|
+
#
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# should "update stat" do
|
56
|
+
#
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# should "delete stat" do
|
60
|
+
#
|
61
|
+
# end
|
62
|
+
end
|
data/test/vcr_setup.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'vcr'
|
4
|
+
|
5
|
+
VCR.config do |c|
|
6
|
+
c.cassette_library_dir = 'fixtures/vcr_cassettes'
|
7
|
+
c.stub_with :fakeweb
|
8
|
+
# c.default_cassette_options = { :record => :none }
|
9
|
+
end
|
10
|
+
|
11
|
+
class VCRTest < Test::Unit::TestCase
|
12
|
+
def test_example_dot_com
|
13
|
+
VCR.use_cassette('synopsis') do
|
14
|
+
response = Net::HTTP.get_response(URI('http://www.iana.org/domains/example/'))
|
15
|
+
assert_match /Example Domains/, response.body
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: statsmix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tom Markiewicz
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06-
|
18
|
+
date: 2011-06-22 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- statsmix.gemspec
|
100
100
|
- test/helper.rb
|
101
101
|
- test/test_statsmix.rb
|
102
|
+
- test/vcr_setup.rb
|
102
103
|
has_rdoc: true
|
103
104
|
homepage: http://github.com/tmarkiewicz/statsmix
|
104
105
|
licenses:
|
@@ -136,3 +137,4 @@ summary: A Ruby gem for the StatsMix API.
|
|
136
137
|
test_files:
|
137
138
|
- test/helper.rb
|
138
139
|
- test/test_statsmix.rb
|
140
|
+
- test/vcr_setup.rb
|