Skip to content

Commit

Permalink
Fixed issue caused by Harvest API change
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Mulholland committed Dec 17, 2009
1 parent 1fd7445 commit 1b5a311
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 15 deletions.
14 changes: 1 addition & 13 deletions README.rdoc
@@ -1,22 +1,10 @@
= Harvest Plugin For Redmine

==Overview

The object of this plugin is to sync timesheet data from {Harvest}[http://www.getharvest.com/] with individual projects within Redmine. When activated, this plugin will include a new "Harvest" tab and a "Harvest Time" section on the issue detail page with a summed up total of hours tied to a Redmine issue. Harvest time entries are tied to Redmine issues by included #ticket_no (ie #1234) in the text portion of the timesheet entry.

Currently, data is automatically imported for the past week's worth of data every time a user goes to the "Harvest" tab of a particular Redmine project.
= harvest

==Installation

- Install the plugin as described at: http://www.redmine.org/wiki/redmine/Plugins, according to the way you've obtained the plugin (this plugin does not require a plugin database migration)
- Install the {Harvestr}[http://github.com/squeejee/harvestr] plugin
- Restart Redmine
- Create a "config/harvest.yml" file with the following:

domain: <Harvest subdomain>
email: <Harvest email address>
password: <Harvest password>

==Global setup

Before you can actually use the plugin within the preferred projects some setup has to be done first.
Expand Down
Binary file added app/.DS_Store
Binary file not shown.
12 changes: 11 additions & 1 deletion app/models/harvest_time.rb
Expand Up @@ -40,7 +40,17 @@ def self.import_time(project)

ht = HarvestTime.find_or_create_by_id(entry.id)

ht.update_attributes(entry.to_hash)
# Key names from the Harvest API
harvest_keys = entry.to_hash.keys

# Column names of HarvestTime
harvest_time_keys = HarvestTime.column_names

# These keys are not in our db, so do not try to include with the insert / update
excess_keys = harvest_keys - harvest_time_keys
entry_hash = entry.to_hash.reject {|k,v| excess_keys.include?(k)}

ht.update_attributes(entry_hash)
end if harvest_entries

end
Expand Down
2 changes: 1 addition & 1 deletion init.rb
Expand Up @@ -15,7 +15,7 @@
name 'Redmine Harvest plugin'
author 'Jim Mulholland'
description 'This is a plugin for Redmine to import project timesheet data from Harvest.'
version '0.0.1'
version '0.0.2'

# This plugin contains settings
settings :default => {
Expand Down
31 changes: 31 additions & 0 deletions test/fixtures/harvest_project_entries_extra_attr.xml
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<day-entries type="array">
<day-entry>
<created-at type="datetime">2009-08-01T02:21:32Z</created-at>
<hours type="decimal">4.5</hours>
<id type="integer">14316565</id>
<is-billed type="boolean">false</is-billed>
<is-closed type="boolean">false</is-closed>
<notes>This is a test</notes>
<project-id type="integer">408960</project-id>
<spent-at type="date">2009-07-31</spent-at>
<task-id type="integer">333865</task-id>
<timer-started-at type="datetime" nil="true"></timer-started-at>
<user-id type="integer">86342</user-id>
<new-attr>New attribute added to api</new-attr>
</day-entry>
<day-entry>
<created-at type="datetime">2009-08-01T02:21:46Z</created-at>
<hours type="decimal">2.0</hours>
<id type="integer">14316569</id>
<is-billed type="boolean">false</is-billed>
<is-closed type="boolean">false</is-closed>
<notes>Ticket #1234 - Working on stuff</notes>
<project-id type="integer">408960</project-id>
<spent-at type="date">2009-07-31</spent-at>
<task-id type="integer">333867</task-id>
<timer-started-at type="datetime" nil="true"></timer-started-at>
<user-id type="integer">86342</user-id>
<new-attr>New attribute added to api</new-attr>
</day-entry>
</day-entries>
8 changes: 8 additions & 0 deletions test/unit/harvest_times_test.rb
Expand Up @@ -32,5 +32,13 @@ class HarvestTimesTest < ActiveSupport::TestCase
should "extract out integers prepended by # and store as issue_id" do
assert HarvestTime.find(14316569).issue_id == 1234
end

should "be successful if attributes are added to Harvest api" do
url = /http:\/\/test%40example.com:OU812@testing.harvestapp.com\/projects\/408960\/entries.*/
stub_get url, 'harvest_project_entries_extra_attr.xml'
project = Project.first
assert HarvestTime.import_time(project)
end

end
end

0 comments on commit 1b5a311

Please sign in to comment.