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 CHANGED
@@ -1,3 +1,6 @@
1
+ v0.7.5
2
+ :force_ts now default in QueryBuilder
3
+
1
4
  v0.7.4
2
5
  Eliminated default host for database. Must be specified in the configuration environment.
3
6
 
data/Manifest CHANGED
@@ -7,4 +7,6 @@ lib/base/db.rb
7
7
  lib/base/query_builder.rb
8
8
  lib/logworm.rb
9
9
  spec/base_spec.rb
10
+ spec/spec.opts
11
+ spec/spec_helper.rb
10
12
  tests/builder_test.rb
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'echoe'
2
- Echoe.new('logworm', '0.7.4') do |p|
2
+ Echoe.new('logworm', '0.7.5') do |p|
3
3
  p.description = "logworm logging tool"
4
4
  p.url = "http://www.logworm.com"
5
5
  p.author = "Pomelo, LLC"
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
- res = db_call(:get, "#{host_with_protocol}/")
66
+ db_call(:get, "#{host_with_protocol}/") || []
66
67
  end
67
68
 
68
69
  def query(table, cond)
69
- res = db_call(:post, "#{host_with_protocol}/queries", {:table => table, :query => cond})
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 DatabaseException if res.code.to_i == 404
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
@@ -21,6 +21,7 @@ module Logworm
21
21
 
22
22
  def initialize(options = {})
23
23
  @options = options
24
+ @options.merge(:force_ts => true) unless @options.include? :force_ts
24
25
  @query = build()
25
26
  end
26
27
 
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.4"
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-06}
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 support a call to get the list of tables" do
36
- @db.should have(0).tables
37
- log_details = {:value => 10, :_ts => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"), :_ts_utc => (Time.now.utc.to_f * 1000).to_i}
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 support a call to start a query"
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 get the results of a query"
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 raise DFGD if 404"
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 raise DFGD if 403"
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 DFGD if 400"
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
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format specdoc
3
+ --loadby mtime
4
+ --reverse
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'spec/autorun'
4
+ require 'spec/interop/test'
5
+ require 'webmock/rspec'
6
+
7
+ include WebMock
8
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 4
9
- version: 0.7.4
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-06 00:00:00 -04:00
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