Class: Harvest::API::Projects

Inherits:
Base
  • Object
show all
Includes:
Behavior::Crud
Defined in:
lib/harvest/api/projects.rb

Instance Attribute Summary

Attributes inherited from Base

#credentials

Instance Method Summary collapse

Methods included from Behavior::Crud

#all, #create, #delete, #find, #update

Methods inherited from Base

api_model, #initialize

Constructor Details

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

Instance Method Details

#activate(project) ⇒ Harvest::Project

Activates the project. Does nothing if the project is already activated

Parameters:

Returns:



37
38
39
40
41
42
43
# File 'lib/harvest/api/projects.rb', line 37

def activate(project)
  if !project.active?
    request(:put, credentials, "#{api_model.api_path}/#{project.to_i}/toggle", :headers => {'Content-Length' => '0'})
    project.active = true
  end
  project
end

#create_task(project, task_name) ⇒ Harvest::Project

Creates and Assigns a task to the project

Examples

project = harvest.projects.find(401)
harvest.projects.create_task(project, 'Bottling Glue') # creates and assigns a task to the project

Returns:



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

def create_task(project, task_name)
  response = request(:post, credentials, "/projects/#{project.to_i}/task_assignments/add_with_create_new_task", :body => task_xml(task_name))
  id = response.headers["location"].first.match(/\/.*\/(\d+)\/.*\/(\d+)/)[1]
  find(id)
end

#deactivate(project) ⇒ Harvest::Project

Deactivates the project. Does nothing if the project is already deactivated

Parameters:

Returns:



25
26
27
28
29
30
31
# File 'lib/harvest/api/projects.rb', line 25

def deactivate(project)
  if project.active?
    request(:put, credentials, "#{api_model.api_path}/#{project.to_i}/toggle", :headers => {'Content-Length' => '0'})
    project.active = false
  end
  project
end