class Geoserver::Publish::Connection
Attributes
config[R]
Public Class Methods
new(config = nil)
click to toggle source
# File lib/geoserver/publish/connection.rb, line 7 def initialize(config = nil) @config = config || Geoserver::Publish.config["geoserver"] end
Public Instance Methods
delete(path:)
click to toggle source
# File lib/geoserver/publish/connection.rb, line 11 def delete(path:) response = faraday_connection.delete do |req| req.url path req.params["recurse"] = "true" end return true if response.status == 200 raise Geoserver::Publish::Error, response.reason_phrase end
get(path:)
click to toggle source
# File lib/geoserver/publish/connection.rb, line 20 def get(path:) response = faraday_connection.get do |req| req.url path req.headers["Accept"] = "application/json" end response.body if response.status == 200 end
post(path:, payload:, content_type: "application/json")
click to toggle source
# File lib/geoserver/publish/connection.rb, line 28 def post(path:, payload:, content_type: "application/json") response = faraday_connection.post do |req| req.url path req.headers["Content-Type"] = content_type req.body = payload end return true if response.status == 201 || response.status == 401 || response.status == 200 raise Geoserver::Publish::Error, response.reason_phrase end
put(path:, payload:, content_type:)
click to toggle source
# File lib/geoserver/publish/connection.rb, line 38 def put(path:, payload:, content_type:) response = faraday_connection.put do |req| req.url path req.headers['Content-Type'] = content_type req.body = payload end return true if response.status == 201 || response.status == 200 raise Geoserver::Publish::Error, response.reason_phrase end
Private Instance Methods
faraday_connection()
click to toggle source
# File lib/geoserver/publish/connection.rb, line 51 def faraday_connection Faraday.new(url: config["url"]) do |conn| conn.adapter Faraday.default_adapter conn.basic_auth(config["user"], config["password"]) if config["user"] end end