Class: Tenk::Users::UserResource
- Inherits:
-
Object
- Object
- Tenk::Users::UserResource
- Defined in:
- lib/users/user_resource.rb
Overview
A base model for API resources nested under a user (/users/:id subresources)
Direct Known Subclasses
Instance Method Summary collapse
-
#create(user_id, options) ⇒ Hashie::Mash
The default implementation of create requests for user subresources.
-
#delete(user_id, id) ⇒ Hashie::Mash
The default implementation of delete requests for user subresources.
-
#get(user_id, id, options) ⇒ Hashie::Mash
The default implementation of get requests for user subresources.
-
#initialize(client) ⇒ UserResource
constructor
A new instance of UserResource.
-
#list(user_id, options) ⇒ Hashie::Mash
The default implementation of list requests for user subresources.
-
#resource_root(user_id) ⇒ String
The base route for subresources under this user By default, infers this URL from the resource class name.
-
#update(user_id, id, options) ⇒ Hashie::Mash
The default implementation of update requests for user subresources.
Constructor Details
#initialize(client) ⇒ UserResource
Returns a new instance of UserResource.
8 9 10 |
# File 'lib/users/user_resource.rb', line 8 def initialize(client) @_client = client end |
Instance Method Details
#create(user_id, options) ⇒ Hashie::Mash
The default implementation of create requests for user subresources
34 35 36 |
# File 'lib/users/user_resource.rb', line 34 def create(user_id, ) @_client.post(resource_root(user_id), ) end |
#delete(user_id, id) ⇒ Hashie::Mash
The default implementation of delete requests for user subresources
46 47 48 |
# File 'lib/users/user_resource.rb', line 46 def delete(user_id, id) @_client.delete("#{resource_root(user_id)}/#{id}") end |
#get(user_id, id, options) ⇒ Hashie::Mash
The default implementation of get requests for user subresources
28 29 30 |
# File 'lib/users/user_resource.rb', line 28 def get(user_id, id, ) @_client.get("#{resource_root(user_id)}/#{id}", ) end |
#list(user_id, options) ⇒ Hashie::Mash
The default implementation of list requests for user subresources
22 23 24 |
# File 'lib/users/user_resource.rb', line 22 def list(user_id, ) @_client.get(resource_root(user_id), ) end |
#resource_root(user_id) ⇒ String
The base route for subresources under this user By default, infers this URL from the resource class name
16 17 18 |
# File 'lib/users/user_resource.rb', line 16 def resource_root(user_id) "/users/#{user_id}/#{self.class.name.demodulize.tableize}" end |
#update(user_id, id, options) ⇒ Hashie::Mash
The default implementation of update requests for user subresources
40 41 42 |
# File 'lib/users/user_resource.rb', line 40 def update(user_id, id, ) @_client.put("#{resource_root(user_id)}/#{id}", ) end |