eotb 0.5.11 → 0.5.12

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,6 +4,16 @@ Rails plugin which allow you easily track and observe your apps.
4
4
 
5
5
  == Installation
6
6
 
7
+ === Bundler
8
+
9
+ For rails3 you just want to add this line to the Gemfile
10
+
11
+ gem 'eotb'
12
+
13
+ and run
14
+
15
+ $ bundle install
16
+
7
17
  === RubyGems
8
18
 
9
19
  Install gem in traditional way
@@ -17,17 +27,7 @@ Install gem from GitHub repository
17
27
  $ git clone git://github.com/Quirke/eotb_rails_plugin.git
18
28
  $ cd eotb_rails_plugin
19
29
  $ rake build
20
- $ gem install ./pkg/eotb-0.5.1.gem
21
-
22
- === Bundler
23
-
24
- Add this line to Gemfile in your rails application
25
-
26
- gem 'eotb'
27
-
28
- And run
29
-
30
- $ bundle install
30
+ $ gem install ./pkg/eotb-0.5.11.gem
31
31
 
32
32
  == Getting API Key
33
33
 
@@ -40,25 +40,20 @@ As a result you will get API Key of your application.
40
40
 
41
41
  To configure your rails 3 app just run the generator with your_api_key and optional number of events sent in one package to Beholder:
42
42
 
43
- rails generate eotb --api-key=your_api_key [--events=number_of_events]
43
+ rails generate eotb --api-key=your_api_key
44
44
 
45
45
  === Rails 2
46
46
 
47
47
  To configure your rails 2 app just run the generator with your_api_key and optional number of events sent in one package to Beholder:
48
48
 
49
- script/generate eotb --api-key=your_api_key [--events=number_of_events]
49
+ script/generate eotb --api-key=your_api_key
50
50
 
51
51
  === Configuration file
52
52
 
53
53
  If you didn't use rails generator you can manualy create a file <tt>eotb.rb</tt> in directory <tt>config/initializers</tt> in your rails application with content:
54
54
 
55
55
  require 'Eotb'
56
- Eotb.configure("your_api_key", "events", "host", "port")
57
- # default host and port are 127.0.0.1 and 3000
58
- # to use it with Beholder:
59
- # host = "beta.beholder.ragnarson.com"
60
- # port = "80"
61
- # events - number of events sent in one package/request to beholder, default 1.
56
+ Eotb.configure("your_api_key")
62
57
 
63
58
  == Using in your apps
64
59
 
data/Rakefile CHANGED
@@ -8,12 +8,11 @@ begin
8
8
  gem.summary = "Rails plugin which allow you easily track and observe your apps"
9
9
  gem.description = "Rails plugin which allow you easily track and observe your apps"
10
10
  gem.email = "bartlomiej.kozal@ragnarson.com"
11
- gem.homepage = "http://github.com/placek/eotb_rails_plugin"
11
+ gem.homepage = "http://github.com/Ragnarson/eotb_rails_plugin"
12
12
  gem.authors = ["Ragnarson"]
13
13
  gem.add_development_dependency "rspec", ">= 1.3.0"
14
14
  gem.add_development_dependency "jeweler", ">= 1.4.0"
15
15
  gem.add_dependency "json", ">= 1.4.3"
16
- gem.add_dependency "hoptoad_notifier", ">= 2.3.2"
17
16
  end
18
17
 
19
18
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.11
1
+ 0.5.12
data/bin/eotb ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pp'
4
+ require 'optparse'
5
+
6
+ class EotbConfigurator
7
+ def parse_options
8
+ @app = Hash.new
9
+ options = OptionParser.new do |opts|
10
+ opts.on("init") do
11
+ @action = :init
12
+ end
13
+ opts.on("-a", "--api-key=[ARG]", "Your API Key") do |opt|
14
+ @app[:apikey] = opt
15
+ end
16
+ opts.on("-e", "--events=[ARG]", "Number of events") do |opt|
17
+ @app[:events] = opt
18
+ end
19
+ end
20
+ options.parse!(ARGV)
21
+ end
22
+
23
+ def recognize_rails_version
24
+ @version = %x( rails -v ).split[1]
25
+ end
26
+
27
+ def ensure_parameter_was_set
28
+ if !@app[:apikey]
29
+ puts "Must pass --api-key or create config/initializers/eotb.rb"
30
+ exit
31
+ end
32
+ end
33
+
34
+ def prepare_command
35
+ if @version >= "3"
36
+ command = "rails generate eotb --api-key=#{@app[:apikey]}"
37
+ else
38
+ command = "script/generate eotb --api-key=#{@app[:apikey]}"
39
+ end
40
+ if @app[:events]
41
+ command = command + " --events=#{@app[:events]}"
42
+ end
43
+ command
44
+ end
45
+
46
+ def configure args
47
+ @args = args
48
+ parse_options
49
+ ensure_parameter_was_set
50
+ recognize_rails_version
51
+ command = prepare_command
52
+ # exec( command )
53
+ puts "Will execute: "+command
54
+ end
55
+ end
56
+
57
+ EotbConfigurator.new.configure ARGV
data/eotb.gemspec CHANGED
@@ -5,13 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{eotb}
8
- s.version = "0.5.11"
8
+ s.version = "0.5.12"
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-09-20}
12
+ s.date = %q{2010-09-27}
13
+ s.default_executable = %q{eotb}
13
14
  s.description = %q{Rails plugin which allow you easily track and observe your apps}
14
15
  s.email = %q{bartlomiej.kozal@ragnarson.com}
16
+ s.executables = ["eotb"]
15
17
  s.extra_rdoc_files = [
16
18
  "LICENSE",
17
19
  "README.rdoc"
@@ -25,6 +27,7 @@ Gem::Specification.new do |s|
25
27
  "README.rdoc",
26
28
  "Rakefile",
27
29
  "VERSION",
30
+ "bin/eotb",
28
31
  "eotb.gemspec",
29
32
  "generators/eotb/USAGE",
30
33
  "generators/eotb/eotb_generator.rb",
@@ -36,14 +39,14 @@ Gem::Specification.new do |s|
36
39
  "spec/eotb_spec.rb",
37
40
  "spec/spec_helper.rb"
38
41
  ]
39
- s.homepage = %q{http://github.com/placek/eotb_rails_plugin}
42
+ s.homepage = %q{http://github.com/Ragnarson/eotb_rails_plugin}
40
43
  s.rdoc_options = ["--charset=UTF-8"]
41
44
  s.require_paths = ["lib"]
42
45
  s.rubygems_version = %q{1.3.7}
43
46
  s.summary = %q{Rails plugin which allow you easily track and observe your apps}
44
47
  s.test_files = [
45
- "spec/eotb_spec.rb",
46
- "spec/spec_helper.rb"
48
+ "spec/spec_helper.rb",
49
+ "spec/eotb_spec.rb"
47
50
  ]
48
51
 
49
52
  if s.respond_to? :specification_version then
@@ -54,18 +57,15 @@ Gem::Specification.new do |s|
54
57
  s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
55
58
  s.add_development_dependency(%q<jeweler>, [">= 1.4.0"])
56
59
  s.add_runtime_dependency(%q<json>, [">= 1.4.3"])
57
- s.add_runtime_dependency(%q<hoptoad_notifier>, [">= 2.3.2"])
58
60
  else
59
61
  s.add_dependency(%q<rspec>, [">= 1.3.0"])
60
62
  s.add_dependency(%q<jeweler>, [">= 1.4.0"])
61
63
  s.add_dependency(%q<json>, [">= 1.4.3"])
62
- s.add_dependency(%q<hoptoad_notifier>, [">= 2.3.2"])
63
64
  end
64
65
  else
65
66
  s.add_dependency(%q<rspec>, [">= 1.3.0"])
66
67
  s.add_dependency(%q<jeweler>, [">= 1.4.0"])
67
68
  s.add_dependency(%q<json>, [">= 1.4.3"])
68
- s.add_dependency(%q<hoptoad_notifier>, [">= 2.3.2"])
69
69
  end
70
70
  end
71
71
 
@@ -3,7 +3,7 @@ Description:
3
3
 
4
4
 
5
5
  Example:
6
- rails generate eotb --api-key=your_api_key [--events=number_of_events]
6
+ rails generate eotb --api-key=your_api_key
7
7
 
8
8
  This will create:
9
9
  config/initializers/eotb.rb
@@ -2,13 +2,12 @@ class EotbGenerator < Rails::Generator::Base
2
2
 
3
3
  def add_options!(opt)
4
4
  opt.on('-k', '--api-key=key', String, "Your Beholder API key") {|v| options[:api_key] = v}
5
- opt.on('-e', '--events=number_of_event', Integer, "Number of events sent in one package to Beholder") {|v| options[:events] = v}
6
5
  end
7
6
 
8
7
  def manifest
9
8
  record do |m|
10
9
  ensure_parameter_was_set
11
- m.template "initializer.rb", "config/initializers/eotb.rb", :assigns => {:api_key => api_key_exp, :events => events_exp}
10
+ m.template "initializer.rb", "config/initializers/eotb.rb", :assigns => {:api_key => api_key_exp}
12
11
  end
13
12
 
14
13
  end
@@ -16,14 +15,6 @@ class EotbGenerator < Rails::Generator::Base
16
15
  def api_key_exp
17
16
  "#{options[:api_key]}"
18
17
  end
19
-
20
- def events_exp
21
- s = if options[:events]
22
- "#{options[:events]}"
23
- else
24
- "1"
25
- end
26
- end
27
18
 
28
19
  def ensure_parameter_was_set
29
20
  if !options[:api_key]
@@ -1,3 +1,3 @@
1
1
  require 'eotb'
2
2
 
3
- Eotb.configure("<%= api_key_exp %>", <%= events_exp %>, "beta.beholder.ragnarson.com", "80")
3
+ Eotb.configure("<%= api_key_exp %>")
data/lib/eotb.rb CHANGED
@@ -3,46 +3,82 @@ require 'net/http'
3
3
  require 'timeout'
4
4
  require 'uri'
5
5
  require 'json'
6
+ require 'timer'
6
7
 
7
8
  class Eotb
8
9
 
9
10
  @@api_key = nil
10
11
  METHODS = [:to_actor, :to_subject, :to_json, :to_hash, :inspect]
11
12
 
12
- def self.configure(api_key, events = 1, host = '127.0.0.1', port = '3000')
13
+ def self.configure(api_key)
14
+ @@host = "beta.beholder.ragnarson.com"
15
+ @@port = '80'
13
16
  @@api_key = api_key
14
- @@uri = URI.parse('http://' + host + ':' + port + '/events/' + api_key)
17
+ @@uri = URI.parse('http://' + @@host + ':' + @@port + '/events/' + api_key)
15
18
  @@post = Net::HTTP::Post.new(@@uri.path)
16
19
  @@events = {}
17
20
  @@counter = 1
18
- events >= 1 ? @@reset = events : @@reset = 1
21
+ @@reset = 100
22
+
23
+ Thread.new do
24
+ Timer.every(600.0) { |elapsed|
25
+ unless @@events.empty?
26
+ @@counter = @@reset
27
+ send
28
+ end
29
+ }
30
+ end unless ENV['RAILS_ENV'] == 'test'
19
31
  end
20
32
 
21
33
  def self.api_key
22
34
  @@api_key
23
35
  end
24
36
 
25
- def self.register_event(actor, action, subject = {})
37
+ def self.register_event(*args)
38
+ case args.size
39
+ when 1
40
+ self._json_register_event(*args)
41
+ when 2,3
42
+ self._base_register_event(*args)
43
+ else
44
+ raise ArgumentError, "wrong number of arguments (#{args.size} for 1,2 or 3)"
45
+ end
46
+ end
47
+
48
+ def self._json_register_event(json)
49
+ json = JSON.parse json
50
+ args = [json["actor"],json["action"]]
51
+ args << json["subject"] if json["subject"]
52
+ self._base_register_event(*args)
53
+ end
54
+
55
+ def self._base_register_event(actor, action, subject = {})
56
+ unless ENV['RAILS_ENV'] == 'test'
26
57
  action = { "event#{@@counter}[action]" => action.to_s }
27
- event = (hash_format(actor, :actor)).merge(action).merge(hash_format(subject, :subject))
58
+ event = (hash_format(actor, :actor)).merge(action).merge(hash_format(subject, :subject))
28
59
 
29
- @@events.merge! event
30
- if (@@counter == @@reset)
31
- @@post.set_form_data(@@events)
32
- @@counter = 1
33
- begin
34
- Timeout::timeout(2) {
35
- Net::HTTP.new(@@uri.host, @@uri.port).start.request(@@post)
36
- }
37
- rescue => e
38
- logger = Logger.new("log/#{ENV['RAILS_ENV']}.log")
39
- logger.error "ERROR eotb gem: " + e.to_s
40
- rescue Timeout::Error => e
41
- logger = Logger.new("log/#{ENV['RAILS_ENV']}.log")
42
- logger.error "ERROR eotb gem: " + e.to_s
60
+ @@events.merge! event
61
+ if (@@counter == @@reset)
62
+ send
63
+ else
64
+ @@counter += 1
43
65
  end
44
- else
45
- @@counter += 1
66
+ end
67
+ end
68
+
69
+ def self.send
70
+ @@post.set_form_data(@@events)
71
+ @@counter = 1
72
+ begin
73
+ Timeout::timeout(2) {
74
+ Net::HTTP.new(@@uri.host, @@uri.port).start.request(@@post)
75
+ }
76
+ rescue => e
77
+ logger = Logger.new("log/#{ENV['RAILS_ENV']}.log")
78
+ logger.error "ERROR eotb gem: " + e.to_s
79
+ rescue Timeout::Error => e
80
+ logger = Logger.new("log/#{ENV['RAILS_ENV']}.log")
81
+ logger.error "ERROR eotb gem: " + e.to_s
46
82
  end
47
83
  end
48
84
 
@@ -2,7 +2,7 @@ Description:
2
2
  Creates eotb initializer in confing/initializers/eotb.rb, setting your app to work with Beholder.
3
3
 
4
4
  Example:
5
- rails generate eotb --api-key=your_api_key [--events=number_of_events]
5
+ rails generate eotb --api-key=your_api_key
6
6
 
7
7
  This will create:
8
8
  config/initializers/eotb.rb
@@ -7,7 +7,6 @@ class EotbGenerator < Rails::Generators::Base
7
7
  source_root File.expand_path('../../../../generators/eotb/templates', __FILE__)
8
8
 
9
9
  class_option :api_key, :aliases => "-k", :type => :string, :desc => "Your Beholder API key"
10
- class_option :events, :aliases => "-e",:type => :numeric, :desc => "Number of events sent in one package to Beholder", :default => "1"
11
10
 
12
11
  def generator
13
12
  ensure_parameters_was_set
@@ -29,20 +28,17 @@ class EotbGenerator < Rails::Generators::Base
29
28
  def api_key_exp
30
29
  "#{options[:api_key]}"
31
30
  end
32
- def events_exp
33
- s = if options[:events]
34
- "#{options[:events]}"
35
- else
36
- "1"
37
- end
38
- end
39
31
 
40
32
  def generate_initializer
41
33
  template 'initializer.rb', 'config/initializers/eotb.rb'
42
34
  end
43
35
 
44
36
  def api_key_configured?
45
- File.exists?('config/initializers/eotb.rb')
37
+ if !options[:api_key]
38
+ puts "Must pass --api-key='your_api_key'"
39
+ exit
40
+ end
41
+ File.exists?('config/initializers/eotb.rb') && options[:api_key].empty?
46
42
  end
47
43
 
48
44
  end
data/spec/eotb_spec.rb CHANGED
@@ -2,13 +2,6 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe Eotb do
4
4
 
5
- it "should log errors" do
6
- logger = mock(Logger)
7
- logger.stub(:new) { logger }
8
- logger.stub(:error) { @response }
9
- Eotb.register_event(:actor, :action, {:username => "John"}).should == @response
10
- end
11
-
12
5
  describe "shoud format objects" do
13
6
  before do
14
7
  @@counter = 0
@@ -32,7 +25,9 @@ describe Eotb do
32
25
 
33
26
  before(:each) do
34
27
  @response = "200"
35
- Eotb.configure("0"*40, 1)
28
+
29
+ Eotb.configure("0"*40)
30
+ @@counter = 100
36
31
  Net::HTTP.stub(:new) { Net::HTTP }
37
32
  Net::HTTP.stub(:start) { Net::HTTP }
38
33
  Net::HTTP.stub(:request) { "200" }
@@ -40,7 +35,6 @@ describe Eotb do
40
35
 
41
36
  it "should register two arguments" do
42
37
  Eotb.register_event("actor", "action").should == @response
43
- Eotb.register_event("act2or", "acti2on").should == @response
44
38
  end
45
39
 
46
40
  it "should register three arguments" do
@@ -63,6 +57,10 @@ describe Eotb do
63
57
  Eotb.register_event({:type => { :account => "User"}}, :action, {:username => {:first_name => "John"}}).should == @response
64
58
  end
65
59
 
60
+ it "should register JSON messages" do
61
+ Eotb.register_event('{"actor":{"type":{"account":"User"}},"action":"action","subject":{"username":{"first_name":"John"}}}').should == @response
62
+ end
63
+
66
64
  it "should register arrays" do
67
65
  Eotb.register_event([2,3,4], :action, {:username => ["John", "Josh"]}).should == @response
68
66
  end
@@ -73,7 +71,8 @@ describe Eotb do
73
71
 
74
72
  before(:each) do
75
73
  @response = "200"
76
- Eotb.configure("0"*40, 5)
74
+ Eotb.configure("0"*40)
75
+ @@counter = 96
77
76
  Net::HTTP.stub(:new) { Net::HTTP }
78
77
  Net::HTTP.stub(:start) { Net::HTTP }
79
78
  Net::HTTP.stub(:request) { "200" }
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: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 11
10
- version: 0.5.11
9
+ - 12
10
+ version: 0.5.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ragnarson
@@ -15,8 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-20 00:00:00 +02:00
19
- default_executable:
18
+ date: 2010-09-27 00:00:00 +02:00
19
+ default_executable: eotb
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: rspec
@@ -66,26 +66,10 @@ dependencies:
66
66
  version: 1.4.3
67
67
  type: :runtime
68
68
  version_requirements: *id003
69
- - !ruby/object:Gem::Dependency
70
- name: hoptoad_notifier
71
- prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- hash: 7
78
- segments:
79
- - 2
80
- - 3
81
- - 2
82
- version: 2.3.2
83
- type: :runtime
84
- version_requirements: *id004
85
69
  description: Rails plugin which allow you easily track and observe your apps
86
70
  email: bartlomiej.kozal@ragnarson.com
87
- executables: []
88
-
71
+ executables:
72
+ - eotb
89
73
  extensions: []
90
74
 
91
75
  extra_rdoc_files:
@@ -100,6 +84,7 @@ files:
100
84
  - README.rdoc
101
85
  - Rakefile
102
86
  - VERSION
87
+ - bin/eotb
103
88
  - eotb.gemspec
104
89
  - generators/eotb/USAGE
105
90
  - generators/eotb/eotb_generator.rb
@@ -111,7 +96,7 @@ files:
111
96
  - spec/eotb_spec.rb
112
97
  - spec/spec_helper.rb
113
98
  has_rdoc: true
114
- homepage: http://github.com/placek/eotb_rails_plugin
99
+ homepage: http://github.com/Ragnarson/eotb_rails_plugin
115
100
  licenses: []
116
101
 
117
102
  post_install_message:
@@ -145,5 +130,5 @@ signing_key:
145
130
  specification_version: 3
146
131
  summary: Rails plugin which allow you easily track and observe your apps
147
132
  test_files:
148
- - spec/eotb_spec.rb
149
133
  - spec/spec_helper.rb
134
+ - spec/eotb_spec.rb