stathat 0.0.5 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ddfff8dbbe9dea010d91fdde55759f8e91830089
4
+ data.tar.gz: 8b934b9139ca99e7b6d47bf1256a62878a669a74
5
+ SHA512:
6
+ metadata.gz: aac889bfb0f781329085d6e2cce81024e60f737d92ff273b350e8d4dbb9bbee4c3623b91c2434b344b0567bd2a6cce2bed806f2aebb49fc289edd9945a5ef8bc
7
+ data.tar.gz: d4436bc3b97803b0676c27e699b33d4c2d9686f6157f7b6d74bbd57e672905af539aa47d29dd00ad33c5c00e3605d1bd75d920e3fdbe5b54d127aff683f1b0be
data/Gemfile CHANGED
@@ -7,8 +7,8 @@ source "http://rubygems.org"
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  group :development do
9
9
  gem "minitest", ">= 0"
10
- gem "bundler", "~> 1.0.0"
11
- gem "jeweler", "~> 1.5.2"
12
- gem "rcov", ">= 0"
13
- gem "rocco"
10
+ # gem "bundler", "~> 1.0.0"
11
+ # gem "jeweler", "~> 1.5.2"
12
+ # gem "rcov", ">= 0"
13
+ # gem "rocco"
14
14
  end
data/Gemfile.lock CHANGED
@@ -1,26 +1,10 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- git (1.2.5)
5
- jeweler (1.5.2)
6
- bundler (~> 1.0.0)
7
- git (>= 1.2.5)
8
- rake
9
4
  minitest (2.0.2)
10
- mustache (0.12.0)
11
- rake (0.8.7)
12
- rcov (0.9.9)
13
- rdiscount (1.6.5)
14
- rocco (0.5)
15
- mustache
16
- rdiscount
17
5
 
18
6
  PLATFORMS
19
7
  ruby
20
8
 
21
9
  DEPENDENCIES
22
- bundler (~> 1.0.0)
23
- jeweler (~> 1.5.2)
24
10
  minitest
25
- rcov
26
- rocco
data/Rakefile CHANGED
@@ -1,30 +1,30 @@
1
1
  require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
2
+ #require 'bundler'
3
+ #begin
4
+ # Bundler.setup(:default, :development)
5
+ #rescue Bundler::BundlerError => e
6
+ # $stderr.puts e.message
7
+ # $stderr.puts "Run `bundle install` to install missing gems"
8
+ # exit e.status_code
9
+ #end
10
10
  require 'rake'
11
11
 
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "stathat"
16
- gem.homepage = "http://github.com/patrickxb/stathat"
17
- gem.license = "MIT"
18
- gem.summary = %Q{gem to access StatHat api}
19
- gem.description = %Q{Easily post stats to your StatHat account using this gem. Encapsulates full API.}
20
- gem.email = "patrick@stathat.com"
21
- gem.authors = ["Patrick Crosby"]
22
- # Include your dependencies below. Runtime dependencies are required when using your gem,
23
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
- # gem.add_development_dependency 'rspec', '> 1.2.3'
26
- end
27
- Jeweler::RubygemsDotOrgTasks.new
12
+ #require 'jeweler'
13
+ #Jeweler::Tasks.new do |gem|
14
+ # # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ # gem.name = "stathat"
16
+ # gem.homepage = "http://github.com/patrickxb/stathat"
17
+ # gem.license = "MIT"
18
+ # gem.summary = %Q{gem to access StatHat api}
19
+ # gem.description = %Q{Easily post stats to your StatHat account using this gem. Encapsulates full API.}
20
+ # gem.email = "patrick@xblabs.com"
21
+ # gem.authors = ["Patrick Crosby"]
22
+ # # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ #end
27
+ #Jeweler::RubygemsDotOrgTasks.new
28
28
 
29
29
  require 'rake/testtask'
30
30
  Rake::TestTask.new(:test) do |test|
@@ -33,28 +33,29 @@ Rake::TestTask.new(:test) do |test|
33
33
  test.verbose = true
34
34
  end
35
35
 
36
- require 'rcov/rcovtask'
37
- Rcov::RcovTask.new do |test|
38
- test.libs << 'test'
39
- test.pattern = 'test/**/test_*.rb'
40
- test.verbose = true
41
- end
36
+ #require 'rcov/rcovtask'
37
+ #Rcov::RcovTask.new do |test|
38
+ # test.libs << 'test'
39
+ # test.pattern = 'test/**/test_*.rb'
40
+ # test.verbose = true
41
+ #end
42
42
 
43
43
  task :default => :test
44
44
 
45
- require 'rake/rdoctask'
46
- Rake::RDocTask.new do |rdoc|
47
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
-
49
- rdoc.rdoc_dir = 'rdoc'
50
- rdoc.title = "stathat #{version}"
51
- rdoc.rdoc_files.include('README*')
52
- rdoc.rdoc_files.include('lib/**/*.rb')
53
- end
45
+ require 'rdoc/task'
46
+ #require 'rake/rdoctask'
47
+ #Rake::RDocTask.new do |rdoc|
48
+ # version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+ #
50
+ # rdoc.rdoc_dir = 'rdoc'
51
+ # rdoc.title = "stathat #{version}"
52
+ # rdoc.rdoc_files.include('README*')
53
+ # rdoc.rdoc_files.include('lib/**/*.rb')
54
+ #end
54
55
 
55
- namespace :doc do
56
- desc "build literate documentation"
57
- task :build do
58
- sh "rocco -o doc lib/*.rb"
59
- end
60
- end
56
+ #namespace :doc do
57
+ # desc "build literate documentation"
58
+ # task :build do
59
+ # sh "rocco -o doc lib/*.rb"
60
+ # end
61
+ #end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.4
data/lib/stathat.rb CHANGED
@@ -1,42 +1,117 @@
1
1
  require 'net/http'
2
2
  require 'uri'
3
3
  require 'json'
4
+ require 'thread'
5
+ require 'singleton'
4
6
 
5
7
  module StatHat
6
8
  class API
9
+ class << self
10
+ def ez_post_value(stat_name, ezkey, value, &block)
11
+ Reporter.instance.ez_post_value(stat_name, ezkey, value, block)
12
+ end
13
+
14
+ def ez_post_count(stat_name, ezkey, count)
15
+ Reporter.instance.ez_post_count(stat_name, ezkey, count)
16
+ end
17
+
18
+ def post_count(stat_key, user_key, count)
19
+ Reporter.instance.post_count(stat_key, user_key, count)
20
+ end
21
+
22
+ def post_value(stat_key, user_key, value)
23
+ Reporter.instance.post_value(stat_key, user_key, value)
24
+ end
25
+ end
26
+ end
27
+
28
+ class Reporter
29
+ include Singleton
30
+
7
31
  CLASSIC_VALUE_URL = "http://api.stathat.com/v"
8
32
  CLASSIC_COUNT_URL = "http://api.stathat.com/c"
9
33
  EZ_URL = "http://api.stathat.com/ez"
10
34
 
11
- def self.post_value(stat_key, user_key, value)
35
+
36
+ def initialize
37
+ @que = Queue.new
38
+ run_pool()
39
+ end
40
+
41
+ def finish()
42
+ stop_pool
43
+ # XXX serialize queue?
44
+ end
45
+
46
+ def post_value(stat_key, user_key, value)
12
47
  args = { :key => stat_key,
13
48
  :ukey => user_key,
14
49
  :value => value }
15
- return self.send_to_stathat(CLASSIC_VALUE_URL, args)
50
+ enqueue(CLASSIC_VALUE_URL, args)
16
51
  end
17
52
 
18
- def self.post_count(stat_key, user_key, count)
53
+ def post_count(stat_key, user_key, count)
19
54
  args = { :key => stat_key,
20
55
  :ukey => user_key,
21
56
  :count => count }
22
- return self.send_to_stathat(CLASSIC_COUNT_URL, args)
57
+ enqueue(CLASSIC_COUNT_URL, args)
23
58
  end
24
59
 
25
- def self.ez_post_value(stat_name, ezkey, value)
60
+ def ez_post_value(stat_name, ezkey, value, cb)
61
+ puts "ezval cb: #{cb}"
26
62
  args = { :stat => stat_name,
27
63
  :ezkey => ezkey,
28
64
  :value => value }
29
- return self.send_to_stathat(EZ_URL, args)
65
+ enqueue(EZ_URL, args, cb)
30
66
  end
31
67
 
32
- def self.ez_post_count(stat_name, ezkey, count)
68
+ def ez_post_count(stat_name, ezkey, count)
33
69
  args = { :stat => stat_name,
34
70
  :ezkey => ezkey,
35
71
  :count => count }
36
- return self.send_to_stathat(EZ_URL, args)
72
+ enqueue(EZ_URL, args)
73
+ end
74
+
75
+ private
76
+ def run_pool
77
+ @running = true
78
+ @pool = []
79
+ 5.times do |i|
80
+ @pool[i] = Thread.new do
81
+ puts "thread #{i} started"
82
+ while @running do
83
+ point = @que.pop
84
+ # XXX check for error?
85
+ begin
86
+ puts "thread #{i}: sending"
87
+ resp = send_to_stathat(point[:url], point[:args])
88
+ if point[:cb]
89
+ point[:cb].call(resp)
90
+ end
91
+ rescue
92
+ pp $!
93
+ end
94
+ end
95
+ puts "reporter thread #{i} finished"
96
+ end
97
+ end
98
+ end
99
+
100
+ def stop_pool()
101
+ @running = false
102
+ @pool.each do |th|
103
+ th.join
104
+ end
105
+ end
106
+
107
+ def enqueue(url, args, cb=nil)
108
+ return false unless @running
109
+ point = {:url => url, :args => args, :cb => cb}
110
+ @que << point
111
+ true
37
112
  end
38
113
 
39
- def self.send_to_stathat(url, args)
114
+ def send_to_stathat(url, args)
40
115
  uri = URI.parse(url)
41
116
  uri.query = URI.encode_www_form(args)
42
117
  resp = Net::HTTP.get(uri)
data/stathat.gemspec CHANGED
@@ -1,17 +1,11 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
3
  Gem::Specification.new do |s|
7
4
  s.name = %q{stathat}
8
- s.version = "0.0.5"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Patrick Crosby}]
12
- s.date = %q{2012-10-29}
5
+ s.version = "0.1.1"
6
+ s.authors = ["StatHat"]
13
7
  s.description = %q{Easily post stats to your StatHat account using this gem. Encapsulates full API.}
14
- s.email = %q{patrick@stathat.com}
8
+ s.email = %q{info@stathat.com}
15
9
  s.extra_rdoc_files = [
16
10
  "LICENSE.txt",
17
11
  "README.rdoc"
@@ -30,37 +24,12 @@ Gem::Specification.new do |s|
30
24
  "test/test_stathat.rb"
31
25
  ]
32
26
  s.homepage = %q{http://github.com/patrickxb/stathat}
33
- s.licenses = [%q{MIT}]
34
- s.require_paths = [%q{lib}]
35
- s.rubygems_version = %q{1.8.6}
27
+ s.licenses = ["MIT"]
28
+ s.require_paths = ["lib"]
36
29
  s.summary = %q{gem to access StatHat api}
37
30
  s.test_files = [
38
31
  "test/helper.rb",
39
32
  "test/test_stathat.rb"
40
33
  ]
41
-
42
- if s.respond_to? :specification_version then
43
- s.specification_version = 3
44
-
45
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
- s.add_development_dependency(%q<minitest>, [">= 0"])
47
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
48
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
49
- s.add_development_dependency(%q<rcov>, [">= 0"])
50
- s.add_development_dependency(%q<rocco>, [">= 0"])
51
- else
52
- s.add_dependency(%q<minitest>, [">= 0"])
53
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
55
- s.add_dependency(%q<rcov>, [">= 0"])
56
- s.add_dependency(%q<rocco>, [">= 0"])
57
- end
58
- else
59
- s.add_dependency(%q<minitest>, [">= 0"])
60
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
62
- s.add_dependency(%q<rcov>, [">= 0"])
63
- s.add_dependency(%q<rocco>, [">= 0"])
64
- end
65
34
  end
66
35
 
data/test/helper.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
2
+ #require 'bundler'
3
+ #begin
4
+ # Bundler.setup(:default, :development)
5
+ #rescue Bundler::BundlerError => e
6
+ # $stderr.puts e.message
7
+ # $stderr.puts "Run `bundle install` to install missing gems"
8
+ # exit e.status_code
9
+ #end
10
10
  require 'minitest/unit'
11
11
 
12
12
  $LOAD_PATH.unshift(File.dirname(__FILE__))
data/test/test_stathat.rb CHANGED
@@ -1,31 +1,42 @@
1
1
  require 'helper'
2
2
 
3
+
3
4
  class TestStathat < MiniTest::Unit::TestCase
5
+
4
6
  def test_ez_value
5
- r = StatHat::API.ez_post_value("test ez value stat", "patrick@stathat.com", 0.92)
6
- assert(r.valid?, "response was invalid")
7
- assert_equal(r.msg, "ok", "message should be 'ok'")
8
- assert_equal(r.status, 200, "status should be 200")
7
+ StatHat::API.ez_post_value("test ez value stat", "test@stathat.com", 0.92) do |resp|
8
+ assert(resp.valid?, "response was invalid")
9
+ assert_equal(resp.msg, "ok", "message should be 'ok'")
10
+ assert_equal(resp.status, 200, "status should be 200")
11
+ end
12
+ sleep(1)
13
+ puts "finished test_ez_val"
9
14
  end
10
15
 
11
16
  def test_ez_count
12
- r = StatHat::API.ez_post_value("test ez count stat", "patrick@stathat.com", 12)
13
- assert(r.valid?, "response was invalid")
14
- assert_equal(r.msg, "ok", "message should be 'ok'")
15
- assert_equal(r.status, 200, "status should be 200")
17
+ StatHat::API.ez_post_value("test ez count stat", "test@stathat.com", 12) do |r|
18
+ assert(r.valid?, "response was invalid")
19
+ assert_equal(r.msg, "ok", "message should be 'ok'")
20
+ assert_equal(r.status, 200, "status should be 200")
21
+ end
22
+ sleep(1)
16
23
  end
17
24
 
18
25
  def test_classic_count_bad_keys
19
- r = StatHat::API.post_count("XXXXXXXX", "YYYYYYYY", 12)
20
- assert_equal(r.valid?, false, "response was valid")
21
- assert_equal(r.msg, "invalid keys", "incorrect error message")
22
- assert_equal(r.status, 500, "incorrect status code")
26
+ StatHat::API.post_count("XXXXXXXX", "YYYYYYYY", 12) do |r|
27
+ assert_equal(r.valid?, false, "response was valid")
28
+ assert_equal(r.msg, "invalid keys", "incorrect error message")
29
+ assert_equal(r.status, 500, "incorrect status code")
30
+ end
31
+ sleep(1)
23
32
  end
24
33
 
25
34
  def test_classic_value_bad_keys
26
- r = StatHat::API.post_value("ZZZZZZZZ", "YYYYYYYYY", 0.92)
27
- assert_equal(r.valid?, false, "response was valid")
28
- assert_equal(r.msg, "invalid keys", "incorrect error message")
29
- assert_equal(r.status, 500, "incorrect status code")
35
+ StatHat::API.post_value("ZZZZZZZZ", "YYYYYYYYY", 0.92) do |r|
36
+ assert_equal(r.valid?, false, "response was valid")
37
+ assert_equal(r.msg, "invalid keys", "incorrect error message")
38
+ assert_equal(r.status, 500, "incorrect status code")
39
+ end
40
+ sleep(1)
30
41
  end
31
42
  end
metadata CHANGED
@@ -1,74 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stathat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
5
- prerelease:
4
+ version: 0.1.1
6
5
  platform: ruby
7
6
  authors:
8
- - Patrick Crosby
7
+ - StatHat
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-10-29 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: minitest
16
- requirement: &70150214492820 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :development
23
- prerelease: false
24
- version_requirements: *70150214492820
25
- - !ruby/object:Gem::Dependency
26
- name: bundler
27
- requirement: &70150214492100 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ~>
31
- - !ruby/object:Gem::Version
32
- version: 1.0.0
33
- type: :development
34
- prerelease: false
35
- version_requirements: *70150214492100
36
- - !ruby/object:Gem::Dependency
37
- name: jeweler
38
- requirement: &70150214491080 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ~>
42
- - !ruby/object:Gem::Version
43
- version: 1.5.2
44
- type: :development
45
- prerelease: false
46
- version_requirements: *70150214491080
47
- - !ruby/object:Gem::Dependency
48
- name: rcov
49
- requirement: &70150214489840 !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- type: :development
56
- prerelease: false
57
- version_requirements: *70150214489840
58
- - !ruby/object:Gem::Dependency
59
- name: rocco
60
- requirement: &70150214488400 !ruby/object:Gem::Requirement
61
- none: false
62
- requirements:
63
- - - ! '>='
64
- - !ruby/object:Gem::Version
65
- version: '0'
66
- type: :development
67
- prerelease: false
68
- version_requirements: *70150214488400
11
+ date: 2013-03-18 00:00:00.000000000 Z
12
+ dependencies: []
69
13
  description: Easily post stats to your StatHat account using this gem. Encapsulates
70
14
  full API.
71
- email: patrick@stathat.com
15
+ email: info@stathat.com
72
16
  executables: []
73
17
  extensions: []
74
18
  extra_rdoc_files:
@@ -89,30 +33,26 @@ files:
89
33
  homepage: http://github.com/patrickxb/stathat
90
34
  licenses:
91
35
  - MIT
36
+ metadata: {}
92
37
  post_install_message:
93
38
  rdoc_options: []
94
39
  require_paths:
95
40
  - lib
96
41
  required_ruby_version: !ruby/object:Gem::Requirement
97
- none: false
98
42
  requirements:
99
- - - ! '>='
43
+ - - '>='
100
44
  - !ruby/object:Gem::Version
101
45
  version: '0'
102
- segments:
103
- - 0
104
- hash: 1512607732856864404
105
46
  required_rubygems_version: !ruby/object:Gem::Requirement
106
- none: false
107
47
  requirements:
108
- - - ! '>='
48
+ - - '>='
109
49
  - !ruby/object:Gem::Version
110
50
  version: '0'
111
51
  requirements: []
112
52
  rubyforge_project:
113
- rubygems_version: 1.8.6
53
+ rubygems_version: 2.0.0
114
54
  signing_key:
115
- specification_version: 3
55
+ specification_version: 4
116
56
  summary: gem to access StatHat api
117
57
  test_files:
118
58
  - test/helper.rb