logworm 0.7.4 → 0.7.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/Manifest +2 -0
- data/Rakefile +1 -1
- data/lib/base/db.rb +6 -5
- data/lib/base/query_builder.rb +1 -0
- data/logworm.gemspec +3 -3
- data/spec/base_spec.rb +54 -10
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +8 -0
- metadata +5 -3
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
data/Rakefile
CHANGED
data/lib/base/db.rb
CHANGED
@@ -60,13 +60,14 @@ module Logworm
|
|
60
60
|
def self.example_url
|
61
61
|
self.make_url("db.logworm.com", "Ub5sOstT9w", "GZi0HciTVcoFHEoIZ7", "OzO71hEvWYDmncbf3C", "J7wq4X06MihhZgqDeB")
|
62
62
|
end
|
63
|
+
|
63
64
|
|
64
65
|
def tables()
|
65
|
-
|
66
|
+
db_call(:get, "#{host_with_protocol}/") || []
|
66
67
|
end
|
67
68
|
|
68
69
|
def query(table, cond)
|
69
|
-
|
70
|
+
db_call(:post, "#{host_with_protocol}/queries", {:table => table, :query => cond})
|
70
71
|
end
|
71
72
|
|
72
73
|
def results(uri)
|
@@ -87,10 +88,10 @@ module Logworm
|
|
87
88
|
rescue SocketError
|
88
89
|
raise DatabaseException
|
89
90
|
end
|
90
|
-
raise
|
91
|
+
raise InvalidQueryException.new("#{res.body}") if res.code.to_i == 400
|
92
|
+
raise ForbiddenAccessException if res.code.to_i == 403
|
93
|
+
raise DatabaseException if res.code.to_i == 404
|
91
94
|
raise DatabaseException.new("Server returned: #{res.body}") if res.code.to_i == 500
|
92
|
-
raise ForbiddenAccessException if res.code.to_i == 403
|
93
|
-
raise InvalidQueryException.new("#{res.body}") if res.code.to_i == 400
|
94
95
|
begin
|
95
96
|
JSON.parse(res.body)
|
96
97
|
rescue Exception => e
|
data/lib/base/query_builder.rb
CHANGED
data/logworm.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{logworm}
|
5
|
-
s.version = "0.7.
|
5
|
+
s.version = "0.7.5"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Pomelo, LLC"]
|
9
|
-
s.date = %q{2010-04-
|
9
|
+
s.date = %q{2010-04-22}
|
10
10
|
s.description = %q{logworm logging tool}
|
11
11
|
s.email = %q{schapira@pomelollc.com}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "README", "lib/base/config.rb", "lib/base/db.rb", "lib/base/query_builder.rb", "lib/logworm.rb"]
|
13
|
-
s.files = ["CHANGELOG", "Manifest", "README", "Rakefile", "lib/base/config.rb", "lib/base/db.rb", "lib/base/query_builder.rb", "lib/logworm.rb", "spec/base_spec.rb", "tests/builder_test.rb", "logworm.gemspec"]
|
13
|
+
s.files = ["CHANGELOG", "Manifest", "README", "Rakefile", "lib/base/config.rb", "lib/base/db.rb", "lib/base/query_builder.rb", "lib/logworm.rb", "spec/base_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tests/builder_test.rb", "logworm.gemspec"]
|
14
14
|
s.homepage = %q{http://www.logworm.com}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Logworm", "--main", "README"]
|
16
16
|
s.require_paths = ["lib"]
|
data/spec/base_spec.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'webmock'
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
5
|
+
|
1
6
|
$: << File.dirname(__FILE__) + '/../lib'
|
2
7
|
require 'logworm.rb'
|
3
8
|
|
@@ -28,25 +33,64 @@ end
|
|
28
33
|
|
29
34
|
describe Logworm::DB, " functioning" do
|
30
35
|
|
36
|
+
host = "http://localhost:9401"
|
37
|
+
|
31
38
|
before(:all) do
|
32
39
|
@db = Logworm::DB.new('logworm://a:b@localhost:9401/c/d/')
|
33
40
|
end
|
34
41
|
|
35
|
-
it "should
|
36
|
-
@db.
|
37
|
-
|
38
|
-
@db.batch_log([["log", log_details]])
|
39
|
-
@db.should have(1).tables
|
42
|
+
it "should offer a call to get the list of tables --> /" do
|
43
|
+
@db.should_receive(:db_call).with(:get, "#{host}/")
|
44
|
+
@db.tables
|
40
45
|
end
|
41
46
|
|
42
|
-
it "should
|
47
|
+
it "should just parse and return the results of the call to get tables" do
|
48
|
+
return_body = [
|
49
|
+
{"tablename" => "table1", "url" => "/table1", "last_write" => "2010-03-20 18:10:22", "rows" => 50},
|
50
|
+
{"tablename" => "table2", "url" => "/table1", "last_write" => "2010-03-20 18:10:22", "rows" => 50}]
|
51
|
+
stub_request(:get, "#{host}/").to_return(:body => return_body.to_json)
|
52
|
+
@db.tables.should == return_body
|
53
|
+
end
|
43
54
|
|
44
|
-
it "should support a call to
|
55
|
+
it "should support a call to start a query --> POST /queries" do
|
56
|
+
@db.should_receive(:db_call).with(:post, "#{host}/queries", {:table => "tbl1", :query => "a good query"})
|
57
|
+
@db.query("tbl1", "a good query")
|
58
|
+
end
|
45
59
|
|
46
|
-
it "should
|
60
|
+
it "should just parse and return the results of the call to query" do
|
61
|
+
return_body = {"id" => 10, "query" => "q", "self_uri" => "/queries/10", "results_uri" => "/queries/10/results"}
|
62
|
+
stub_request(:post, "#{host}/queries").with(:body => "table=table1&query=q").to_return(:body => return_body.to_json)
|
63
|
+
@db.query("table1", "q").should == return_body
|
64
|
+
end
|
47
65
|
|
48
|
-
it "should
|
66
|
+
it "should support a call to retrieve the results of a query --> GET /queries/10/results" do
|
67
|
+
@db.should_receive(:db_call).with(:get, "#{host}/queries/10/results")
|
68
|
+
@db.results("#{host}/queries/10/results") rescue Exception # Returns an error when trying to parse results
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should just parse and return the results of the call to retrieve results, but also add results field" do
|
72
|
+
results = [{"a" => 10, "b" => "2"}, {"a" => "x"}]
|
73
|
+
return_body = {"id" => 10, "execution_time" => "5",
|
74
|
+
"query_url" => "#{host}/queries/10", "results_url" => "#{host}/queries/10/results",
|
75
|
+
"results" => results.to_json}
|
76
|
+
stub_request(:get, "#{host}/queries/10/results").to_return(:body => return_body.to_json)
|
77
|
+
@db.results("#{host}/queries/10/results").should == return_body.merge("results" => results)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should raise ForbiddenAccessException if 403" do
|
81
|
+
stub_request(:get, "#{host}/").to_return(:status => 403)
|
82
|
+
lambda {@db.tables}.should raise_exception(Logworm::ForbiddenAccessException)
|
83
|
+
end
|
49
84
|
|
50
|
-
it "should raise
|
85
|
+
it "should raise InvalidQueryException if query is not valid" do
|
86
|
+
stub_request(:post, "#{host}/queries").to_return(:status => 400, :body => "Query error")
|
87
|
+
lambda {@db.query("tbl1", "bad query")}.should raise_exception(Logworm::InvalidQueryException)
|
88
|
+
end
|
51
89
|
|
90
|
+
it "should raise DatabaseException if response from server is not JSON" do
|
91
|
+
stub_request(:get, "#{host}/").to_return(:body => "blah")
|
92
|
+
lambda {@db.tables}.should raise_exception(Logworm::DatabaseException)
|
93
|
+
end
|
94
|
+
|
95
|
+
|
52
96
|
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 7
|
8
|
-
-
|
9
|
-
version: 0.7.
|
8
|
+
- 5
|
9
|
+
version: 0.7.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Pomelo, LLC
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-22 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -136,6 +136,8 @@ files:
|
|
136
136
|
- lib/base/query_builder.rb
|
137
137
|
- lib/logworm.rb
|
138
138
|
- spec/base_spec.rb
|
139
|
+
- spec/spec.opts
|
140
|
+
- spec/spec_helper.rb
|
139
141
|
- tests/builder_test.rb
|
140
142
|
- logworm.gemspec
|
141
143
|
has_rdoc: true
|