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.
-
#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
#all, #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
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
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
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 |