class Harvest::API::Projects

Public Instance Methods

activate(project) click to toggle source

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

@param [Harvest::Project] project the project you want to activate @return [Harvest::Project] the activated project

# File lib/harvest/api/projects.rb, line 45
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
all(*) click to toggle source

Retrieves all projects. Note: this requires project manager or administrator authorization. @return [Harvest::Project]

Calls superclass method Harvest::Behavior::Crud#all
# File lib/harvest/api/projects.rb, line 10
def all(*)
  super
rescue NotFound => e
  raise NotFound.new(e.response, e.params, "Do you have sufficient privileges? If not, consider using time.trackable_projects instead.")
end
create_task(project, task_name) click to toggle source

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

@return [Harvest::Project]

# File lib/harvest/api/projects.rb, line 23
def create_task(project, task_name)
  response = request(:post, credentials, "/projects/#{project.to_i}/task_assignments/add_with_create_new_task", :body => {"task" => {"name" => task_name}}.to_json)
  id = response.headers["location"].match(/\/.*\/(\d+)\/.*\/(\d+)/)[1]
  find(id)
end
deactivate(project) click to toggle source

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

@param [Harvest::Project] project the project you want to deactivate @return [Harvest::Project] the deactivated project

# File lib/harvest/api/projects.rb, line 33
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