geoserver-publish 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +17 -0
- data/.travis.yml +5 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +15 -0
- data/README.md +81 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/config.yml +4 -0
- data/geoserver-publish.gemspec +31 -0
- data/lib/geoserver/publish.rb +46 -0
- data/lib/geoserver/publish/config.rb +17 -0
- data/lib/geoserver/publish/connection.rb +48 -0
- data/lib/geoserver/publish/coverage.rb +46 -0
- data/lib/geoserver/publish/coverage_store.rb +51 -0
- data/lib/geoserver/publish/create.rb +32 -0
- data/lib/geoserver/publish/data_store.rb +62 -0
- data/lib/geoserver/publish/feature_type.rb +48 -0
- data/lib/geoserver/publish/version.rb +6 -0
- data/lib/geoserver/publish/workspace.rb +43 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 408b468e3035e6cc2936098828b02cb17ea2229a
|
4
|
+
data.tar.gz: c59d7fc39f5e862432cb4ccdfd71809015cba20a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4cd36658509fda089b6320ae089f3218834149a506142ffe40e14332e3743534bfd63e59bd478d5491ad8b6bb782ebde8e6cca626d4a5a4827f3c2df986730cb
|
7
|
+
data.tar.gz: 7a3e123c4a42b73e7cd3272807996adc60b56df0f2f71f94c783654f012e01d39d35403325ce0fb6ec7ac5198ee333623ba14f55b4d742d470436fc3e2fde6e5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
inherit_gem:
|
2
|
+
bixby: bixby_default.yml
|
3
|
+
AllCops:
|
4
|
+
DisplayCopNames: true
|
5
|
+
TargetRubyVersion: 2.4
|
6
|
+
Exclude:
|
7
|
+
- 'bin/*'
|
8
|
+
Metrics/BlockLength:
|
9
|
+
Exclude:
|
10
|
+
- 'spec/**/*'
|
11
|
+
- '*.gemspec'
|
12
|
+
Naming/FileName:
|
13
|
+
Exclude:
|
14
|
+
- "geoserver-publish.gemspec"
|
15
|
+
- "Gemfile"
|
16
|
+
Style/StringLiterals:
|
17
|
+
EnforcedStyle: double_quotes
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
source "https://rubygems.org"
|
3
|
+
|
4
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
5
|
+
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
group :development, :test do
|
9
|
+
gem "bixby", require: false
|
10
|
+
gem "coveralls", require: false
|
11
|
+
gem "simplecov", require: false
|
12
|
+
end
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem "webmock"
|
16
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
##########################################################################
|
2
|
+
# Copyright 2018 Princeton University Library
|
3
|
+
# Additional copyright may be held by others, as reflected in the commit log
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# Geoserver::Publish
|
2
|
+
|
3
|
+
[![Build Status](https://img.shields.io/travis/pulibrary/geoserver-publish/master.svg)](https://travis-ci.org/pulibrary/geoserver-publish)
|
4
|
+
[![Coverage Status](https://img.shields.io/coveralls/pulibrary/geoserver-publish/master.svg)](https://coveralls.io/github/pulibrary/geoserver-publish?branch=master)
|
5
|
+
|
6
|
+
Simple client for publishing Shapefiles and GeoTIFFs to Geoserver.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'geoserver-publish'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install geoserver-publish
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
#### GeoTIFF
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
Geoserver::Publish.geotiff(workspace_name: "public", file_path: "file:///path/on/geoserver/raster.tif", id: "1234", title: "GeoTiff Title")
|
30
|
+
```
|
31
|
+
|
32
|
+
#### Shapefile
|
33
|
+
|
34
|
+
Because of a limitation in GeoServer, the layer id must be the same name as the shapefile without the extenstion. For example, if the file name is `1234.shp`, the id must be `1234`.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
Geoserver::Publish.shapefile(workspace_name: "public", file_path: "file:///path/on/geoserver/1234.shp", id: "1234", title: "Shapefile Title")
|
38
|
+
```
|
39
|
+
|
40
|
+
#### Deleting
|
41
|
+
|
42
|
+
```Ruby
|
43
|
+
Geoserver::Publish.delete_geotiff(workspace_name: "public", id: "1234")
|
44
|
+
Geoserver::Publish.delete_shapefile(workspace_name: "public", id: "1234")
|
45
|
+
```
|
46
|
+
|
47
|
+
## Configuration
|
48
|
+
|
49
|
+
#### Default
|
50
|
+
|
51
|
+
To use the default GeoServer connection parameters, no further configuration is needed. These are useful for testing and development against a local GeoServer instance.
|
52
|
+
|
53
|
+
- url: http://localhost:8080/geoserver/rest
|
54
|
+
- user: admin
|
55
|
+
- password: geoserver
|
56
|
+
|
57
|
+
|
58
|
+
#### Environment Variables
|
59
|
+
|
60
|
+
GeoServer Connection parameters can be set using environment variables.
|
61
|
+
|
62
|
+
- GEOSERVER_URL
|
63
|
+
- GEOSERVER_USER
|
64
|
+
- GEOSERVER_PASSWORD
|
65
|
+
|
66
|
+
#### Connection Object
|
67
|
+
|
68
|
+
A connection object can be instantiated with a parameter hash and passed into publishing methods.
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
new_conn = Geoserver::Publish::Connection.new({"url"=> "http://mygeoserver.com:8181/geoserver/rest", "user" => "admin_user", "password" => "supersecret"})
|
72
|
+
Geoserver::Publish.geotiff(connection: new_conn, workspace_name: "public", file_path: "file:///path/on/geoserver/raster.tif", id: "1234", title: "GeoTiff Title")
|
73
|
+
```
|
74
|
+
|
75
|
+
## Development
|
76
|
+
|
77
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pulibrary/geoserver-publish.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "geoserver/publish"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/config/config.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
# frozen_string_literal: true
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "geoserver/publish/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "geoserver-publish"
|
9
|
+
spec.version = Geoserver::Publish::VERSION
|
10
|
+
spec.authors = ["Eliot Jordan"]
|
11
|
+
spec.email = ["eliotj@princeton.edu"]
|
12
|
+
|
13
|
+
spec.summary = "Simple client for publishing Shapefiles and GeoTIFFs to Geoserver"
|
14
|
+
spec.description = "Simple client for publishing Shapefiles and GeoTIFFs to Geoserver"
|
15
|
+
spec.homepage = "https://github.com/pulibrary/geoserver-publish"
|
16
|
+
spec.license = "Apache-2.0"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "faraday"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "erb"
|
3
|
+
require "faraday"
|
4
|
+
require "json"
|
5
|
+
require "yaml"
|
6
|
+
|
7
|
+
module Geoserver
|
8
|
+
module Publish
|
9
|
+
require "geoserver/publish/config"
|
10
|
+
require "geoserver/publish/connection"
|
11
|
+
require "geoserver/publish/coverage"
|
12
|
+
require "geoserver/publish/coverage_store"
|
13
|
+
require "geoserver/publish/create"
|
14
|
+
require "geoserver/publish/data_store"
|
15
|
+
require "geoserver/publish/feature_type"
|
16
|
+
require "geoserver/publish/version"
|
17
|
+
require "geoserver/publish/workspace"
|
18
|
+
|
19
|
+
def self.delete_geotiff(workspace_name:, id:, connection: nil)
|
20
|
+
CoverageStore.new(connection).delete(workspace_name: workspace_name, coverage_store_name: id)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.delete_shapefile(workspace_name:, id:, connection: nil)
|
24
|
+
DataStore.new(connection).delete(workspace_name: workspace_name, data_store_name: id)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.geotiff(workspace_name:, file_path:, id:, title: nil, connection: nil)
|
28
|
+
create_workspace(workspace_name: workspace_name, connection: connection)
|
29
|
+
create_coverage_store(workspace_name: workspace_name, coverage_store_name: id, url: file_path, connection: connection)
|
30
|
+
create_coverage(workspace_name: workspace_name, coverage_store_name: id, coverage_name: id, title: title, connection: connection)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.shapefile(workspace_name:, file_path:, id:, title: nil, connection: nil)
|
34
|
+
create_workspace(workspace_name: workspace_name, connection: connection)
|
35
|
+
create_data_store(workspace_name: workspace_name, data_store_name: id, url: file_path, connection: connection)
|
36
|
+
create_feature_type(workspace_name: workspace_name, data_store_name: id, feature_type_name: id, title: title, connection: connection)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.root
|
40
|
+
Pathname.new(File.expand_path("../../../", __FILE__))
|
41
|
+
end
|
42
|
+
|
43
|
+
class Error < StandardError
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Geoserver
|
3
|
+
module Publish
|
4
|
+
def config
|
5
|
+
@config ||= config_yaml
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def config_yaml
|
11
|
+
file_path = File.join(Geoserver::Publish.root, "config", "config.yml")
|
12
|
+
YAML.safe_load(ERB.new(File.read(file_path)).result, [], [], true)
|
13
|
+
end
|
14
|
+
|
15
|
+
module_function :config, :config_yaml
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Geoserver
|
3
|
+
module Publish
|
4
|
+
class Connection
|
5
|
+
attr_reader :config
|
6
|
+
|
7
|
+
def initialize(config = nil)
|
8
|
+
@config = config || Geoserver::Publish.config["geoserver"]
|
9
|
+
end
|
10
|
+
|
11
|
+
def delete(path:)
|
12
|
+
response = faraday_connection.delete do |req|
|
13
|
+
req.url path
|
14
|
+
req.params["recurse"] = "true"
|
15
|
+
end
|
16
|
+
return true if response.status == 200
|
17
|
+
raise Geoserver::Publish::Error, response.reason_phrase
|
18
|
+
end
|
19
|
+
|
20
|
+
def get(path:)
|
21
|
+
response = faraday_connection.get do |req|
|
22
|
+
req.url path
|
23
|
+
req.headers["Accept"] = "application/json"
|
24
|
+
end
|
25
|
+
response.body if response.status == 200
|
26
|
+
end
|
27
|
+
|
28
|
+
def post(path:, payload:)
|
29
|
+
response = faraday_connection.post do |req|
|
30
|
+
req.url path
|
31
|
+
req.headers["Content-Type"] = "application/json"
|
32
|
+
req.body = payload
|
33
|
+
end
|
34
|
+
return true if response.status == 201 || response.status == 401
|
35
|
+
raise Geoserver::Publish::Error, response.reason_phrase
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def faraday_connection
|
41
|
+
Faraday.new(url: config["url"]) do |conn|
|
42
|
+
conn.adapter Faraday.default_adapter
|
43
|
+
conn.basic_auth(config["user"], config["password"]) if config["user"]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Geoserver
|
3
|
+
module Publish
|
4
|
+
class Coverage
|
5
|
+
attr_reader :connection
|
6
|
+
|
7
|
+
def initialize(conn = nil)
|
8
|
+
@connection = conn || Geoserver::Publish::Connection.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def delete(workspace_name:, coverage_store_name:, coverage_name:)
|
12
|
+
path = coverage_url(workspace_name: workspace_name, coverage_store_name: coverage_store_name, coverage_name: coverage_name)
|
13
|
+
connection.delete(path: path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def find(workspace_name:, coverage_store_name:, coverage_name:)
|
17
|
+
path = coverage_url(workspace_name: workspace_name, coverage_store_name: coverage_store_name, coverage_name: coverage_name)
|
18
|
+
out = connection.get(path: path)
|
19
|
+
JSON.parse(out) if out
|
20
|
+
end
|
21
|
+
|
22
|
+
def create(workspace_name:, coverage_store_name:, coverage_name:, title:)
|
23
|
+
path = coverage_url(workspace_name: workspace_name, coverage_store_name: coverage_store_name, coverage_name: nil)
|
24
|
+
payload = payload_new(coverage_name: coverage_name, title: title)
|
25
|
+
connection.post(path: path, payload: payload)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def coverage_url(workspace_name:, coverage_store_name:, coverage_name:)
|
31
|
+
last_path_component = coverage_name ? "/#{coverage_name}" : ""
|
32
|
+
"workspaces/#{workspace_name}/coveragestores/#{coverage_store_name}/coverages#{last_path_component}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def payload_new(coverage_name:, title:)
|
36
|
+
{
|
37
|
+
coverage: {
|
38
|
+
enabled: true,
|
39
|
+
name: coverage_name,
|
40
|
+
title: title
|
41
|
+
}
|
42
|
+
}.to_json
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Geoserver
|
3
|
+
module Publish
|
4
|
+
class CoverageStore
|
5
|
+
attr_reader :connection
|
6
|
+
|
7
|
+
def initialize(conn = nil)
|
8
|
+
@connection = conn || Geoserver::Publish::Connection.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def delete(workspace_name:, coverage_store_name:)
|
12
|
+
path = coverage_store_url(workspace_name: workspace_name, coverage_store_name: coverage_store_name)
|
13
|
+
connection.delete(path: path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def find(workspace_name:, coverage_store_name:)
|
17
|
+
path = coverage_store_url(workspace_name: workspace_name, coverage_store_name: coverage_store_name)
|
18
|
+
out = connection.get(path: path)
|
19
|
+
JSON.parse(out) if out
|
20
|
+
end
|
21
|
+
|
22
|
+
def create(workspace_name:, coverage_store_name:, url:, type: "GeoTIFF")
|
23
|
+
path = coverage_store_url(workspace_name: workspace_name, coverage_store_name: nil)
|
24
|
+
payload = payload_new(workspace_name: workspace_name, coverage_store_name: coverage_store_name, url: url, type: type)
|
25
|
+
connection.post(path: path, payload: payload)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def coverage_store_url(workspace_name:, coverage_store_name:)
|
31
|
+
last_path_component = coverage_store_name ? "/#{coverage_store_name}" : ""
|
32
|
+
"workspaces/#{workspace_name}/coveragestores#{last_path_component}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def payload_new(workspace_name:, coverage_store_name:, type:, url:)
|
36
|
+
{
|
37
|
+
coverageStore: {
|
38
|
+
name: coverage_store_name,
|
39
|
+
url: url,
|
40
|
+
enabled: true,
|
41
|
+
workspace: {
|
42
|
+
name: workspace_name
|
43
|
+
},
|
44
|
+
type: type,
|
45
|
+
_default: false
|
46
|
+
}
|
47
|
+
}.to_json
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Geoserver
|
4
|
+
module Publish
|
5
|
+
def create_coverage_store(workspace_name:, coverage_store_name:, url:, connection: nil)
|
6
|
+
return if CoverageStore.new(connection).find(workspace_name: workspace_name, coverage_store_name: coverage_store_name)
|
7
|
+
CoverageStore.new(connection).create(workspace_name: workspace_name, coverage_store_name: coverage_store_name, url: url)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_coverage(workspace_name:, coverage_store_name:, coverage_name:, title:, connection: nil)
|
11
|
+
return if Coverage.new(connection).find(workspace_name: workspace_name, coverage_store_name: coverage_store_name, coverage_name: coverage_name)
|
12
|
+
Coverage.new(connection).create(workspace_name: workspace_name, coverage_store_name: coverage_store_name, coverage_name: coverage_name, title: title)
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_data_store(workspace_name:, data_store_name:, url:, connection: nil)
|
16
|
+
return if DataStore.new(connection).find(workspace_name: workspace_name, data_store_name: data_store_name)
|
17
|
+
DataStore.new(connection).create(workspace_name: workspace_name, data_store_name: data_store_name, url: url)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_feature_type(workspace_name:, data_store_name:, feature_type_name:, title:, connection: nil)
|
21
|
+
return if FeatureType.new(connection).find(workspace_name: workspace_name, data_store_name: data_store_name, feature_type_name: feature_type_name)
|
22
|
+
FeatureType.new(connection).create(workspace_name: workspace_name, data_store_name: data_store_name, feature_type_name: feature_type_name, title: title)
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_workspace(workspace_name:, connection: nil)
|
26
|
+
return if Workspace.new(connection).find(workspace_name: workspace_name)
|
27
|
+
Workspace.new(connection).create(workspace_name: workspace_name)
|
28
|
+
end
|
29
|
+
|
30
|
+
module_function :create_coverage_store, :create_coverage, :create_data_store, :create_feature_type, :create_workspace
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Geoserver
|
3
|
+
module Publish
|
4
|
+
class DataStore
|
5
|
+
attr_reader :connection
|
6
|
+
|
7
|
+
def initialize(conn = nil)
|
8
|
+
@connection = conn || Geoserver::Publish::Connection.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def delete(workspace_name:, data_store_name:)
|
12
|
+
path = data_store_url(workspace_name: workspace_name, data_store_name: data_store_name)
|
13
|
+
connection.delete(path: path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def find(workspace_name:, data_store_name:)
|
17
|
+
path = data_store_url(workspace_name: workspace_name, data_store_name: data_store_name)
|
18
|
+
out = connection.get(path: path)
|
19
|
+
JSON.parse(out) if out
|
20
|
+
end
|
21
|
+
|
22
|
+
def create(workspace_name:, data_store_name:, url:)
|
23
|
+
path = data_store_url(workspace_name: workspace_name, data_store_name: nil)
|
24
|
+
payload = payload_new(data_store_name: data_store_name, url: url)
|
25
|
+
connection.post(path: path, payload: payload)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def data_store_url(workspace_name:, data_store_name:)
|
31
|
+
last_path_component = data_store_name ? "/#{data_store_name}" : ""
|
32
|
+
"workspaces/#{workspace_name}/datastores#{last_path_component}"
|
33
|
+
end
|
34
|
+
|
35
|
+
# rubocop:disable Metrics/MethodLength
|
36
|
+
def payload_new(data_store_name:, url:)
|
37
|
+
{
|
38
|
+
dataStore: {
|
39
|
+
name: data_store_name,
|
40
|
+
connectionParameters: {
|
41
|
+
entry: [
|
42
|
+
{
|
43
|
+
"@key": "create spatial index",
|
44
|
+
"$": "true"
|
45
|
+
},
|
46
|
+
{
|
47
|
+
"@key": "url",
|
48
|
+
"$": url
|
49
|
+
},
|
50
|
+
{
|
51
|
+
"@key": "cache and reuse memory maps",
|
52
|
+
"$": "false"
|
53
|
+
}
|
54
|
+
]
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}.to_json
|
58
|
+
end
|
59
|
+
# rubocop:enable Metrics/MethodLength
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Geoserver
|
3
|
+
module Publish
|
4
|
+
class FeatureType
|
5
|
+
attr_reader :connection
|
6
|
+
|
7
|
+
def initialize(conn = nil)
|
8
|
+
@connection = conn || Geoserver::Publish::Connection.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def delete(workspace_name:, data_store_name:, feature_type_name:)
|
12
|
+
path = feature_type_url(workspace_name: workspace_name, data_store_name: data_store_name, feature_type_name: feature_type_name)
|
13
|
+
connection.delete(path: path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def find(workspace_name:, data_store_name:, feature_type_name:)
|
17
|
+
path = feature_type_url(workspace_name: workspace_name, data_store_name: data_store_name, feature_type_name: feature_type_name)
|
18
|
+
out = connection.get(path: path)
|
19
|
+
JSON.parse(out) if out
|
20
|
+
end
|
21
|
+
|
22
|
+
# Feature type name must be the same name as the shapefile without the extenstion.
|
23
|
+
# E.g. If the file is `12345.shp`, then feature_type_name = "12345".
|
24
|
+
def create(workspace_name:, data_store_name:, feature_type_name:, title:)
|
25
|
+
path = feature_type_url(workspace_name: workspace_name, data_store_name: data_store_name, feature_type_name: nil)
|
26
|
+
payload = payload_new(feature_type_name: feature_type_name, title: title)
|
27
|
+
connection.post(path: path, payload: payload)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def feature_type_url(workspace_name:, data_store_name:, feature_type_name:)
|
33
|
+
last_path_component = feature_type_name ? "/#{feature_type_name}" : ""
|
34
|
+
"workspaces/#{workspace_name}/datastores/#{data_store_name}/featuretypes#{last_path_component}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def payload_new(feature_type_name:, title:)
|
38
|
+
{
|
39
|
+
featureType: {
|
40
|
+
name: feature_type_name,
|
41
|
+
title: title,
|
42
|
+
enabled: true
|
43
|
+
}
|
44
|
+
}.to_json
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Geoserver
|
3
|
+
module Publish
|
4
|
+
class Workspace
|
5
|
+
attr_reader :connection
|
6
|
+
|
7
|
+
def initialize(conn = nil)
|
8
|
+
@connection = conn || Geoserver::Publish::Connection.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def delete(workspace_name:)
|
12
|
+
path = workspace_url(workspace_name: workspace_name)
|
13
|
+
connection.delete(path: path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def find(workspace_name:)
|
17
|
+
path = workspace_url(workspace_name: workspace_name)
|
18
|
+
out = connection.get(path: path)
|
19
|
+
JSON.parse(out) if out
|
20
|
+
end
|
21
|
+
|
22
|
+
def create(workspace_name:)
|
23
|
+
path = workspace_url(workspace_name: nil)
|
24
|
+
connection.post(path: path, payload: payload_new(workspace_name: workspace_name))
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def payload_new(workspace_name:)
|
30
|
+
{
|
31
|
+
workspace: {
|
32
|
+
name: workspace_name
|
33
|
+
}
|
34
|
+
}.to_json
|
35
|
+
end
|
36
|
+
|
37
|
+
def workspace_url(workspace_name:)
|
38
|
+
last_path_component = workspace_name ? "/#{workspace_name}" : ""
|
39
|
+
"workspaces#{last_path_component}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geoserver-publish
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eliot Jordan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Simple client for publishing Shapefiles and GeoTIFFs to Geoserver
|
70
|
+
email:
|
71
|
+
- eliotj@princeton.edu
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".rubocop.yml"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- config/config.yml
|
87
|
+
- geoserver-publish.gemspec
|
88
|
+
- lib/geoserver/publish.rb
|
89
|
+
- lib/geoserver/publish/config.rb
|
90
|
+
- lib/geoserver/publish/connection.rb
|
91
|
+
- lib/geoserver/publish/coverage.rb
|
92
|
+
- lib/geoserver/publish/coverage_store.rb
|
93
|
+
- lib/geoserver/publish/create.rb
|
94
|
+
- lib/geoserver/publish/data_store.rb
|
95
|
+
- lib/geoserver/publish/feature_type.rb
|
96
|
+
- lib/geoserver/publish/version.rb
|
97
|
+
- lib/geoserver/publish/workspace.rb
|
98
|
+
homepage: https://github.com/pulibrary/geoserver-publish
|
99
|
+
licenses:
|
100
|
+
- Apache-2.0
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.6.14
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Simple client for publishing Shapefiles and GeoTIFFs to Geoserver
|
122
|
+
test_files: []
|