spacialdb 0.0.2 → 0.0.3

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.
@@ -52,6 +52,27 @@ class Spacialdb::Client
52
52
  delete("/api/databases/#{name}", :accept => 'json').to_s
53
53
  end
54
54
 
55
+ # Get a list of layers on the database
56
+ def list_layers()
57
+ json_decode get("/api/layers", :accept => 'json').to_s
58
+ end
59
+
60
+ def show_layer(name)
61
+ json_decode get("/api/layers/#{name}", :accept => 'json').to_s
62
+ end
63
+
64
+ def add_layer(name, database, table_name=nil, srid=4326)
65
+ payload = {:name => name, :database => database}
66
+ payload.merge!(:table_name => table_name) unless table_name == nil
67
+ payload.merge!(:srid => srid) unless srid == 4326
68
+
69
+ post('/api/layers', payload, :accept => 'json')
70
+ end
71
+
72
+ def remove_layer(name)
73
+ delete("/api/layers/#{name}", :accept => 'json').to_s
74
+ end
75
+
55
76
  def get(uri, extra_headers={}) # :nodoc:
56
77
  process(:get, uri, extra_headers)
57
78
  end
@@ -105,8 +126,7 @@ class Spacialdb::Client
105
126
  def resource(uri, options={})
106
127
  RestClient.proxy = ENV['HTTP_PROXY'] || ENV['http_proxy']
107
128
  resource = RestClient::Resource.new(realize_full_uri(uri),
108
- :user => login,
109
- :password => password
129
+ options.merge(:user => login, :password => password)
110
130
  )
111
131
  resource
112
132
  end
@@ -103,7 +103,9 @@ module Spacialdb
103
103
  run "login"
104
104
  retry
105
105
  rescue RestClient::ResourceNotFound => e
106
- error extract_not_found(e.http_body)
106
+ error extract_error(e.http_body) {
107
+ e.http_body =~ /^[\w\s]+ not found$/ ? e.http_body : "Resource not found"
108
+ }
107
109
  rescue RestClient::Locked => e
108
110
  db = e.response.headers[:x_confirmation_required]
109
111
  message = extract_error(e.response.body)
@@ -127,12 +129,9 @@ module Spacialdb
127
129
  commands[cmd] || commands[command_aliases[cmd]]
128
130
  end
129
131
 
130
- def self.extract_not_found(body)
131
- body =~ /^[\w\s]+ not found$/ ? body : "Resource not found"
132
- end
133
-
134
132
  def self.extract_error(body)
135
- msg = parse_error_json(body) || parse_error_plain(body) || 'Internal server error'
133
+ default_error = block_given? ? yield : "Internal server error"
134
+ msg = parse_error_json(body) || parse_error_plain(body) || default_error
136
135
  msg.split("\n").map { |line| ' ! ' + line }.join("\n")
137
136
  end
138
137
 
@@ -1,5 +1,5 @@
1
1
  require "fileutils"
2
- require "spacialdb/client"
2
+ require "spacialdb/auth"
3
3
  require "spacialdb/command"
4
4
 
5
5
  class Spacialdb::Command::Base
@@ -1,6 +1,6 @@
1
1
  require "spacialdb/command/base"
2
2
 
3
- # manage databases (create, destroy)
3
+ # manage databases (list, create, destroy)
4
4
  #
5
5
  class Spacialdb::Command::Db < Spacialdb::Command::Base
6
6
 
@@ -5,7 +5,7 @@ require "spacialdb/deprecated/help"
5
5
  #
6
6
  class Spacialdb::Command::Help < Spacialdb::Command::Base
7
7
 
8
- PRIMARY_NAMESPACES = %w( auth db )
8
+ PRIMARY_NAMESPACES = %w( auth db layers )
9
9
 
10
10
  include Spacialdb::Deprecated::Help
11
11
 
@@ -0,0 +1,64 @@
1
+ require "spacialdb/command/base"
2
+
3
+ # manage layers (list, create, destroy)
4
+ #
5
+ class Spacialdb::Command::Layers < Spacialdb::Command::Base
6
+
7
+ # layers
8
+ #
9
+ # list your layers
10
+ #
11
+ def index
12
+ display spacialdb.list_layers.join("\n")
13
+ end
14
+
15
+ # layers:add NAME
16
+ #
17
+ # add a new layer to a database
18
+ #
19
+ # NAME should be the name of the layer.
20
+ #
21
+ # --db DATABASE # name of the database
22
+ # --tablename TABLENAME # name of the table in the database (defaults to NAME)
23
+ # --srid SRID # srid (defaults to 4326)
24
+ #
25
+ def add
26
+ tablename = extract_option('--tablename', nil)
27
+ srid = extract_option('--srid') || 4326
28
+ srid = srid.to_i rescue 4326
29
+
30
+ name = args.shift.downcase.strip rescue ''
31
+ raise(Spacialdb::Command::CommandFailed, "Invalid name.") if name == ''
32
+
33
+ database = extract_option('--db', nil)
34
+ raise(Spacialdb::Command::CommandFailed, "Invalid database.") if database == nil
35
+
36
+ display spacialdb.add_layer(name, database, tablename, srid)
37
+ end
38
+
39
+ # layers:info NAME
40
+ #
41
+ # show the layer info
42
+ #
43
+ # NAME should be the name of the layer.
44
+ #
45
+ def info
46
+ name = args.shift.downcase.strip rescue ''
47
+ raise(Spacialdb::Command::CommandFailed, "Invalid name.") if name == ''
48
+
49
+ display spacialdb.show_layer(name)
50
+ end
51
+
52
+ # layers:remove NAME
53
+ #
54
+ # remove a layer
55
+ #
56
+ # NAME should be the name of the layer.
57
+ #
58
+ def remove
59
+ name = args.shift.downcase.strip rescue ''
60
+ raise(Spacialdb::Command::CommandFailed, "Invalid name.") if name == ''
61
+
62
+ display spacialdb.remove_layer(name)
63
+ end
64
+ end
@@ -1,3 +1,3 @@
1
1
  module Spacialdb
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/vendor/okjson.rb CHANGED
@@ -28,7 +28,6 @@ require 'stringio'
28
28
  module OkJson
29
29
  extend self
30
30
 
31
- class ParserError < ::StandardError; end
32
31
 
33
32
  # Decodes a json document in string s and
34
33
  # returns the corresponding ruby value.
@@ -166,7 +165,7 @@ module OkJson
166
165
  end
167
166
 
168
167
 
169
- # Sans s and returns a list of json tokens,
168
+ # Scans s and returns a list of json tokens,
170
169
  # excluding white space (as defined in RFC 4627).
171
170
  def lex(s)
172
171
  ts = []
@@ -186,7 +185,7 @@ module OkJson
186
185
 
187
186
  # Scans the first token in s and
188
187
  # returns a 3-element list, or nil
189
- # if no such token exists.
188
+ # if s does not begin with a valid token.
190
189
  #
191
190
  # The first list element is one of
192
191
  # '{', '}', ':', ',', '[', ']',
@@ -579,4 +578,4 @@ module OkJson
579
578
  Spc = ' '[0]
580
579
  Unesc = {?b=>?\b, ?f=>?\f, ?n=>?\n, ?r=>?\r, ?t=>?\t}
581
580
  Hex = '0123456789abcdef'
582
- end
581
+ end
data/spec/auth_spec.rb CHANGED
@@ -5,7 +5,12 @@ module Spacialdb
5
5
  describe Auth do
6
6
  before do
7
7
  @cli = Spacialdb::Auth
8
+ @cli.stub!(:check)
9
+ @cli.stub!(:display)
10
+ @cli.stub!(:running_on_a_mac?).and_return(false)
8
11
  @cli.stub!(:set_credentials_permissions)
12
+ @cli.credentials = nil
13
+
9
14
  FakeFS.activate!
10
15
 
11
16
  File.open(@cli.credentials_file, "w") do |file|
data/spec/spec_helper.rb CHANGED
@@ -29,27 +29,25 @@ def execute(command_line)
29
29
  Spacialdb::Command.load
30
30
  object, method = Spacialdb::Command.prepare_run(command, args)
31
31
 
32
- $command_output = []
32
+ $command_output = ""
33
33
 
34
34
  def object.print(line=nil)
35
- last_line = $command_output.pop || ""
36
- last_line.concat(line)
37
- $command_output.push last_line
35
+ $command_output << "#{line}"
38
36
  end
39
37
 
40
38
  def object.puts(line=nil)
41
- $command_output << line
39
+ print("#{line}\n")
42
40
  end
43
41
 
44
42
  def object.error(line=nil)
45
- $command_output << line
43
+ puts(line)
46
44
  end
47
45
 
48
46
  object.send(method)
49
47
  end
50
48
 
51
49
  def output
52
- ($command_output || []).join("\n")
50
+ $command_output.gsub(/\n$/, '')
53
51
  end
54
52
 
55
53
  def run(command_line)
@@ -68,11 +66,26 @@ def capture_stdout(&block)
68
66
  fake.string
69
67
  end
70
68
 
69
+ def fail_command(message)
70
+ raise_error(Spacialdb::Command::CommandFailed, message)
71
+ end
72
+
73
+ def stub_core
74
+ stubbed_core = nil
75
+ any_instance_of(Spacialdb::Client) do |core|
76
+ stubbed_core = stub(core)
77
+ end
78
+ stub(Spacialdb::Auth).user.returns("user")
79
+ stub(Spacialdb::Auth).password.returns("pass")
80
+ stub(Spacialdb::Client).auth.returns("apikey01")
81
+ stubbed_core
82
+ end
83
+
71
84
  module Spacialdb::Helpers
72
85
  def display(msg, newline=true)
73
86
  end
74
87
  end
75
88
 
76
- Rspec.configure do |config|
89
+ RSpec.configure do |config|
77
90
  config.color_enabled = true
78
91
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: spacialdb
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Shoaib Burq
@@ -11,7 +11,8 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-06-11 00:00:00 Z
14
+ date: 2011-08-26 00:00:00 +02:00
15
+ default_executable:
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
17
18
  name: rest-client
@@ -24,7 +25,7 @@ dependencies:
24
25
  version: "0"
25
26
  type: :runtime
26
27
  version_requirements: *id001
27
- description: Ruby client for SpacialDB
28
+ description: Client gem for SpacialDB a cloud hosted Geospatial data store.
28
29
  email:
29
30
  - shoaib@nomad-labs.com
30
31
  - kashif@nomad-labs.com
@@ -43,6 +44,7 @@ files:
43
44
  - lib/spacialdb/command/base.rb
44
45
  - lib/spacialdb/command/db.rb
45
46
  - lib/spacialdb/command/help.rb
47
+ - lib/spacialdb/command/layers.rb
46
48
  - lib/spacialdb/command/version.rb
47
49
  - lib/spacialdb/command.rb
48
50
  - lib/spacialdb/deprecated/help.rb
@@ -59,7 +61,8 @@ files:
59
61
  - spec/command/version_spec.rb
60
62
  - spec/commmad_spec.rb
61
63
  - spec/spec_helper.rb
62
- homepage: http://spacialdb.com
64
+ has_rdoc: true
65
+ homepage: http://spacialdb.com/
63
66
  licenses: []
64
67
 
65
68
  post_install_message:
@@ -82,10 +85,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
85
  requirements: []
83
86
 
84
87
  rubyforge_project:
85
- rubygems_version: 1.8.5
88
+ rubygems_version: 1.6.2
86
89
  signing_key:
87
90
  specification_version: 3
88
- summary: Client gem for SpacialDB cloud hosting
91
+ summary: Ruby CLI for SpacialDB.
89
92
  test_files:
90
93
  - spec/auth_spec.rb
91
94
  - spec/client_spec.rb