Class: Routemaster::Resources::RestResource
- Inherits:
-
Object
- Object
- Routemaster::Resources::RestResource
- Defined in:
- lib/routemaster/resources/rest_resource.rb
Instance Method Summary collapse
- #create(params) ⇒ Object
- #destroy(id = nil) ⇒ Object
- #index(params: {}, filters: {}, enable_caching: false) ⇒ Object
-
#initialize(url, client: nil) ⇒ RestResource
constructor
A new instance of RestResource.
- #show(id = nil, enable_caching: true) ⇒ Object
- #update(id = nil, params) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(url, client: nil) ⇒ RestResource
Returns a new instance of RestResource.
10 11 12 13 |
# File 'lib/routemaster/resources/rest_resource.rb', line 10 def initialize(url, client: nil) @url_template = Addressable::Template.new(url) @client = client || Routemaster::APIClient.new end |
Instance Method Details
#create(params) ⇒ Object
15 16 17 |
# File 'lib/routemaster/resources/rest_resource.rb', line 15 def create(params) @client.post(, body: params) end |
#destroy(id = nil) ⇒ Object
36 37 38 39 |
# File 'lib/routemaster/resources/rest_resource.rb', line 36 def destroy(id=nil) # no response wrapping as DELETE is supposed to 204. @client.delete((id: id)) end |
#index(params: {}, filters: {}, enable_caching: false) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/routemaster/resources/rest_resource.rb', line 23 def index(params: {}, filters: {}, enable_caching: false) @client.get( , params: params.merge(filters), options: { enable_caching: enable_caching, response_class: Responses::HateoasEnumerableResponse } ) end |
#show(id = nil, enable_caching: true) ⇒ Object
19 20 21 |
# File 'lib/routemaster/resources/rest_resource.rb', line 19 def show(id=nil, enable_caching: true) @client.get((id: id), options: { enable_caching: enable_caching }) end |
#update(id = nil, params) ⇒ Object
32 33 34 |
# File 'lib/routemaster/resources/rest_resource.rb', line 32 def update(id=nil, params) @client.patch((id: id), body: params) end |
#url ⇒ Object
41 42 43 |
# File 'lib/routemaster/resources/rest_resource.rb', line 41 def url @url_template.pattern end |