Module: Sync
- Included in:
- HarvestThings::Application
- Defined in:
- lib/harvestthings/sync.rb
Instance Method Summary collapse
-
#add_client_to_harvest(area_name) ⇒ Integer
add_client_to_harvest - saves a Things area_name as a Harvest client.
-
#add_project_to_harvest(proj_name, client) ⇒ Boolean
add_project_to_harvest - saves a Things project as a Harvest project.
-
#add_task_to_harvest(project_name, task_desc) ⇒ String
add_task_to_harvest - saves a Things task as a Harvest task.
-
#assign_task_assignment(new_task_id, project_name) ⇒ Integer
assign_task_assignment - assigns a newly created task to a Project in Harvest.
-
#things_projects_to_harvest ⇒ Array
things_projects_to_harvest - detemines which Things projects get sent to Harvest.
-
#things_tasks_to_harvest(project) ⇒ Array
things_tasks_to_harvest - determines which Things tasks get sent to Harvest.
Instance Method Details
#add_client_to_harvest(area_name) ⇒ Integer
add_client_to_harvest - saves a Things area_name as a Harvest client
92 93 94 95 96 97 98 99 100 |
# File 'lib/harvestthings/sync.rb', line 92 def add_client_to_harvest(area_name) str = <<EOS <client> <name>#{area_name}</name> <details></details> </client> EOS response = @harvest.request '/clients', :post, str end |
#add_project_to_harvest(proj_name, client) ⇒ Boolean
add_project_to_harvest - saves a Things project as a Harvest project
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/harvestthings/sync.rb', line 38 def add_project_to_harvest(proj_name, client) puts " adding #{proj_name} to Harvest" str = <<EOS <project> <name>#{proj_name}</name> <active type="boolean">true</active> <bill-by>none</bill-by> <client-id type="integer">#{client}</client-id> <code></code> <notes></notes> <budget type="decimal"></budget> <budget-by>none</budget-by> </project> EOS response = @harvest.request '/projects', :post, str end |
#add_task_to_harvest(project_name, task_desc) ⇒ String
add_task_to_harvest - saves a Things task as a Harvest task
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/harvestthings/sync.rb', line 60 def add_task_to_harvest(project_name, task_desc) str = <<EOS <task> <billable-by-default type="boolean">true</billable-by-default> <default-hourly-rate type="decimal"></default-hourly-rate> <is-default type="boolean">false</is-default> <name>#{task_desc}</name> </task> EOS response = @harvest.request '/tasks', :post, str new_task_location = response['Location'] new_task_id = new_task_location.gsub(/\/tasks\//, '') assign_task_assignment(new_task_id, project_name) end |
#assign_task_assignment(new_task_id, project_name) ⇒ Integer
assign_task_assignment - assigns a newly created task to a Project in Harvest
79 80 81 82 83 84 85 86 |
# File 'lib/harvestthings/sync.rb', line 79 def assign_task_assignment(new_task_id, project_name) str = <<EOS <task> <id type="integer">#{new_task_id}</id> </task> EOS response = @harvest.request "/projects/#{harvest_project_id(project_name)}/task_assignments", :post, str end |
#things_projects_to_harvest ⇒ Array
things_projects_to_harvest - detemines which Things projects get sent to Harvest
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/harvestthings/sync.rb', line 6 def things_projects_to_harvest define_harvest_projects define_harvest_tasks define_harvest_clients @things.projects.each do |project| print "." name = @things.project_title(project).downcase client = @things.project_area(project).downcase client_id = harvest_client?(client) ? harvest_client_id(client) : add_client_to_harvest(client) add_project_to_harvest(name, client_id) unless harvest_project?(name) things_tasks_to_harvest(project) end end |
#things_tasks_to_harvest(project) ⇒ Array
things_tasks_to_harvest - determines which Things tasks get sent to Harvest
24 25 26 27 28 29 30 31 |
# File 'lib/harvestthings/sync.rb', line 24 def things_tasks_to_harvest(project) @things.tasks(project).each do |task| unless @things.task_complete?(task) # complete in Things task_desc = @things.task_description(task).downcase add_task_to_harvest(@things.project_title(project).downcase, task_desc) unless harvest_task?(task_desc) # unless already exists in Harvest end end end |