eotb 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ gemcutter (0.6.1)
5
+ git (1.2.5)
6
+ jeweler (1.4.0)
7
+ gemcutter (>= 0.1.0)
8
+ git (>= 1.2.5)
9
+ rubyforge (>= 2.0.0)
10
+ json (1.4.6)
11
+ json_pure (1.4.6)
12
+ rspec (1.3.0)
13
+ rubyforge (2.0.4)
14
+ json_pure (>= 1.1.7)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ jeweler (>= 1.4.0)
21
+ json (>= 1.4.3)
22
+ rspec (>= 1.3.0)
data/README.rdoc CHANGED
@@ -39,7 +39,8 @@ As a result you will get API Key of your application.
39
39
  Add file <tt>eotb.rb</tt> in directory <tt>config/initializers</tt> of your rails application with content:
40
40
 
41
41
  require 'Eotb'
42
- Eotb.configure("your_api_key", "host", "port") # default host and port are 127.0.0.1 and 3000
42
+ Eotb.configure("your_api_key", "events", "host", "port") # default host and port are 127.0.0.1 and 3000
43
+ #events - number of events sent in one package/request to beholder, default 1.
43
44
 
44
45
  Register events by:
45
46
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.5.3
data/eotb.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{eotb}
8
- s.version = "0.5.2"
8
+ s.version = "0.5.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ragnarson"]
12
- s.date = %q{2010-08-23}
12
+ s.date = %q{2010-08-30}
13
13
  s.description = %q{Rails plugin which allow you easily track and observe your apps}
14
14
  s.email = %q{bartlomiej.kozal@ragnarson.com}
15
15
  s.extra_rdoc_files = [
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  ".document",
21
21
  ".gitignore",
22
22
  "Gemfile",
23
+ "Gemfile.lock",
23
24
  "LICENSE",
24
25
  "README.rdoc",
25
26
  "Rakefile",
data/lib/eotb.rb CHANGED
@@ -8,22 +8,33 @@ class Eotb
8
8
 
9
9
  METHODS = [:to_actor, :to_subject, :to_json, :to_hash, :inspect]
10
10
 
11
- def self.configure(api_key, host = '127.0.0.1', port = '3000')
11
+ def self.configure(api_key, events = 1, host = '127.0.0.1', port = '3000')
12
12
  @@uri = URI.parse('http://' + host + ':' + port + '/events/' + api_key)
13
13
  @@post = Net::HTTP::Post.new(@@uri.path)
14
+ @@events = {}
15
+ @@counter = 1
16
+ events >= 1 ? @@reset = events : @@reset = 1
14
17
  end
18
+
15
19
 
16
20
  def self.register_event(actor, action, subject = {})
17
- action = { "event[action]" => action.to_s }
21
+ action = { "event#{@@counter}[action]" => action.to_s }
18
22
  event = (hash_format(actor, :actor)).merge(action).merge(hash_format(subject, :subject))
19
- @@post.set_form_data(event)
20
- begin
21
- Timeout::timeout(2) {
22
- Net::HTTP.new(@@uri.host, @@uri.port).start.request(@@post)
23
- }
24
- rescue => e
25
- logger = Logger.new("log/#{ENV['RAILS_ENV']}.log")
26
- logger.error "ERROR eotb gem: " + e.to_s
23
+
24
+ @@events.merge! event
25
+ if (@@counter == @@reset)
26
+ @@post.set_form_data(@@events)
27
+ @@counter = 1
28
+ begin
29
+ Timeout::timeout(2) {
30
+ Net::HTTP.new(@@uri.host, @@uri.port).start.request(@@post)
31
+ }
32
+ rescue => e
33
+ logger = Logger.new("log/#{ENV['RAILS_ENV']}.log")
34
+ logger.error "ERROR eotb gem: " + e.to_s
35
+ end
36
+ else
37
+ @@counter += 1
27
38
  end
28
39
  end
29
40
 
@@ -49,10 +60,10 @@ class Eotb
49
60
  if hash.is_a?(Hash)
50
61
  h = hash_flatten(hash).map do |k, v|
51
62
  key = k.map{ |e| "[#{e}]" }.join
52
- "\"event[#{type}]#{key}\" => #{value_format(v)}"
63
+ "\"event#{@@counter}[#{type}]#{key}\" => #{value_format(v)}"
53
64
  end.join(', ')
54
65
  else
55
- h = "\"event[#{type}]\" => #{value_format(hash)}"
66
+ h = "\"event#{@@counter}[#{type}]\" => #{value_format(hash)}"
56
67
  end
57
68
  eval "{#{h.to_s}}"
58
69
  end
data/spec/eotb_spec.rb CHANGED
@@ -2,18 +2,28 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe Eotb do
4
4
 
5
+ it "should log errors" do
6
+ logger = mock(Logger)
7
+ logger.stub(:new) { logger }
8
+ logger.stub(:error) { @response }
9
+ Eotb.register_event(:actor, :action, {:username => "John"}).should == @response
10
+ end
11
+
5
12
  describe "shoud format objects" do
13
+ before do
14
+ @@counter = 0
15
+ end
6
16
 
7
17
  it "should format actor in string" do
8
- Eotb.hash_format("actor", :actor).should == {"event[actor]" => "actor"}
18
+ Eotb.hash_format("actor", :actor).should == {"event0[actor]" => "actor"}
9
19
  end
10
20
 
11
21
  it "should format actor in hash" do
12
- Eotb.hash_format({:type => "User"}, :actor).should == {"event[actor][type]" => "User"}
22
+ Eotb.hash_format({:type => "User"}, :actor).should == {"event0[actor][type]" => "User"}
13
23
  end
14
24
 
15
25
  it "should format actor in nested hash" do
16
- Eotb.hash_format({:type => { :account => "User"}}, :actor).should == {"event[actor][type][account]" => "User"}
26
+ Eotb.hash_format({:type => { :account => "User"}}, :actor).should == {"event0[actor][type][account]" => "User"}
17
27
  end
18
28
 
19
29
  end
@@ -22,7 +32,7 @@ describe Eotb do
22
32
 
23
33
  before(:each) do
24
34
  @response = "200"
25
- Eotb.configure("0"*40)
35
+ Eotb.configure("0"*40, 1)
26
36
  Net::HTTP.stub(:new) { Net::HTTP }
27
37
  Net::HTTP.stub(:start) { Net::HTTP }
28
38
  Net::HTTP.stub(:request) { "200" }
@@ -30,6 +40,7 @@ describe Eotb do
30
40
 
31
41
  it "should register two arguments" do
32
42
  Eotb.register_event("actor", "action").should == @response
43
+ Eotb.register_event("act2or", "acti2on").should == @response
33
44
  end
34
45
 
35
46
  it "should register three arguments" do
@@ -55,13 +66,24 @@ describe Eotb do
55
66
  it "should register arrays" do
56
67
  Eotb.register_event([2,3,4], :action, {:username => ["John", "Josh"]}).should == @response
57
68
  end
69
+
70
+ end
71
+
72
+ describe "should register data in one package" do
58
73
 
59
- it "should log errors" do
60
- logger = mock(Logger)
61
- logger.stub(:new) { logger }
62
- logger.stub(:error) { @response }
63
- Eotb.register_event(:actor, :action, {:username => "John"}).should == @response
74
+ before(:each) do
75
+ @response = "200"
76
+ Eotb.configure("0"*40, 5)
77
+ Net::HTTP.stub(:new) { Net::HTTP }
78
+ Net::HTTP.stub(:start) { Net::HTTP }
79
+ Net::HTTP.stub(:request) { "200" }
80
+ end
81
+
82
+ it "when registering 5 events" do
83
+ 4.times {Eotb.register_event("actor", "action", {:username => "John"})}
84
+ Eotb.register_event("actor", "action", {:username => "John"}).should == @response
64
85
  end
86
+
65
87
 
66
88
  end
67
89
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eotb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 2
10
- version: 0.5.2
9
+ - 3
10
+ version: 0.5.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ragnarson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-23 00:00:00 +02:00
18
+ date: 2010-08-30 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -95,6 +95,7 @@ files:
95
95
  - .document
96
96
  - .gitignore
97
97
  - Gemfile
98
+ - Gemfile.lock
98
99
  - LICENSE
99
100
  - README.rdoc
100
101
  - Rakefile