eotb 0.2.2 → 0.3.0
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/VERSION +1 -1
- data/eotb.gemspec +2 -5
- data/lib/eotb.rb +28 -12
- data/spec/eotb_spec.rb +19 -15
- metadata +4 -7
- data/lib/eotb_actor.rb +0 -13
- data/lib/eotb_subject.rb +0 -22
- data/lib/object.rb +0 -15
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
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.
|
8
|
+
s.version = "0.3.0"
|
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-06}
|
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 = [
|
@@ -27,9 +27,6 @@ Gem::Specification.new do |s|
|
|
27
27
|
"VERSION",
|
28
28
|
"eotb.gemspec",
|
29
29
|
"lib/eotb.rb",
|
30
|
-
"lib/eotb_actor.rb",
|
31
|
-
"lib/eotb_subject.rb",
|
32
|
-
"lib/object.rb",
|
33
30
|
"spec/eotb_spec.rb",
|
34
31
|
"spec/spec_helper.rb"
|
35
32
|
]
|
data/lib/eotb.rb
CHANGED
@@ -3,28 +3,44 @@ require 'net/http'
|
|
3
3
|
require 'uri'
|
4
4
|
require 'json'
|
5
5
|
|
6
|
-
require File.expand_path(File.dirname(__FILE__) + '/object')
|
7
|
-
require File.expand_path(File.dirname(__FILE__) + '/eotb_actor')
|
8
|
-
require File.expand_path(File.dirname(__FILE__) + '/eotb_subject')
|
9
|
-
|
10
6
|
class Eotb
|
11
7
|
|
12
8
|
def self.configure(api_key, host = '127.0.0.1', port = '3000')
|
13
9
|
@@uri = URI.parse('http://' + host + ':' + port + '/apps/' + api_key + '/events')
|
14
10
|
@@post = Net::HTTP::Post.new(@@uri.path)
|
15
|
-
@@api_key = api_key
|
11
|
+
@@api_key = { "event[app_id]" => api_key }
|
16
12
|
end
|
17
13
|
|
18
14
|
def self.register_event(actor, action, subject = {})
|
19
|
-
|
20
|
-
action = { "event[action]" => action }
|
21
|
-
actor = { "event[actor]" => actor }
|
22
|
-
subject_to_post = {}
|
23
|
-
subject.each { |key, value| subject_to_post["event[subject][#{key.to_s}]"] = value.to_s }
|
24
|
-
|
25
|
-
event = api_key.merge(actor).merge(action).merge(subject_to_post)
|
15
|
+
event = @@api_key.merge(to_actor(actor)).merge(to_action(action)).merge(to_subject(subject))
|
26
16
|
@@post.set_form_data(event)
|
27
17
|
Net::HTTP.new(@@uri.host, @@uri.port).start.request(@@post)
|
28
18
|
end
|
29
19
|
|
20
|
+
def self.to_actor(actor)
|
21
|
+
{ "event[actor]" => format(actor) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.to_action(action)
|
25
|
+
{ "event[action]" => action.to_s }
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.to_subject(subject)
|
29
|
+
subject = JSON.parse subject if subject.is_a? String
|
30
|
+
subject_to_post = {}
|
31
|
+
subject.each { |key, value| subject_to_post["event[subject][#{key.to_s}]"] = format(value) }
|
32
|
+
subject_to_post
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.format(object)
|
36
|
+
object_class = object.class
|
37
|
+
if [String, Symbol].member? object_class
|
38
|
+
object.to_s
|
39
|
+
elsif [Array, Hash].member? object_class
|
40
|
+
object.inspect
|
41
|
+
else
|
42
|
+
object_class
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
30
46
|
end
|
data/spec/eotb_spec.rb
CHANGED
@@ -3,32 +3,36 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
3
3
|
describe Eotb do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
@response = "
|
7
|
-
Eotb.configure("
|
6
|
+
@response = "200"
|
7
|
+
Eotb.configure("4c333965b3dfae07bd00000d")
|
8
8
|
end
|
9
9
|
|
10
|
-
it "should register
|
11
|
-
Eotb.register_event("
|
10
|
+
it "should register two arguments" do
|
11
|
+
Eotb.register_event("actor", "action").code.should == @response
|
12
12
|
end
|
13
13
|
|
14
|
-
it "should register
|
15
|
-
Eotb.register_event("
|
14
|
+
it "should register three arguments" do
|
15
|
+
Eotb.register_event("actor", "action", {:username => "John"}).code.should == @response
|
16
16
|
end
|
17
17
|
|
18
|
-
it "should register
|
19
|
-
Eotb.register_event(:
|
18
|
+
it "should register symbols" do
|
19
|
+
Eotb.register_event(:actor, :action, {:username => "John"}).code.should == @response
|
20
20
|
end
|
21
21
|
|
22
|
-
it "should register objects
|
23
|
-
Eotb.register_event(Object.new
|
22
|
+
it "should register objects" do
|
23
|
+
Eotb.register_event(Object.new, :action, {:username => Object.new}).code.should == @response
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should register hashes" do
|
27
|
+
Eotb.register_event({:type => "User"}, :action, {:username => "John"}).code.should == @response
|
24
28
|
end
|
25
29
|
|
26
|
-
it "should
|
27
|
-
|
30
|
+
it "should register arrays" do
|
31
|
+
Eotb.register_event([2,3,4], :action, {:username => ["John", "Josh"]}).code.should == @response
|
28
32
|
end
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
it "should register subject in json" do
|
35
|
+
Eotb.register_event(:actor, :action, "{\"username\":\"John\"}").code.should == @response
|
36
|
+
end
|
33
37
|
|
34
38
|
end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
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-06 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -70,9 +70,6 @@ files:
|
|
70
70
|
- VERSION
|
71
71
|
- eotb.gemspec
|
72
72
|
- lib/eotb.rb
|
73
|
-
- lib/eotb_actor.rb
|
74
|
-
- lib/eotb_subject.rb
|
75
|
-
- lib/object.rb
|
76
73
|
- spec/eotb_spec.rb
|
77
74
|
- spec/spec_helper.rb
|
78
75
|
has_rdoc: true
|
data/lib/eotb_actor.rb
DELETED
data/lib/eotb_subject.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
class EotbSubject
|
2
|
-
|
3
|
-
attr_reader :subject
|
4
|
-
|
5
|
-
def initialize(object)
|
6
|
-
@subject = {}
|
7
|
-
@subject.merge(object).each { |key, value| subject[key] = value.to_s }
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_json
|
11
|
-
@subject = JSON.generate(@subject)
|
12
|
-
end
|
13
|
-
|
14
|
-
# def to_hash
|
15
|
-
# @subject = JSON.parse(@subject)
|
16
|
-
# end
|
17
|
-
|
18
|
-
def inspect
|
19
|
-
@subject.inspect
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|