Class: Tenk::Projects::ProjectResource

Inherits:
Object
  • Object
show all
Defined in:
lib/projects/project_resource.rb

Overview

A base class for subresources under a project (within a /projects/:id url space)

Direct Known Subclasses

Assignments, BillRates, Phases, TimeEntries, Users

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ProjectResource

Returns a new instance of ProjectResource.



9
10
11
# File 'lib/projects/project_resource.rb', line 9

def initialize(client)
  @_client = client
end

Instance Method Details

#create(project_id, options) ⇒ Hashie::Mash

The default implementation of create requests for project subresources

Returns:

  • (Hashie::Mash)

    the API response as a Hashie::Mash



35
36
37
# File 'lib/projects/project_resource.rb', line 35

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

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

The default implementation of delete requests for project subresources

Returns:

  • (Hashie::Mash)

    the API response as a Hashie::Mash



47
48
49
# File 'lib/projects/project_resource.rb', line 47

def delete(project_id, id)
  @_client.delete("#{resource_root(project_id)}/#{id}")
end

#get(project_id, id, options) ⇒ Hashie::Mash

The default implementation of get requests for project subresources

Returns:

  • (Hashie::Mash)

    the API response as a Hashie::Mash



29
30
31
# File 'lib/projects/project_resource.rb', line 29

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

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

The default implementation of list requests for project subresources

Returns:

  • (Hashie::Mash)

    the API response as a Hashie::Mash



23
24
25
# File 'lib/projects/project_resource.rb', line 23

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

#resource_root(project_id) ⇒ String

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

Parameters:

  • project_id (Integer)

    the id of this project

Returns:

  • (String)

    the base URL for the subresource



17
18
19
# File 'lib/projects/project_resource.rb', line 17

def resource_root(project_id)
  "/projects/#{project_id}/#{self.class.name.demodulize.tableize}"
end

#update(project_id, id, options) ⇒ Hashie::Mash

The default implementation of update requests for project subresources

Returns:

  • (Hashie::Mash)

    the API response as a Hashie::Mash



41
42
43
# File 'lib/projects/project_resource.rb', line 41

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