Class: HttpResource::Resource
- Inherits:
-
Object
- Object
- HttpResource::Resource
- Defined in:
- lib/http_resource/resource.rb
Overview
Base for the REST resource proxies hung off a Client. A subclass maps one endpoint to its verbs in a bang/non-bang pair (Rails-style):
find(id) — returns the value object, or nil on an EXPECTED miss (404
not-found). Raises on the UNEXPECTED (validation, auth, 5xx,
timeout, connection).
find!(id) — raises an HttpResource::ApiError on ANY failure.
Sketch:
class Contacts < HttpResource::Resource
def find(id) = soft { find!(id) }
def find!(id)
data = @client.get(["api", "contacts", id])
data && Contact.from(data)
end
end
Instance Method Summary collapse
-
#initialize(client) ⇒ Resource
constructor
A new instance of Resource.
Constructor Details
#initialize(client) ⇒ Resource
Returns a new instance of Resource.
22 23 24 |
# File 'lib/http_resource/resource.rb', line 22 def initialize(client) @client = client end |