public
Fork of aiaio/harvest
Description: A ruby library wrapping (most of) the Harvest Api.
Homepage: http://aiaio.github.com/harvest
Clone URL: git://github.com/jeffrydegrande/harvest.git
aiaio (author)
Mon Jun 08 10:11:54 -0700 2009
commit  485940b1205549c8bea1e0a9c5175c2a51ad7282
tree    51f135a3067b9efeec795ac490f0e8f086e9b7fd
parent  ab5fe9ce3b3fbb92f797f39752fd88b59ac342d1
name age message
file HISTORY Tue Dec 23 07:55:59 -0800 2008 fixed typos; added missing hash method [aiaio]
file LICENSE Mon Dec 22 15:12:39 -0800 2008 initial commit [aiaio]
file README.rdoc Mon Jun 08 10:11:54 -0700 2009 Fixes for invoice support. [aiaio]
file Rakefile Mon Dec 22 15:12:39 -0800 2008 initial commit [aiaio]
file harvest.gemspec Mon Jun 08 10:11:54 -0700 2009 Fixes for invoice support. [aiaio]
directory lib/ Sun May 24 13:37:44 -0700 2009 Parsing line items, tests Added tests for Invo... [heisters]
directory test/ Mon Jun 08 10:11:54 -0700 2009 Fixes for invoice support. [aiaio]
README.rdoc

harvest

A ruby library wrapping (most of) the Harvest Api.

DESCRIPTION:

This library uses ActiveResource and activeresource_throttle to provide simple, reliable access to the Harvest Api. Good for building reporting scripts and simple apps.

Note that this library does not support the complete Harvest Api at this time. See Features/Issues below for details.

USAGE:

Creating a new harvest object:

All calls to the Harvest API will originate from a Harvest object. Initialize it like so:

  @harvest = Harvest(:email      => "joe@example.com",
                     :password   => "secret",
                     :sub_domain => "joeandcompany",
                     :headers    => {"User-Agent" => "MyCompany"})

The headers argument is optional. Use :ssl => true if your account requires HTTPS.

Clients

Index

  @harvest.clients.find(:all)

Show

  @harvest.clients.find(43235)

Create

  @client = @harvest.clients.new
  @client.attributes = {:name => "Company, LLC", :details => "New York, NY"}
  @client.save

Update

  @client.first_name = "Smith"
  @client.save

Destroy

  @client.destroy

Toggle (Active/Inactive)

  @client.toggle

Tasks

Index

  @harvest.tasks.find(:all)

Show

  @harvest.tasks.find(123)

Create

  @task = @harvest.tasks.new
  @task.attributes = {:name => "Meeting",   :billable_by_default => false,
                      :is_default => false, :default_hourly_rate => 100}
  @task.save

Update

  @task.name = "Client Meeting"
  @task.save

Destroy

  @task.destroy

People

Index

  @harvest.people.find(:all)

Show

  @harvest.people.find(123)

Projects

Index

  @harvest.projects.find(:all)

Show

  @harvest.projects.find(123)

Create

  @project = @harvest.projects.new
  @project.attributes = {:name => "Refactor", :active => true,
                         :bill_by => "None", :client_id => @client.id, }
  @project.save

Update

  @project.name = "Mega-Refactor"
  @project.save

Destroy

  @project.destroy

Toggle (Active/Inactive)

  @project.toggle

Invoices

Index

  @invoices = @harvest.invoices.find(:all)

Show

  @invoice = @harvest.invoices.find(1)

Find By Invoice Number

  @invoice = @harvest.invoices.find_by_number('200')

Create

  @invoice = @harvest.invoices.new
  @invoice.attributes = {:amount => '250.32', :client_id => @client.id}
  @invoice.save

Update

  @invoice.notes = "Pending payment"
  @invoice.save

Destroy

  @invoice.destroy

Return parsed csv line items

  @invoice.parsed_csv_line_items

User and Task Assignments

  @project.users.find(:all)
  @project.users.find(:first)

  @project.tasks.find(:all)
  @project.tasks.find(:first)

Reports

  @project.entries(:from => Time.now, :to => Time.now)
  @project.entries(:from => Time.now, :to => Time.now, :user_id => @person.id)

  @person.entries(:from => Time.now, :to => Time.now)
  @person.expenses(:from => Time.now, :to => Time.now)

FEATURES/PROBLEMS:

Supports most of the Harvest Api (www.getharvest.com/api).

Though RESTful, the Harvest Api does not entirely follow ActiveResource conventions. In order to support the complete API, certain customizations will be required. We welcome any contributions/modifications to help complete this Api.

The following Api features are incomplete due to incompatibilities with ActiveResource conventions (CRUD actions in parentheses):

  1. People (CUD)
  2. User & Task Assignments (CUD)
  3. Expenses (CUD)

In addition, the following have not been implemented at all due to time constraints:

  1. Time Tracking Api
  2. Invoices, Invoice Payments, Invoice Categories, and Invoice Messages

Expect a more complete library in the near future. Again, contributions are welcome.

TEST SUITE

This library includes a fairly thorough set of unit and integration tests. The unit tests can be run with the "rake" command.

The integration tests require a Harvest account. It is best to use a trial account when running these tests.

The credentials may be entered in test/test_helper.rb. To run the integration suite:

  rake test:integration

Note that the integration test structure is somewhat unorthodox, as it requires tests to run in a particular order. The main test file is test/integration/harvest_integration_test.rb. Examine this to see how the integration suite works.

REQUIREMENTS:

Requires active_resource >= 2.1 and activeresource_throttle >= 1.0.

active_resource_throttle should install automaticallt, but just in case you need to install manually:

  gem sources -a http://gems.github.com
  sudo gem install aiaio-active_resource_throttle

INSTALL:

  gem sources -a http://gems.github.com
  gem install aiaio-harvest