eotb 0.1.5 → 0.2.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 +4 -4
- data/lib/eotb.rb +10 -8
- data/lib/eotb_actor.rb +13 -0
- data/lib/eotb_subject.rb +22 -0
- data/lib/object.rb +6 -2
- data/spec/eotb_spec.rb +27 -0
- metadata +7 -7
- data/lib/actor.rb +0 -22
- data/lib/subject.rb +0 -27
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.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.2.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-05}
|
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 = [
|
@@ -26,10 +26,10 @@ Gem::Specification.new do |s|
|
|
26
26
|
"Rakefile",
|
27
27
|
"VERSION",
|
28
28
|
"eotb.gemspec",
|
29
|
-
"lib/actor.rb",
|
30
29
|
"lib/eotb.rb",
|
30
|
+
"lib/eotb_actor.rb",
|
31
|
+
"lib/eotb_subject.rb",
|
31
32
|
"lib/object.rb",
|
32
|
-
"lib/subject.rb",
|
33
33
|
"spec/eotb_spec.rb",
|
34
34
|
"spec/spec_helper.rb"
|
35
35
|
]
|
data/lib/eotb.rb
CHANGED
@@ -4,25 +4,27 @@ require 'uri'
|
|
4
4
|
require 'json'
|
5
5
|
|
6
6
|
require File.expand_path(File.dirname(__FILE__) + '/object')
|
7
|
-
require File.expand_path(File.dirname(__FILE__) + '/
|
8
|
-
require File.expand_path(File.dirname(__FILE__) + '/
|
7
|
+
require File.expand_path(File.dirname(__FILE__) + '/eotb_actor')
|
8
|
+
require File.expand_path(File.dirname(__FILE__) + '/eotb_subject')
|
9
9
|
|
10
10
|
class Eotb
|
11
11
|
|
12
12
|
def self.configure(api_key, host = '127.0.0.1', port = '3000')
|
13
13
|
@@uri = URI.parse('http://' + host + ':' + port + '/apps/' + api_key + '/events')
|
14
|
-
@@
|
14
|
+
@@post = Net::HTTP::Post.new(@@uri.path)
|
15
15
|
@@api_key = api_key
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.register_event(actor, action, subject)
|
18
|
+
def self.register_event(actor, action, subject = {})
|
19
19
|
api_key = { "event[app_id]" => @@api_key }
|
20
20
|
action = { "event[action]" => action }
|
21
|
-
|
22
|
-
to_post = api_key.merge(actor).merge(action).merge(subject)
|
23
|
-
@@http.set_form_data(to_post)
|
21
|
+
actor = { "event[actor]" => actor }
|
24
22
|
|
25
|
-
|
23
|
+
subject.each { |key, value| subject["event[subject][#{key.to_s}]"] = value.to_s }
|
24
|
+
|
25
|
+
event = api_key.merge(actor).merge(action).merge(subject)
|
26
|
+
@@post.set_form_data(event)
|
27
|
+
Net::HTTP.new(@@uri.host, @@uri.port).start.request(@@post)
|
26
28
|
end
|
27
29
|
|
28
30
|
end
|
data/lib/eotb_actor.rb
ADDED
data/lib/eotb_subject.rb
ADDED
@@ -0,0 +1,22 @@
|
|
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.inspect }
|
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
|
data/lib/object.rb
CHANGED
data/spec/eotb_spec.rb
CHANGED
@@ -2,6 +2,33 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
3
3
|
describe Eotb do
|
4
4
|
|
5
|
+
before(:each) do
|
6
|
+
@response = "302"
|
7
|
+
Eotb.configure("4c30fc21b3dfae0b18000078")
|
8
|
+
end
|
5
9
|
|
10
|
+
it "should register only two arguments" do
|
11
|
+
Eotb.register_event("actor_string", "action_string").code.should == @response
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should register default arguments (strings)" do
|
15
|
+
Eotb.register_event("actor_string", "action_string", {:username => "John"}).code.should == @response
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should register default arguments (symbols)" do
|
19
|
+
Eotb.register_event(:actor_symbol, :action_symbol, {:username => "John"}).code.should == @response
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should register objects with to_actor and to_subject" do
|
23
|
+
Eotb.register_event(Object.new.to_actor, :action_symbol, {:username => Object.new}.to_subject).code.should == @response
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should generate JSON from subject" do
|
27
|
+
{:username => "John"}.to_subject.to_json.should == JSON.generate({:username => "String"})
|
28
|
+
end
|
29
|
+
|
30
|
+
# it "should parse JSON from subject" do
|
31
|
+
# {:username => "John"}.to_subject.to_json.to_hash.should == JSON.generate({:username => "String"})
|
32
|
+
# end
|
6
33
|
|
7
34
|
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: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.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-05 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -69,10 +69,10 @@ files:
|
|
69
69
|
- Rakefile
|
70
70
|
- VERSION
|
71
71
|
- eotb.gemspec
|
72
|
-
- lib/actor.rb
|
73
72
|
- lib/eotb.rb
|
73
|
+
- lib/eotb_actor.rb
|
74
|
+
- lib/eotb_subject.rb
|
74
75
|
- lib/object.rb
|
75
|
-
- lib/subject.rb
|
76
76
|
- spec/eotb_spec.rb
|
77
77
|
- spec/spec_helper.rb
|
78
78
|
has_rdoc: true
|
data/lib/actor.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
class Actor
|
2
|
-
|
3
|
-
attr_reader :actor
|
4
|
-
|
5
|
-
def initialize(object)
|
6
|
-
@actor = { "event[actor][type]" => object.to_s }
|
7
|
-
end
|
8
|
-
|
9
|
-
def to_json
|
10
|
-
@actor = JSON.generate(@actor)
|
11
|
-
end
|
12
|
-
|
13
|
-
# TODO
|
14
|
-
# def to_hash
|
15
|
-
# @actor = JSON.parse(@actor)
|
16
|
-
# end
|
17
|
-
|
18
|
-
def inspect
|
19
|
-
@actor.inspect
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
data/lib/subject.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
class Subject
|
2
|
-
|
3
|
-
attr_reader :subject
|
4
|
-
|
5
|
-
# FIXME subject is not a hash
|
6
|
-
|
7
|
-
def initialize(object)
|
8
|
-
@subject = {}
|
9
|
-
object.each do |key, value|
|
10
|
-
@subject["event[subject][#{key.to_s}]"] = value.to_s
|
11
|
-
end
|
12
|
-
@subject
|
13
|
-
end
|
14
|
-
|
15
|
-
def inspect
|
16
|
-
@subject.inspect
|
17
|
-
end
|
18
|
-
|
19
|
-
# TODO def to_hash
|
20
|
-
# @subject = JSON.parse(@subject)
|
21
|
-
# end
|
22
|
-
|
23
|
-
def to_json
|
24
|
-
@subject = JSON.generate(@subject)
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|