Class: Lurch::Client
- Inherits:
-
Object
- Object
- Lurch::Client
- Defined in:
- lib/lurch/client.rb
Constant Summary collapse
- AUTHORIZATION =
"Authorization".freeze
- STATUS_EXCEPTIONS =
{ 400 => Errors::BadRequest, 401 => Errors::Unauthorized, 403 => Errors::Forbidden, 404 => Errors::NotFound, 409 => Errors::Conflict, 422 => Errors::UnprocessableEntity }.freeze
Instance Method Summary collapse
- #delete(path, payload = nil) ⇒ Object
- #get(path) ⇒ Object
-
#initialize(url, config) ⇒ Client
constructor
A new instance of Client.
- #patch(path, payload) ⇒ Object
- #post(path, payload) ⇒ Object
Constructor Details
#initialize(url, config) ⇒ Client
Returns a new instance of Client.
14 15 16 17 |
# File 'lib/lurch/client.rb', line 14 def initialize(url, config) @url = url @config = config end |
Instance Method Details
#delete(path, payload = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/lurch/client.rb', line 35 def delete(path, payload = nil) response = timed_request("DELETE", path, payload) do client.delete do |req| req.url path req.body = payload unless payload.nil? end end catch_errors(response).body end |
#get(path) ⇒ Object
19 20 21 22 |
# File 'lib/lurch/client.rb', line 19 def get(path) response = timed_request("GET", path) { client.get(path) } catch_errors(response).body end |
#patch(path, payload) ⇒ Object
30 31 32 33 |
# File 'lib/lurch/client.rb', line 30 def patch(path, payload) response = timed_request("PATCH", path, payload) { client.patch(path, payload) } catch_errors(response).body end |
#post(path, payload) ⇒ Object
24 25 26 27 28 |
# File 'lib/lurch/client.rb', line 24 def post(path, payload) response = timed_request("POST", path, payload) { client.post(path, payload) } # TODO: if 204 is returned, use payload as return body (http://jsonapi.org/format/#crud-creating-responses-204) catch_errors(response).body end |