Class: PurlFetcher::Client
- Inherits:
-
Object
- Object
- PurlFetcher::Client
- Includes:
- Singleton
- Defined in:
- lib/purl_fetcher/client.rb,
lib/purl_fetcher/client/mods.rb,
lib/purl_fetcher/client/publish.rb,
lib/purl_fetcher/client/version.rb,
lib/purl_fetcher/client/withdraw.rb,
lib/purl_fetcher/client/unpublish.rb,
lib/purl_fetcher/client/release_tags.rb
Defined Under Namespace
Classes: AlreadyDeletedResponseError, Error, Mods, NotFoundResponseError, Publish, Reader, ReleaseTags, ResponseError, Unpublish, Withdraw
Constant Summary collapse
- VERSION =
"2.1.2"
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
-
#delete(path:, params: {}) ⇒ Object
Send an DELETE request.
-
#post(path:, body:) ⇒ Object
Send an POST request.
-
#put(path:, body: nil, headers: {}) ⇒ Object
Send an PUT request.
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
48 49 50 |
# File 'lib/purl_fetcher/client.rb', line 48 def config @config end |
Class Method Details
.configure(url:, logger: default_logger, token: nil) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/purl_fetcher/client.rb', line 31 def configure(url:, logger: default_logger, token: nil) instance.config = Config.new( url: url, logger: logger, token: token ) instance end |
.default_logger ⇒ Object
41 42 43 |
# File 'lib/purl_fetcher/client.rb', line 41 def default_logger Logger.new($stdout) end |
Instance Method Details
#delete(path:, params: {}) ⇒ Object
Send an DELETE request
53 54 55 56 57 58 59 60 |
# File 'lib/purl_fetcher/client.rb', line 53 def delete(path:, params: {}) response = connection.delete(path, params) raise AlreadyDeletedResponseError, response.body if response.status == 409 raise "unexpected response: #{response.status} #{response.body}" unless response.success? response.body end |
#post(path:, body:) ⇒ Object
Send an POST request
65 66 67 68 69 70 71 72 73 |
# File 'lib/purl_fetcher/client.rb', line 65 def post(path:, body:) response = connection.post(path) do |request| request.body = body end raise "unexpected response: #{response.status} #{response.body}" unless response.success? response.body end |
#put(path:, body: nil, headers: {}) ⇒ Object
Send an PUT request
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/purl_fetcher/client.rb', line 79 def put(path:, body: nil, headers: {}) response = connection.put(path) do |request| request.body = body if body request.headers = default_headers.merge(headers) end raise "unexpected response: #{response.status} #{response.body}" unless response.success? response.body end |