geoserver-publish 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '038968f3cbde7d9a19944be64b05d0ff2d51b73d342b2828d80758389c3ee544'
4
- data.tar.gz: 2876f56b1401b5f0108fce1a429b99e94c860c029ae8da417bcb429ba7d179ad
3
+ metadata.gz: f15ea83139e028c59e3dc2d3d121524eee34cd5507edd3e1963cbf3e8815e885
4
+ data.tar.gz: 6c7d862f595948a9ad717029fbbb0cfa8fa8a6307104a7710456c28d480b1646
5
5
  SHA512:
6
- metadata.gz: 8506a643df04755609e2d7b02063ccde7ee22db949dd5a868267a4d029273c04afd82e633a34db2db1578bfe916ba72e0cfaa67c1eed0b08829668a7a7d7c3b8
7
- data.tar.gz: a73bc4fef84d232ea2463d32b0e747706e8048487ef5558254359e547f7feba0f95dbc0cd1761dc6e4318d347e5542380f4e6a6bc794c542215c752ffc4af3a6
6
+ metadata.gz: 7aeac6c7210f23f29cda6e4fc31cc07ab4dbcc21f412b8fdf13344e7a7c0ac74241f3c9595bba9c66297b04e25f05e7d01f3d924ad874cd59029ade2dc28abeb
7
+ data.tar.gz: 00d8b594bc21686173925af5b88e50787189cd1ba57583218c11f66cba91e46c41f68f2dd10cf1ff4421962df786f5719fa14930dd191dcda5b8729625c7b278
data/README.md CHANGED
@@ -44,6 +44,16 @@ Geoserver::Publish.delete_geotiff(workspace_name: "public", id: "1234")
44
44
  Geoserver::Publish.delete_shapefile(workspace_name: "public", id: "1234")
45
45
  ```
46
46
 
47
+ #### Styles
48
+
49
+ For users wanting to publish styles, this can be done using the [GeoServer styles API](https://docs.geoserver.org/latest/en/api/#1.0.0/styles.yaml).
50
+
51
+ ```ruby
52
+ Geoserver::Publish::Style.new.create(style_name: "raster_layer", filename: "raster_layer.sld")
53
+ sld = File.read("./spec/fixtures/files/payload/raster_layer.sld")
54
+ Geoserver::Publish::Style.new.update(style_name: "raster_layer", filename: "raster_layer.sld", payload: sld)
55
+ ```
56
+
47
57
  ## Configuration
48
58
 
49
59
  #### Default
@@ -13,6 +13,8 @@ module Geoserver
13
13
  require "geoserver/publish/create"
14
14
  require "geoserver/publish/data_store"
15
15
  require "geoserver/publish/feature_type"
16
+ require "geoserver/publish/layer"
17
+ require "geoserver/publish/style"
16
18
  require "geoserver/publish/version"
17
19
  require "geoserver/publish/workspace"
18
20
 
@@ -19,12 +19,18 @@ module Geoserver
19
19
  JSON.parse(out) if out
20
20
  end
21
21
 
22
- def create(workspace_name:, coverage_store_name:, coverage_name:, title:)
22
+ def create(workspace_name:, coverage_store_name:, coverage_name:, title:, additional_payload: nil)
23
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)
24
+ payload = payload_new(coverage_name: coverage_name, title: title, payload: additional_payload)
25
25
  connection.post(path: path, payload: payload)
26
26
  end
27
27
 
28
+ def update(workspace_name:, coverage_store_name:, coverage_name:, title:, additional_payload: nil)
29
+ path = coverage_url(workspace_name: workspace_name, coverage_store_name: coverage_store_name, coverage_name: coverage_name)
30
+ payload = payload_new(coverage_name: coverage_name, title: title, payload: additional_payload)
31
+ connection.put(path: path, payload: payload, content_type: "application/json")
32
+ end
33
+
28
34
  private
29
35
 
30
36
  def coverage_url(workspace_name:, coverage_store_name:, coverage_name:)
@@ -32,13 +38,13 @@ module Geoserver
32
38
  "workspaces/#{workspace_name}/coveragestores/#{coverage_store_name}/coverages#{last_path_component}"
33
39
  end
34
40
 
35
- def payload_new(coverage_name:, title:)
41
+ def payload_new(coverage_name:, title:, payload: nil)
36
42
  {
37
43
  coverage: {
38
44
  enabled: true,
39
45
  name: coverage_name,
40
46
  title: title
41
- }
47
+ }.merge(payload.to_h)
42
48
  }.to_json
43
49
  end
44
50
  end
@@ -19,12 +19,18 @@ module Geoserver
19
19
  JSON.parse(out) if out
20
20
  end
21
21
 
22
- def create(workspace_name:, coverage_store_name:, url:, type: "GeoTIFF")
22
+ def create(workspace_name:, coverage_store_name:, url:, type: "GeoTIFF", additional_payload: nil)
23
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)
24
+ payload = payload_new(workspace_name: workspace_name, coverage_store_name: coverage_store_name, url: url, type: type, payload: additional_payload)
25
25
  connection.post(path: path, payload: payload)
26
26
  end
27
27
 
28
+ def update(workspace_name:, coverage_store_name:, url:, type: "GeoTIFF", additional_payload: nil)
29
+ path = coverage_store_url(workspace_name: workspace_name, coverage_store_name: coverage_store_name)
30
+ payload = payload_new(workspace_name: workspace_name, coverage_store_name: coverage_store_name, url: url, type: type, payload: additional_payload)
31
+ connection.put(path: path, payload: payload, content_type: "application/json")
32
+ end
33
+
28
34
  private
29
35
 
30
36
  def coverage_store_url(workspace_name:, coverage_store_name:)
@@ -32,7 +38,7 @@ module Geoserver
32
38
  "workspaces/#{workspace_name}/coveragestores#{last_path_component}"
33
39
  end
34
40
 
35
- def payload_new(workspace_name:, coverage_store_name:, type:, url:)
41
+ def payload_new(workspace_name:, coverage_store_name:, type:, url:, payload:)
36
42
  {
37
43
  coverageStore: {
38
44
  name: coverage_store_name,
@@ -43,7 +49,7 @@ module Geoserver
43
49
  },
44
50
  type: type,
45
51
  _default: false
46
- }
52
+ }.merge(payload.to_h)
47
53
  }.to_json
48
54
  end
49
55
  end
@@ -21,12 +21,18 @@ module Geoserver
21
21
 
22
22
  # Feature type name must be the same name as the shapefile without the extenstion.
23
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:)
24
+ def create(workspace_name:, data_store_name:, feature_type_name:, title:, additional_payload: nil)
25
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)
26
+ payload = payload_new(feature_type_name: feature_type_name, title: title, payload: additional_payload)
27
27
  connection.post(path: path, payload: payload)
28
28
  end
29
29
 
30
+ def update(workspace_name:, data_store_name:, feature_type_name:, title:, additional_payload: nil)
31
+ path = feature_type_url(workspace_name: workspace_name, data_store_name: data_store_name, feature_type_name: feature_type_name)
32
+ payload = payload_new(feature_type_name: feature_type_name, title: title, payload: additional_payload)
33
+ connection.put(path: path, payload: payload, content_type: "application/json")
34
+ end
35
+
30
36
  private
31
37
 
32
38
  def feature_type_url(workspace_name:, data_store_name:, feature_type_name:)
@@ -34,13 +40,13 @@ module Geoserver
34
40
  "workspaces/#{workspace_name}/datastores/#{data_store_name}/featuretypes#{last_path_component}"
35
41
  end
36
42
 
37
- def payload_new(feature_type_name:, title:)
43
+ def payload_new(feature_type_name:, title:, payload:)
38
44
  {
39
45
  featureType: {
40
46
  name: feature_type_name,
41
47
  title: title,
42
48
  enabled: true
43
- }
49
+ }.merge(payload.to_h)
44
50
  }.to_json
45
51
  end
46
52
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+ module Geoserver
3
+ module Publish
4
+ class Layer
5
+ attr_reader :connection
6
+
7
+ def initialize(conn = nil)
8
+ @connection = conn || Geoserver::Publish::Connection.new
9
+ end
10
+
11
+ def delete(layer_name:, workspace_name: nil)
12
+ path = layer_url(layer_name: layer_name, workspace_name: nil)
13
+ connection.delete(path: path)
14
+ end
15
+
16
+ def find(layer_name:, workspace_name: nil)
17
+ path = layer_url(layer_name: layer_name, workspace_name: workspace_name)
18
+ out = connection.get(path: path)
19
+ JSON.parse(out) if out
20
+ end
21
+
22
+ def update(layer_name:, workspace_name: nil, additional_payload: nil)
23
+ path = layer_url(layer_name: layer_name, workspace_name: workspace_name)
24
+ payload = additional_payload.to_h.to_json
25
+ connection.put(path: path, payload: payload, content_type: "application/json")
26
+ end
27
+
28
+ private
29
+
30
+ def layer_url(layer_name:, workspace_name: nil)
31
+ path = []
32
+ path.push("workspaces", workspace_name) if workspace_name
33
+ path.push "layers"
34
+ path.push layer_name if layer_name
35
+ path.join("/")
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+ module Geoserver
3
+ module Publish
4
+ ##
5
+ # Class for interacting with GeoServer Styles API.
6
+ # **NOTE** This assumes only the top level styles path /styles and does not
7
+ # work with workspace and layer based styles.
8
+ class Style
9
+ attr_reader :connection
10
+
11
+ def initialize(conn = nil)
12
+ @connection = conn || Geoserver::Publish::Connection.new
13
+ end
14
+
15
+ def delete(style_name:)
16
+ path = style_url(style_name: style_name)
17
+ connection.delete(path: path)
18
+ end
19
+
20
+ def find(style_name:)
21
+ path = style_url(style_name: style_name)
22
+ out = connection.get(path: path)
23
+ JSON.parse(out) if out
24
+ end
25
+
26
+ ##
27
+ # Create will update the GeoServer catalog, but not provide the style
28
+ def create(style_name:, filename:, additional_payload: nil)
29
+ path = style_url(style_name: nil)
30
+ payload = payload_new(style_name: style_name, filename: filename, payload: additional_payload)
31
+ connection.post(path: path, payload: payload)
32
+ end
33
+
34
+ ##
35
+ # Update requires and uses the payload to upload an SLD
36
+ def update(style_name:, filename:, payload:)
37
+ path = style_url(style_name: style_name)
38
+ connection.put(path: path, payload: payload, content_type: "application/vnd.ogc.sld+xml")
39
+ end
40
+
41
+ private
42
+
43
+ def style_url(style_name:)
44
+ last_path_component = style_name ? "/#{style_name}" : ""
45
+ "styles#{last_path_component}"
46
+ end
47
+
48
+ def payload_new(style_name:, filename:, payload: nil)
49
+ {
50
+ style: {
51
+ name: style_name,
52
+ filename: filename,
53
+ }.merge(payload.to_h)
54
+ }.to_json
55
+ end
56
+ end
57
+ end
58
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Geoserver
3
3
  module Publish
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geoserver-publish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eliot Jordan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-17 00:00:00.000000000 Z
11
+ date: 2020-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -99,13 +99,15 @@ files:
99
99
  - lib/geoserver/publish/create.rb
100
100
  - lib/geoserver/publish/data_store.rb
101
101
  - lib/geoserver/publish/feature_type.rb
102
+ - lib/geoserver/publish/layer.rb
103
+ - lib/geoserver/publish/style.rb
102
104
  - lib/geoserver/publish/version.rb
103
105
  - lib/geoserver/publish/workspace.rb
104
106
  homepage: https://github.com/samvera-labs/geoserver-publish
105
107
  licenses:
106
108
  - Apache-2.0
107
109
  metadata: {}
108
- post_install_message:
110
+ post_install_message:
109
111
  rdoc_options: []
110
112
  require_paths:
111
113
  - lib
@@ -121,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
123
  version: '0'
122
124
  requirements: []
123
125
  rubygems_version: 3.0.3
124
- signing_key:
126
+ signing_key:
125
127
  specification_version: 4
126
128
  summary: Simple client for publishing Shapefiles and GeoTIFFs to Geoserver
127
129
  test_files: []