eotb 0.3.1 → 0.4.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/README.rdoc CHANGED
@@ -17,7 +17,7 @@ Install gem from GitHub repository
17
17
  $ git clone git://github.com/Quirke/eotb_rails_plugin.git
18
18
  $ cd eotb_rails_plugin
19
19
  $ rake build
20
- $ gem install ./pkg/eotb-0.2.0.gem
20
+ $ gem install ./pkg/eotb-0.3.1.gem
21
21
 
22
22
  === Bundler
23
23
 
@@ -51,10 +51,9 @@ Register actor and his action
51
51
 
52
52
  Eotb.register_event("user", "registered")
53
53
 
54
- Register subject of event (<b>it must be a Hash or JSON string!</b>)
54
+ Register subject of event (<b>it must be a Hash</b>)
55
55
 
56
56
  Eotb.register_event("user", "registered", {:username => "John", :when => "today"})
57
- Eotb.register_event("user", "registered", '{"username":"John", "when":"today"}')
58
57
 
59
58
  Use Symbols instead of Strings
60
59
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
data/eotb.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{eotb}
8
- s.version = "0.3.1"
8
+ s.version = "0.4.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"]
data/lib/eotb.rb CHANGED
@@ -12,34 +12,22 @@ class Eotb
12
12
  end
13
13
 
14
14
  def self.register_event(actor, action, subject = {})
15
- event = @@api_key.merge(to_actor(actor)).merge(to_action(action)).merge(to_subject(subject))
15
+ actor = { "event[actor]" => format(actor) }
16
+ action = { "event[action]" => action.to_s }
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
+
16
22
  @@post.set_form_data(event)
17
23
  Net::HTTP.new(@@uri.host, @@uri.port).start.request(@@post)
18
24
  end
19
25
 
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
26
  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
27
+ if object.respond_to? :to_json
28
+ object.to_json
41
29
  else
42
- object_class
30
+ object.inspect
43
31
  end
44
32
  end
45
33
 
data/spec/eotb_spec.rb CHANGED
@@ -4,7 +4,7 @@ describe Eotb do
4
4
 
5
5
  before(:each) do
6
6
  @response = "200"
7
- Eotb.configure("4c333965b3dfae07bd00000d")
7
+ Eotb.configure("0"*24)
8
8
  end
9
9
 
10
10
  it "should register two arguments" do
@@ -24,15 +24,11 @@ describe Eotb do
24
24
  end
25
25
 
26
26
  it "should register hashes" do
27
- Eotb.register_event({:type => "User"}, :action, {:username => "John"}).code.should == @response
27
+ Eotb.register_event({:type => "User"}, :action, {:username => {:first_name => "John"}}).code.should == @response
28
28
  end
29
29
 
30
30
  it "should register arrays" do
31
31
  Eotb.register_event([2,3,4], :action, {:username => ["John", "Josh"]}).code.should == @response
32
32
  end
33
33
 
34
- it "should register subject in json" do
35
- Eotb.register_event(:actor, :action, "{\"username\":\"John\"}").code.should == @response
36
- end
37
-
38
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: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ragnarson