eotb 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ ---
2
+ hash: 3dbced1d1a21525620b773ff6f5ea1c928f6e9b4
3
+ sources:
4
+ - Rubygems:
5
+ uri: http://gemcutter.org
6
+ specs:
7
+ - json_pure:
8
+ version: 1.4.3
9
+ - gemcutter:
10
+ version: 0.5.0
11
+ - git:
12
+ version: 1.2.5
13
+ - rubyforge:
14
+ version: 2.0.4
15
+ - jeweler:
16
+ version: 1.4.0
17
+ - json:
18
+ version: 1.4.3
19
+ - rspec:
20
+ version: 1.3.0
21
+ dependencies:
22
+ jeweler:
23
+ version: ">= 1.4.0"
24
+ group:
25
+ - :default
26
+ json:
27
+ version: ">= 1.4.3"
28
+ group:
29
+ - :default
30
+ rspec:
31
+ version: ">= 1.3.0"
32
+ group:
33
+ - :default
data/README CHANGED
@@ -32,6 +32,7 @@ Using in your apps
32
32
  ------------------
33
33
  Add file eotb.rb in directory config/initializers of your rails application with content:
34
34
 
35
+ require 'Eotb'
35
36
  Eotb.configure("your_api_key", "host", "port") # default host and port are 127.0.0.1 and 3000
36
37
 
37
38
  Register events by:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
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.1.4"
8
+ s.version = "0.1.5"
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-06-30}
12
+ s.date = %q{2010-07-04}
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,13 +20,16 @@ Gem::Specification.new do |s|
20
20
  ".document",
21
21
  ".gitignore",
22
22
  "Gemfile",
23
+ "Gemfile.lock",
23
24
  "LICENSE",
24
25
  "README",
25
26
  "Rakefile",
26
27
  "VERSION",
27
28
  "eotb.gemspec",
28
- "init.rb",
29
+ "lib/actor.rb",
29
30
  "lib/eotb.rb",
31
+ "lib/object.rb",
32
+ "lib/subject.rb",
30
33
  "spec/eotb_spec.rb",
31
34
  "spec/spec_helper.rb"
32
35
  ]
data/lib/actor.rb ADDED
@@ -0,0 +1,22 @@
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/eotb.rb CHANGED
@@ -1,8 +1,12 @@
1
+ require 'rubygems'
1
2
  require 'net/http'
2
3
  require 'uri'
3
- require 'rubygems'
4
4
  require 'json'
5
5
 
6
+ require File.expand_path(File.dirname(__FILE__) + '/object')
7
+ require File.expand_path(File.dirname(__FILE__) + '/actor')
8
+ require File.expand_path(File.dirname(__FILE__) + '/subject')
9
+
6
10
  class Eotb
7
11
 
8
12
  def self.configure(api_key, host = '127.0.0.1', port = '3000')
@@ -12,16 +16,13 @@ class Eotb
12
16
  end
13
17
 
14
18
  def self.register_event(actor, action, subject)
15
- to_post = { "event[app_id]" => @@api_key, "event[actor][type]" => actor, "event[action]" => action }
16
- subject.each do |key, value|
17
- to_post["event[subject][#{key.to_s}]"] = value.to_s
18
- end
19
+ api_key = { "event[app_id]" => @@api_key }
20
+ action = { "event[action]" => action }
21
+ # TODO what if user don't send hash?
22
+ to_post = api_key.merge(actor).merge(action).merge(subject)
19
23
  @@http.set_form_data(to_post)
24
+
20
25
  Net::HTTP.new(@@uri.host, @@uri.port).start { |http| http.request(@@http) }
21
26
  end
22
27
 
23
- def to_json(array)
24
- JSON.generate(array)
25
- end
26
-
27
28
  end
data/lib/object.rb ADDED
@@ -0,0 +1,11 @@
1
+ class Object
2
+
3
+ def to_actor
4
+ Actor.new(self).actor
5
+ end
6
+
7
+ def to_subject
8
+ Subject.new(self).subject
9
+ end
10
+
11
+ end
data/lib/subject.rb ADDED
@@ -0,0 +1,27 @@
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
data/spec/eotb_spec.rb CHANGED
@@ -2,14 +2,6 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe Eotb do
4
4
 
5
- before(:each) do
6
- Eotb.new()
7
- Eotb.configure('0', '127.0.0.1', '3000')
8
- @data = ['actor', 'action', 'username']
9
- end
10
5
 
11
- it "should post data to unknown server" do
12
- Eotb.register_event(@data[0], @data[1], @data[2]).code.should eql('500')
13
- end
14
6
 
15
7
  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: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
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-06-30 00:00:00 +02:00
18
+ date: 2010-07-04 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -63,13 +63,16 @@ files:
63
63
  - .document
64
64
  - .gitignore
65
65
  - Gemfile
66
+ - Gemfile.lock
66
67
  - LICENSE
67
68
  - README
68
69
  - Rakefile
69
70
  - VERSION
70
71
  - eotb.gemspec
71
- - init.rb
72
+ - lib/actor.rb
72
73
  - lib/eotb.rb
74
+ - lib/object.rb
75
+ - lib/subject.rb
73
76
  - spec/eotb_spec.rb
74
77
  - spec/spec_helper.rb
75
78
  has_rdoc: true
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'eotb'