Class: Harvest::API::TaskAssignments

Inherits:
Base
  • Object
show all
Defined in:
lib/harvest/api/task_assignments.rb

Instance Attribute Summary

Attributes inherited from Base

#credentials

Instance Method Summary collapse

Methods inherited from Base

api_model, #initialize

Constructor Details

This class inherits a constructor from Harvest::API::Base

Instance Method Details

#all(project) ⇒ Object



5
6
7
8
# File 'lib/harvest/api/task_assignments.rb', line 5

def all(project)
  response = request(:get, credentials, "/projects/#{project.to_i}/task_assignments")
  Harvest::TaskAssignment.parse(response.parsed_response)
end

#create(task_assignment) ⇒ Object



15
16
17
18
19
20
# File 'lib/harvest/api/task_assignments.rb', line 15

def create(task_assignment)
  task_assignment = Harvest::TaskAssignment.wrap(task_assignment)
  response = request(:post, credentials, "/projects/#{task_assignment.project_id}/task_assignments", :body => task_assignment.task_as_json.to_json)
  id = response.headers["location"].match(/\/.*\/(\d+)\/.*\/(\d+)/)[2]
  find(task_assignment.project_id, id)
end

#delete(task_assignment) ⇒ Object



28
29
30
31
# File 'lib/harvest/api/task_assignments.rb', line 28

def delete(task_assignment)
  response = request(:delete, credentials, "/projects/#{task_assignment.project_id}/task_assignments/#{task_assignment.to_i}")
  task_assignment.id
end

#find(project, id) ⇒ Object



10
11
12
13
# File 'lib/harvest/api/task_assignments.rb', line 10

def find(project, id)
  response = request(:get, credentials, "/projects/#{project.to_i}/task_assignments/#{id}")
  Harvest::TaskAssignment.parse(response.parsed_response).first
end

#update(task_assignment) ⇒ Object



22
23
24
25
26
# File 'lib/harvest/api/task_assignments.rb', line 22

def update(task_assignment)
  task_assignment = Harvest::TaskAssignment.wrap(task_assignment)
  request(:put, credentials, "/projects/#{task_assignment.project_id}/task_assignments/#{task_assignment.to_i}", :body => task_assignment.to_json)
  find(task_assignment.project_id, task_assignment.id)
end