class Geoserver::Publish::Style

Class for interacting with GeoServer Styles API. NOTE This assumes only the top level styles path /styles and does not work with workspace and layer based styles.

Attributes

connection[R]

Public Class Methods

new(conn = nil) click to toggle source
# File lib/geoserver/publish/style.rb, line 11
def initialize(conn = nil)
  @connection = conn || Geoserver::Publish::Connection.new
end

Public Instance Methods

create(style_name:, filename:, additional_payload: nil) click to toggle source

Create will update the GeoServer catalog, but not provide the style

# File lib/geoserver/publish/style.rb, line 28
def create(style_name:, filename:, additional_payload: nil)
  path = style_url(style_name: nil)
  payload = payload_new(style_name: style_name, filename: filename, payload: additional_payload)
  connection.post(path: path, payload: payload)
end
delete(style_name:) click to toggle source
# File lib/geoserver/publish/style.rb, line 15
def delete(style_name:)
  path = style_url(style_name: style_name)
  connection.delete(path: path)
end
find(style_name:) click to toggle source
# File lib/geoserver/publish/style.rb, line 20
def find(style_name:)
  path = style_url(style_name: style_name)
  out = connection.get(path: path)
  JSON.parse(out) if out
end
update(style_name:, filename:, payload:) click to toggle source

Update requires and uses the payload to upload an SLD

# File lib/geoserver/publish/style.rb, line 36
def update(style_name:, filename:, payload:)
  path = style_url(style_name: style_name)
  connection.put(path: path, payload: payload, content_type: "application/vnd.ogc.sld+xml")
end

Private Instance Methods

payload_new(style_name:, filename:, payload: nil) click to toggle source
# File lib/geoserver/publish/style.rb, line 48
def payload_new(style_name:, filename:, payload: nil)
  {
    style: {
      name: style_name,
      filename: filename,
    }.merge(payload.to_h)
  }.to_json
end
style_url(style_name:) click to toggle source
# File lib/geoserver/publish/style.rb, line 43
def style_url(style_name:)
  last_path_component = style_name ? "/#{style_name}" : ""
  "styles#{last_path_component}"
end