Class: Tenk::Users::UserResource

Inherits:
Object
  • Object
show all
Defined in:
lib/users/user_resource.rb

Overview

A base model for API resources nested under a user (/users/:id subresources)

Direct Known Subclasses

Assignments, TimeEntries

Instance Method Summary collapse

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

Returns:

  • (Hashie::Mash)

    the API response as a Hashie::Mash



34
35
36
# File 'lib/users/user_resource.rb', line 34

def create(user_id, options)
  @_client.post(resource_root(user_id), options)
end

#delete(user_id, id) ⇒ Hashie::Mash

The default implementation of delete requests for user subresources

Returns:

  • (Hashie::Mash)

    the API response as a Hashie::Mash



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

Returns:

  • (Hashie::Mash)

    the API response as a Hashie::Mash



28
29
30
# File 'lib/users/user_resource.rb', line 28

def get(user_id, id, options)
  @_client.get("#{resource_root(user_id)}/#{id}", options)
end

#list(user_id, options) ⇒ Hashie::Mash

The default implementation of list requests for user subresources

Returns:

  • (Hashie::Mash)

    the API response as a Hashie::Mash



22
23
24
# File 'lib/users/user_resource.rb', line 22

def list(user_id, options)
  @_client.get(resource_root(user_id), options)
end

#resource_root(user_id) ⇒ String

The base route for subresources under this user By default, infers this URL from the resource class name

Parameters:

  • user_id (Integer)

    the id of this user

Returns:

  • (String)

    the base URL for the subresource



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

Returns:

  • (Hashie::Mash)

    the API response as a Hashie::Mash



40
41
42
# File 'lib/users/user_resource.rb', line 40

def update(user_id, id, options)
  @_client.put("#{resource_root(user_id)}/#{id}", options)
end