stathat 0.1.5 → 0.1.6
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.
- checksums.yaml +4 -4
- data/lib/stathat.rb +56 -16
- data/stathat.gemspec +1 -1
- data/test/test_stathat.rb +28 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eff336712e223db2cd53060be30eb5ba11d85404
|
4
|
+
data.tar.gz: 2768fc730354c4c61301b2800b0f53bbd05ce95c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afc6a337f7578d470b6936ca93a5407e2fd3c6aec6e7806e674063c89398495c1a9f8441234c7f021595183839e0892574e3113bcd80cb91ea3ef17f28d37548
|
7
|
+
data.tar.gz: cc7e758657da5fbde268a932fd7859733ff7ab33d8c8f00cde98ebe7ba785a8577c91bf747f0ce65c2f990d94e0c5aff6c5ac9f927867ff497460e6b5166e14f
|
data/lib/stathat.rb
CHANGED
@@ -5,6 +5,57 @@ require 'thread'
|
|
5
5
|
require 'singleton'
|
6
6
|
|
7
7
|
module StatHat
|
8
|
+
class Common
|
9
|
+
CLASSIC_VALUE_URL = "http://api.stathat.com/v"
|
10
|
+
CLASSIC_COUNT_URL = "http://api.stathat.com/c"
|
11
|
+
EZ_URL = "http://api.stathat.com/ez"
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def send_to_stathat(url, args)
|
15
|
+
uri = URI.parse(url)
|
16
|
+
uri.query = URI.encode_www_form(args)
|
17
|
+
resp = Net::HTTP.get(uri)
|
18
|
+
return Response.new(resp)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class SyncAPI
|
24
|
+
class << self
|
25
|
+
def ez_post_value(stat_name, ezkey, value, timestamp=nil)
|
26
|
+
args = { :stat => stat_name,
|
27
|
+
:ezkey => ezkey,
|
28
|
+
:value => value }
|
29
|
+
args[:t] = timestamp unless timestamp.nil?
|
30
|
+
Common::send_to_stathat(Common::EZ_URL, args)
|
31
|
+
end
|
32
|
+
|
33
|
+
def ez_post_count(stat_name, ezkey, count, timestamp=nil)
|
34
|
+
args = { :stat => stat_name,
|
35
|
+
:ezkey => ezkey,
|
36
|
+
:count => count }
|
37
|
+
args[:t] = timestamp unless timestamp.nil?
|
38
|
+
Common::send_to_stathat(Common::EZ_URL, args)
|
39
|
+
end
|
40
|
+
|
41
|
+
def post_count(stat_key, user_key, count, timestamp=nil)
|
42
|
+
args = { :key => stat_key,
|
43
|
+
:ukey => user_key,
|
44
|
+
:count => count }
|
45
|
+
args[:t] = timestamp unless timestamp.nil?
|
46
|
+
Common::send_to_stathat(Common::CLASSIC_COUNT_URL, args)
|
47
|
+
end
|
48
|
+
|
49
|
+
def post_value(stat_key, user_key, value, timestamp=nil)
|
50
|
+
args = { :key => stat_key,
|
51
|
+
:ukey => user_key,
|
52
|
+
:value => value }
|
53
|
+
args[:t] = timestamp unless timestamp.nil?
|
54
|
+
Common::send_to_stathat(Common::CLASSIC_VALUE_URL, args)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
8
59
|
class API
|
9
60
|
class << self
|
10
61
|
def ez_post_value(stat_name, ezkey, value, timestamp=nil, &block)
|
@@ -28,10 +79,6 @@ module StatHat
|
|
28
79
|
class Reporter
|
29
80
|
include Singleton
|
30
81
|
|
31
|
-
CLASSIC_VALUE_URL = "http://api.stathat.com/v"
|
32
|
-
CLASSIC_COUNT_URL = "http://api.stathat.com/c"
|
33
|
-
EZ_URL = "http://api.stathat.com/ez"
|
34
|
-
|
35
82
|
def initialize
|
36
83
|
@que = Queue.new
|
37
84
|
@runlock = Mutex.new
|
@@ -48,7 +95,7 @@ module StatHat
|
|
48
95
|
:ukey => user_key,
|
49
96
|
:value => value }
|
50
97
|
args[:t] = timestamp unless timestamp.nil?
|
51
|
-
enqueue(CLASSIC_VALUE_URL, args, cb)
|
98
|
+
enqueue(Common::CLASSIC_VALUE_URL, args, cb)
|
52
99
|
end
|
53
100
|
|
54
101
|
def post_count(stat_key, user_key, count, timestamp, cb)
|
@@ -56,7 +103,7 @@ module StatHat
|
|
56
103
|
:ukey => user_key,
|
57
104
|
:count => count }
|
58
105
|
args[:t] = timestamp unless timestamp.nil?
|
59
|
-
enqueue(CLASSIC_COUNT_URL, args, cb)
|
106
|
+
enqueue(Common::CLASSIC_COUNT_URL, args, cb)
|
60
107
|
end
|
61
108
|
|
62
109
|
def ez_post_value(stat_name, ezkey, value, timestamp, cb)
|
@@ -64,7 +111,7 @@ module StatHat
|
|
64
111
|
:ezkey => ezkey,
|
65
112
|
:value => value }
|
66
113
|
args[:t] = timestamp unless timestamp.nil?
|
67
|
-
enqueue(EZ_URL, args, cb)
|
114
|
+
enqueue(Common::EZ_URL, args, cb)
|
68
115
|
end
|
69
116
|
|
70
117
|
def ez_post_count(stat_name, ezkey, count, timestamp, cb)
|
@@ -72,7 +119,7 @@ module StatHat
|
|
72
119
|
:ezkey => ezkey,
|
73
120
|
:count => count }
|
74
121
|
args[:t] = timestamp unless timestamp.nil?
|
75
|
-
enqueue(EZ_URL, args, cb)
|
122
|
+
enqueue(Common::EZ_URL, args, cb)
|
76
123
|
end
|
77
124
|
|
78
125
|
private
|
@@ -85,7 +132,7 @@ module StatHat
|
|
85
132
|
point = @que.pop
|
86
133
|
# XXX check for error?
|
87
134
|
begin
|
88
|
-
resp = send_to_stathat(point[:url], point[:args])
|
135
|
+
resp = Common::send_to_stathat(point[:url], point[:args])
|
89
136
|
if point[:cb]
|
90
137
|
point[:cb].call(resp)
|
91
138
|
end
|
@@ -115,13 +162,6 @@ module StatHat
|
|
115
162
|
@que << point
|
116
163
|
true
|
117
164
|
end
|
118
|
-
|
119
|
-
def send_to_stathat(url, args)
|
120
|
-
uri = URI.parse(url)
|
121
|
-
uri.query = URI.encode_www_form(args)
|
122
|
-
resp = Net::HTTP.get(uri)
|
123
|
-
return Response.new(resp)
|
124
|
-
end
|
125
165
|
end
|
126
166
|
|
127
167
|
class Response
|
data/stathat.gemspec
CHANGED
data/test/test_stathat.rb
CHANGED
@@ -38,4 +38,32 @@ class TestStathat < MiniTest::Unit::TestCase
|
|
38
38
|
end
|
39
39
|
sleep(1)
|
40
40
|
end
|
41
|
+
|
42
|
+
def test_ez_value_sync
|
43
|
+
resp = StatHat::SyncAPI.ez_post_value("test ez value stat", "test@stathat.com", 0.92)
|
44
|
+
assert(resp.valid?, "response was invalid")
|
45
|
+
assert_equal(resp.msg, "ok", "message should be 'ok'")
|
46
|
+
assert_equal(resp.status, 200, "status should be 200")
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_ez_count_sync
|
50
|
+
resp = StatHat::SyncAPI.ez_post_value("test ez count stat", "test@stathat.com", 12)
|
51
|
+
assert(resp.valid?, "response was invalid")
|
52
|
+
assert_equal(resp.msg, "ok", "message should be 'ok'")
|
53
|
+
assert_equal(resp.status, 200, "status should be 200")
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_classic_count_bad_keys_sync
|
57
|
+
r = StatHat::SyncAPI.post_count("XXXXXXXX", "YYYYYYYY", 12)
|
58
|
+
assert_equal(r.valid?, false, "response was valid")
|
59
|
+
assert_equal(r.msg, "invalid keys", "incorrect error message")
|
60
|
+
assert_equal(r.status, 500, "incorrect status code")
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_classic_value_bad_keys_sync
|
64
|
+
r = StatHat::SyncAPI.post_value("ZZZZZZZZ", "YYYYYYYYY", 0.92)
|
65
|
+
assert_equal(r.valid?, false, "response was valid")
|
66
|
+
assert_equal(r.msg, "invalid keys", "incorrect error message")
|
67
|
+
assert_equal(r.status, 500, "incorrect status code")
|
68
|
+
end
|
41
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stathat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- StatHat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-03-
|
11
|
+
date: 2013-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Easily post stats to your StatHat account using this gem. Encapsulates
|
14
14
|
full API.
|