eotb 0.4.1 → 0.4.2
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.
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/eotb.gemspec +2 -2
- data/lib/eotb.rb +36 -10
- data/spec/eotb_spec.rb +20 -4
- metadata +4 -4
data/README.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.2
|
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.4.
|
8
|
+
s.version = "0.4.2"
|
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-07-
|
12
|
+
s.date = %q{2010-07-14}
|
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 = [
|
data/lib/eotb.rb
CHANGED
@@ -12,25 +12,51 @@ class Eotb
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.register_event(actor, action, subject = {})
|
15
|
-
|
16
|
-
|
17
|
-
data = {}
|
18
|
-
subject.each { |key, value| data["event[subject][#{key.to_s}]"] = format(value) }
|
19
|
-
|
20
|
-
event = @@api_key.merge(actor).merge(action).merge(data)
|
21
|
-
|
15
|
+
action = { "event[action]" => action.to_s }
|
16
|
+
event = @@api_key.merge(hash_format(actor, :actor)).merge(action).merge(hash_format(subject, :subject))
|
22
17
|
@@post.set_form_data(event)
|
23
18
|
Net::HTTP.new(@@uri.host, @@uri.port).start.request(@@post)
|
24
19
|
end
|
25
20
|
|
26
|
-
def self.
|
27
|
-
if object.respond_to? :
|
21
|
+
def self.value_format(object)
|
22
|
+
if object.respond_to? :to_actor
|
23
|
+
object.to_actor
|
24
|
+
elsif object.respond_to? :to_subject
|
25
|
+
object.to_subject
|
26
|
+
elsif object.respond_to? :to_json
|
28
27
|
object.to_json
|
29
28
|
elsif object.respond_to? :to_hash
|
30
|
-
|
29
|
+
object.to_hash
|
31
30
|
else
|
32
31
|
object.inspect
|
33
32
|
end
|
34
33
|
end
|
35
34
|
|
35
|
+
def self.hash_flatten(hash)
|
36
|
+
hash.inject({}) do |h, (k, v)|
|
37
|
+
if v.is_a?(Hash)
|
38
|
+
hash_flatten(v).each do |sk, sv|
|
39
|
+
h[[k] + sk] = sv
|
40
|
+
end
|
41
|
+
else
|
42
|
+
k = k ? [k] : []
|
43
|
+
h[k] = v
|
44
|
+
end
|
45
|
+
h
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.hash_format(hash, type)
|
50
|
+
if hash.is_a?(Hash)
|
51
|
+
a = hash_flatten(hash).map do |k, v|
|
52
|
+
key = k.map{ |e| "[#{e}]" }.join
|
53
|
+
"\"event[#{type}]#{key}\" => #{value_format(v)}"
|
54
|
+
end
|
55
|
+
a.join(', ')
|
56
|
+
else
|
57
|
+
a = "\"event[#{type}]\" => #{value_format(hash)}"
|
58
|
+
end
|
59
|
+
eval '{' + a + '}'
|
60
|
+
end
|
61
|
+
|
36
62
|
end
|
data/spec/eotb_spec.rb
CHANGED
@@ -2,11 +2,23 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
3
3
|
describe Eotb do
|
4
4
|
|
5
|
-
before(:
|
5
|
+
before(:all) do
|
6
6
|
@response = "200"
|
7
7
|
Eotb.configure("0"*24)
|
8
8
|
end
|
9
9
|
|
10
|
+
it "should format actor in string" do
|
11
|
+
Eotb.hash_format("actor", :actor).should == {"event[actor]" => "actor"}
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should format actor in hash" do
|
15
|
+
Eotb.hash_format({:type => "User"}, :actor).should == {"event[actor][type]" => "User"}
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should format actor in nested hash" do
|
19
|
+
Eotb.hash_format({:type => { :account => "User"}}, :actor).should == {"event[actor][type][account]" => "User"}
|
20
|
+
end
|
21
|
+
|
10
22
|
it "should register two arguments" do
|
11
23
|
Eotb.register_event("actor", "action").code.should == @response
|
12
24
|
end
|
@@ -20,15 +32,19 @@ describe Eotb do
|
|
20
32
|
end
|
21
33
|
|
22
34
|
it "should register objects" do
|
23
|
-
|
35
|
+
Eotb.register_event(Object.new, :action, {:username => Object.new}).code.should == @response
|
24
36
|
end
|
25
37
|
|
26
38
|
it "should register hashes" do
|
27
|
-
|
39
|
+
Eotb.register_event({:type => "User"}, :action, {:username => {:first_name => "John"}}).code.should == @response
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should register nested hashes" do
|
43
|
+
Eotb.register_event({:type => { :account => "User"}}, :action, {:username => {:first_name => "John"}}).code.should == @response
|
28
44
|
end
|
29
45
|
|
30
46
|
it "should register arrays" do
|
31
|
-
|
47
|
+
Eotb.register_event([2,3,4], :action, {:username => ["John", "Josh"]}).code.should == @response
|
32
48
|
end
|
33
49
|
|
34
50
|
end
|
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:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 2
|
10
|
+
version: 0.4.2
|
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-07-
|
18
|
+
date: 2010-07-14 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|