Class: Harvest::API::Projects
- Includes:
- Behavior::Crud
- Defined in:
- lib/harvest/api/projects.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#activate(project) ⇒ Harvest::Project
Activates the project.
-
#all ⇒ Harvest::Project
Retrieves all projects.
-
#create_task(project, task_name) ⇒ Harvest::Project
Creates and Assigns a task to the project.
-
#deactivate(project) ⇒ Harvest::Project
Deactivates the project.
Methods included from Behavior::Crud
#create, #delete, #find, #update
Methods inherited from Base
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
45 46 47 48 49 50 51 |
# 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 ⇒ Harvest::Project
Retrieves all projects. Note: this requires project manager or administrator authorization.
10 11 12 13 14 |
# 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) ⇒ 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
23 24 25 26 27 |
# 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) ⇒ Harvest::Project
Deactivates the project. Does nothing if the project is already deactivated
33 34 35 36 37 38 39 |
# 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 |