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, 500 => Errors::ServerError }.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.
15 16 17 18 |
# File 'lib/lurch/client.rb', line 15 def initialize(url, config) @url = url @config = config end |
Instance Method Details
#delete(path, payload = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/lurch/client.rb', line 36 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
20 21 22 23 |
# File 'lib/lurch/client.rb', line 20 def get(path) response = timed_request("GET", path) { client.get(path) } catch_errors(response).body end |
#patch(path, payload) ⇒ Object
31 32 33 34 |
# File 'lib/lurch/client.rb', line 31 def patch(path, payload) response = timed_request("PATCH", path, payload) { client.patch(path, payload) } catch_errors(response).body end |
#post(path, payload) ⇒ Object
25 26 27 28 29 |
# File 'lib/lurch/client.rb', line 25 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 |