Class: Geoserver::Publish::Connection
- Inherits:
-
Object
- Object
- Geoserver::Publish::Connection
- Defined in:
- lib/geoserver/publish/connection.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #delete(path:) ⇒ Object
- #get(path:) ⇒ Object
-
#initialize(config = nil) ⇒ Connection
constructor
A new instance of Connection.
- #post(path:, payload:, content_type: "application/json") ⇒ Object
- #put(path:, payload:, content_type:) ⇒ Object
Constructor Details
#initialize(config = nil) ⇒ Connection
Returns a new instance of Connection.
7 8 9 |
# File 'lib/geoserver/publish/connection.rb', line 7 def initialize(config = nil) @config = config || Geoserver::Publish.config["geoserver"] end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/geoserver/publish/connection.rb', line 5 def config @config end |
Instance Method Details
#delete(path:) ⇒ Object
11 12 13 14 15 16 17 18 |
# 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:) ⇒ Object
20 21 22 23 24 25 26 |
# 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") ⇒ Object
28 29 30 31 32 33 34 35 36 |
# 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:) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# 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 |