eotb 0.5.16 → 0.5.18
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 +4 -0
- data/VERSION +1 -1
- data/bin/eotb +1 -1
- data/eotb.gemspec +6 -3
- data/generators/eotb/eotb_generator.rb +2 -17
- data/generators/eotb/templates/initializer.rb +2 -1
- data/lib/eotb.rb +22 -8
- data/lib/eotb/report.rb +89 -0
- data/lib/generators/eotb/eotb_generator.rb +2 -16
- data/spec/eotb_spec.rb +14 -4
- data/spec/report_spec.rb +39 -0
- data/spec/spec_helper.rb +3 -0
- metadata +7 -4
data/README.rdoc
CHANGED
@@ -91,6 +91,10 @@ Register hashes and nested hashes
|
|
91
91
|
You can register any type of objects
|
92
92
|
|
93
93
|
Eotb.register_event(Object.new, :fed, {:pet => Dog.new})
|
94
|
+
|
95
|
+
== Using Query API
|
96
|
+
|
97
|
+
eotb version >= 0.5.17 supports new feature which let's you incorporate reports in your application. For more info please vist: http://beta.beholder.ragnarson.com/doc/how_to_use_query_api
|
94
98
|
|
95
99
|
== Copyright
|
96
100
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.18
|
data/bin/eotb
CHANGED
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.5.
|
8
|
+
s.version = "0.5.18"
|
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-
|
12
|
+
s.date = %q{2010-11-23}
|
13
13
|
s.default_executable = %q{eotb}
|
14
14
|
s.description = %q{Rails plugin which allow you easily track and observe your apps}
|
15
15
|
s.email = %q{bartlomiej.kozal@ragnarson.com}
|
@@ -33,10 +33,12 @@ Gem::Specification.new do |s|
|
|
33
33
|
"generators/eotb/eotb_generator.rb",
|
34
34
|
"generators/eotb/templates/initializer.rb",
|
35
35
|
"lib/eotb.rb",
|
36
|
+
"lib/eotb/report.rb",
|
36
37
|
"lib/generators/eotb/USAGE",
|
37
38
|
"lib/generators/eotb/eotb_generator.rb",
|
38
39
|
"lib/timer.rb",
|
39
40
|
"spec/eotb_spec.rb",
|
41
|
+
"spec/report_spec.rb",
|
40
42
|
"spec/spec_helper.rb"
|
41
43
|
]
|
42
44
|
s.homepage = %q{http://github.com/Ragnarson/eotb_rails_plugin}
|
@@ -46,7 +48,8 @@ Gem::Specification.new do |s|
|
|
46
48
|
s.summary = %q{Rails plugin which allow you easily track and observe your apps}
|
47
49
|
s.test_files = [
|
48
50
|
"spec/spec_helper.rb",
|
49
|
-
"spec/eotb_spec.rb"
|
51
|
+
"spec/eotb_spec.rb",
|
52
|
+
"spec/report_spec.rb"
|
50
53
|
]
|
51
54
|
|
52
55
|
if s.respond_to? :specification_version then
|
@@ -2,14 +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('-l', '--login=login', String, "Your Beholder app login") {|v| options[:email] = v}
|
6
|
-
opt.on('-d', '--password=password', String, "Your Beholder app password") {|v| options[:password] = v}
|
7
5
|
end
|
8
6
|
|
9
7
|
def manifest
|
10
8
|
record do |m|
|
11
9
|
ensure_parameter_was_set
|
12
|
-
m.template "initializer.rb", "config/initializers/eotb.rb", :assigns => {:api_key => api_key_exp
|
10
|
+
m.template "initializer.rb", "config/initializers/eotb.rb", :assigns => {:api_key => api_key_exp }
|
13
11
|
end
|
14
12
|
|
15
13
|
end
|
@@ -17,24 +15,11 @@ class EotbGenerator < Rails::Generator::Base
|
|
17
15
|
def api_key_exp
|
18
16
|
"#{options[:api_key]}"
|
19
17
|
end
|
20
|
-
|
21
|
-
"#{options[:login]}"
|
22
|
-
end
|
23
|
-
def password_exp
|
24
|
-
"#{options[:password]}"
|
25
|
-
end
|
26
|
-
|
18
|
+
|
27
19
|
def ensure_parameter_was_set
|
28
20
|
if !options[:api_key]
|
29
21
|
puts "Must pass --api-key='your_api_key' or -k 'your_api_key'"
|
30
22
|
exit
|
31
|
-
elsif !options[:login]
|
32
|
-
puts "Must pass --login='app_login' or -l 'app_login'"
|
33
|
-
exit
|
34
|
-
elsif !options[:password]
|
35
|
-
puts "Must pass --password='app_password' or -d 'app_password'"
|
36
|
-
exit
|
37
|
-
end
|
38
23
|
end
|
39
24
|
|
40
25
|
end
|
data/lib/eotb.rb
CHANGED
@@ -10,28 +10,36 @@ class Eotb
|
|
10
10
|
@@api_key = nil
|
11
11
|
METHODS = [:to_actor, :to_subject, :to_json, :to_hash, :inspect]
|
12
12
|
|
13
|
-
def self.configure(*params)
|
13
|
+
def self.configure(*params)
|
14
14
|
@@host = "beta.beholder.ragnarson.com"
|
15
15
|
@@port = '80'
|
16
16
|
@@api_key = params[0] if params.size > 0
|
17
17
|
@@reset = 100
|
18
|
-
if params.size == 1
|
19
|
-
|
20
|
-
puts 'Eotb.configure(api_key) -- method will be removed in eotb 0.5.17'
|
18
|
+
if params.size == 1
|
19
|
+
|
21
20
|
@@uri = URI.parse('http://' + @@host + ':' + @@port + '/events/' + @@api_key)
|
22
21
|
@@post = Net::HTTP::Post.new(@@uri.path)
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
|
23
|
+
elsif params.size == 4 # DEPRECATED - remove on Eotb 0.5.19
|
24
|
+
|
26
25
|
@@host = params[2]
|
27
26
|
@@port = params[3]
|
28
27
|
params[1].to_i >= 1 ? @@reset = params[1].to_i : @@reset = 1
|
29
28
|
@@uri = URI.parse('http://' + @@host + ':' + @@port + '/events/' + @@api_key)
|
30
29
|
@@post = Net::HTTP::Post.new(@@uri.path)
|
31
|
-
|
30
|
+
puts 'DEPRECATION WARNING'
|
31
|
+
puts 'Eotb.configure(api_key, events, host, port) -- method will be removed in eotb 0.5.19'
|
32
|
+
|
33
|
+
elsif params.size == 3 # DEPRECATED - remove on Eotb 0.5.19
|
34
|
+
|
32
35
|
@@uri = URI.parse('http://' + @@host + ':' + @@port + '/events/' + @@api_key)
|
33
36
|
@@post = Net::HTTP::Post.new(@@uri.path)
|
37
|
+
@@login = params[1]
|
38
|
+
@@pass = params[2]
|
34
39
|
@@post.basic_auth params[1], params[2]
|
40
|
+
puts 'DEPRECATION WARNING'
|
41
|
+
puts 'Eotb.configure(api_key) -- method will be removed in eotb 0.5.19'
|
42
|
+
|
35
43
|
else
|
36
44
|
raise ArgumentError, 'Wrong number of arguments. Check Eotb.configure parameters!'
|
37
45
|
end
|
@@ -52,6 +60,12 @@ class Eotb
|
|
52
60
|
def self.api_key
|
53
61
|
@@api_key
|
54
62
|
end
|
63
|
+
def self.host_port
|
64
|
+
[@@host, @@port]
|
65
|
+
end
|
66
|
+
def self.login_password
|
67
|
+
[@@login, @@pass]
|
68
|
+
end
|
55
69
|
def self.events
|
56
70
|
@@events
|
57
71
|
end
|
data/lib/eotb/report.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
class Eotb::Report
|
3
|
+
|
4
|
+
def self.find(query)
|
5
|
+
configure 'find'
|
6
|
+
hash = {}
|
7
|
+
query.each_pair { |k, v|
|
8
|
+
hash.merge!(hash_format(v, k))
|
9
|
+
}
|
10
|
+
@@post.set_form_data(hash)
|
11
|
+
array = JSON.parse send
|
12
|
+
array.map { |a| OpenStruct.new(a) }.sort {|x ,y| y.created_on <=> x.created_on}
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.latest
|
16
|
+
configure 'latest'
|
17
|
+
array = JSON.parse(send)
|
18
|
+
array.map { |a| OpenStruct.new(a) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.latest_daily
|
22
|
+
configure 'latest_daily'
|
23
|
+
array = JSON.parse(send)
|
24
|
+
array.map { |a| OpenStruct.new(a) }
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.latest_weekly
|
28
|
+
configure 'latest_weekly'
|
29
|
+
array = JSON.parse(send)
|
30
|
+
array.map { |a| OpenStruct.new(a) }
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def self.configure(option)
|
36
|
+
@@uri = URI.parse('http://' + Eotb.host_port[0] + ':' + Eotb.host_port[1] + '/gem/' + Eotb.api_key + '/' + option )
|
37
|
+
@@post = Net::HTTP::Post.new(@@uri.path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.send()
|
41
|
+
res = {}
|
42
|
+
begin
|
43
|
+
Timeout::timeout(2) {
|
44
|
+
res = Net::HTTP.new(@@uri.host, @@uri.port).start.request(@@post)
|
45
|
+
}
|
46
|
+
rescue => e
|
47
|
+
logger = Logger.new("log/#{ENV['RAILS_ENV']}.log")
|
48
|
+
logger.error "ERROR eotb gem: " + e.to_s
|
49
|
+
rescue Timeout::Error => e
|
50
|
+
logger = Logger.new("log/#{ENV['RAILS_ENV']}.log")
|
51
|
+
logger.error "ERROR eotb gem: " + e.to_s
|
52
|
+
end
|
53
|
+
res.body
|
54
|
+
end
|
55
|
+
|
56
|
+
METHODS = [:to_json, :to_hash, :inspect]
|
57
|
+
def self.value_format(value)
|
58
|
+
value.send METHODS.find { |m| m if value.respond_to? m }
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.hash_flatten(hash)
|
62
|
+
hash.inject({}) do |h, (k, v)|
|
63
|
+
if v.is_a?(Hash)
|
64
|
+
hash_flatten(v).each do |sk, sv|
|
65
|
+
h[[k] + sk] = sv
|
66
|
+
end
|
67
|
+
else
|
68
|
+
k = k ? [k] : []
|
69
|
+
h[k] = v
|
70
|
+
end
|
71
|
+
h
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.hash_format(hash, type)
|
76
|
+
if hash.is_a?(Hash)
|
77
|
+
h = hash_flatten(hash).map do |k, v|
|
78
|
+
key = k.map{ |e| "[#{e}]" }.join
|
79
|
+
"\"find[#{type}]#{key}\" => #{value_format(v)}"
|
80
|
+
|
81
|
+
end.join(', ')
|
82
|
+
else
|
83
|
+
h = "\"find[#{type}]\" => #{value_format(hash)}"
|
84
|
+
end
|
85
|
+
eval "{#{h.to_s}}"
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
end
|
@@ -7,8 +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 :login, :aliases => "-l", :type => :string, :desc => "Your Beholder app login"
|
11
|
-
class_option :password, :aliases => "-d", :type => :string, :desc => "Your Beholder app password"
|
12
10
|
|
13
11
|
def generator
|
14
12
|
ensure_parameters_was_set
|
@@ -30,13 +28,7 @@ class EotbGenerator < Rails::Generators::Base
|
|
30
28
|
def api_key_exp
|
31
29
|
"#{options[:api_key]}"
|
32
30
|
end
|
33
|
-
|
34
|
-
"#{options[:login]}"
|
35
|
-
end
|
36
|
-
def password_exp
|
37
|
-
"#{options[:password]}"
|
38
|
-
end
|
39
|
-
|
31
|
+
|
40
32
|
def generate_initializer
|
41
33
|
template 'initializer.rb', 'config/initializers/eotb.rb'
|
42
34
|
end
|
@@ -45,14 +37,8 @@ class EotbGenerator < Rails::Generators::Base
|
|
45
37
|
if !options[:api_key]
|
46
38
|
puts "Must pass --api-key='your_api_key' or -k 'your_api_key'"
|
47
39
|
exit
|
48
|
-
elsif !options[:email]
|
49
|
-
puts "Must pass --email='app_email' or -l 'app_email'"
|
50
|
-
exit
|
51
|
-
elsif !options[:password]
|
52
|
-
puts "Must pass --password='app_password' or -d 'app_password'"
|
53
|
-
exit
|
54
40
|
end
|
55
|
-
File.exists?('config/initializers/eotb.rb') && options[:api_key].empty?
|
41
|
+
File.exists?('config/initializers/eotb.rb') && options[:api_key].empty?
|
56
42
|
end
|
57
43
|
|
58
44
|
end
|
data/spec/eotb_spec.rb
CHANGED
@@ -2,7 +2,18 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
3
3
|
describe Eotb do
|
4
4
|
|
5
|
-
describe "
|
5
|
+
# describe "version" do
|
6
|
+
# it "configure with 3 parameters should return deprecation warning" do
|
7
|
+
# text = <<-EOF
|
8
|
+
# DEPRECATION WARNING
|
9
|
+
# Eotb.configure(api_key, events, host, port) -- method will be removed in eotb 0.5.17
|
10
|
+
# EOF
|
11
|
+
# Eotb.configure("test_api_key", 'login', 'passwords').should == text
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# end
|
15
|
+
|
16
|
+
describe "should format objects" do
|
6
17
|
before do
|
7
18
|
@@counter = 0
|
8
19
|
end
|
@@ -25,7 +36,7 @@ describe Eotb do
|
|
25
36
|
|
26
37
|
before(:each) do
|
27
38
|
@response = "200"
|
28
|
-
Eotb.configure("test_api_key"
|
39
|
+
Eotb.configure("test_api_key")
|
29
40
|
@@counter = 100
|
30
41
|
Net::HTTP.stub(:new) { Net::HTTP }
|
31
42
|
Net::HTTP.stub(:start) { Net::HTTP }
|
@@ -70,7 +81,7 @@ describe Eotb do
|
|
70
81
|
|
71
82
|
before(:each) do
|
72
83
|
@response = "200"
|
73
|
-
Eotb.configure("0"*40
|
84
|
+
Eotb.configure("0"*40)
|
74
85
|
@@counter = 96
|
75
86
|
Net::HTTP.stub(:new) { Net::HTTP }
|
76
87
|
Net::HTTP.stub(:start) { Net::HTTP }
|
@@ -82,7 +93,6 @@ describe Eotb do
|
|
82
93
|
Eotb.register_event("actor", "action", {:username => "John"}).should == @response
|
83
94
|
end
|
84
95
|
|
85
|
-
|
86
96
|
end
|
87
97
|
|
88
98
|
end
|
data/spec/report_spec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Eotb::Report do
|
4
|
+
|
5
|
+
describe "shoud format objects" do
|
6
|
+
before(:each) do
|
7
|
+
@response = "200"
|
8
|
+
Eotb.configure("test_api_key")
|
9
|
+
@@counter = 100
|
10
|
+
Net::HTTP.stub(:new) { Net::HTTP }
|
11
|
+
Net::HTTP.stub(:start) { Net::HTTP }
|
12
|
+
Net::HTTP.stub(:request) { "200" }
|
13
|
+
Eotb::Report.stub(:send) { [] }
|
14
|
+
JSON.stub(:parse) { [{:name => "Example"}] }
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should format with correct type " do
|
18
|
+
Eotb::Report.hash_format('2010-10-05', :created_on).should == {"find[created_on]" => "2010-10-05"}
|
19
|
+
end
|
20
|
+
|
21
|
+
it "find should return OpenStruct objects in an array" do
|
22
|
+
Eotb::Report.find({:name => "Example name"}).should == [OpenStruct.new({:name => "Example"})]
|
23
|
+
end
|
24
|
+
|
25
|
+
it "latest should return OpenStruct objects in an array" do
|
26
|
+
Eotb::Report.latest.should == [OpenStruct.new({:name => "Example"})]
|
27
|
+
end
|
28
|
+
|
29
|
+
it "latest_daily should return OpenStruct objects in an array" do
|
30
|
+
Eotb::Report.latest_daily.should == [OpenStruct.new({:name => "Example"})]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "latest_weekly should return OpenStruct objects in an array" do
|
34
|
+
Eotb::Report.latest_weekly.should == [OpenStruct.new({:name => "Example"})]
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'rubygems'
|
4
|
+
require 'activeresource'
|
3
5
|
require 'eotb'
|
6
|
+
require 'eotb/report'
|
4
7
|
require 'spec'
|
5
8
|
require 'spec/autorun'
|
6
9
|
Spec::Runner.configure do |config|
|
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: 47
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 18
|
10
|
+
version: 0.5.18
|
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-
|
18
|
+
date: 2010-11-23 00:00:00 +01:00
|
19
19
|
default_executable: eotb
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -90,10 +90,12 @@ files:
|
|
90
90
|
- generators/eotb/eotb_generator.rb
|
91
91
|
- generators/eotb/templates/initializer.rb
|
92
92
|
- lib/eotb.rb
|
93
|
+
- lib/eotb/report.rb
|
93
94
|
- lib/generators/eotb/USAGE
|
94
95
|
- lib/generators/eotb/eotb_generator.rb
|
95
96
|
- lib/timer.rb
|
96
97
|
- spec/eotb_spec.rb
|
98
|
+
- spec/report_spec.rb
|
97
99
|
- spec/spec_helper.rb
|
98
100
|
has_rdoc: true
|
99
101
|
homepage: http://github.com/Ragnarson/eotb_rails_plugin
|
@@ -132,3 +134,4 @@ summary: Rails plugin which allow you easily track and observe your apps
|
|
132
134
|
test_files:
|
133
135
|
- spec/spec_helper.rb
|
134
136
|
- spec/eotb_spec.rb
|
137
|
+
- spec/report_spec.rb
|