Module: Harvest

Defined in:
lib/harvested.rb,
lib/harvest/user.rb,
lib/harvest/task.rb,
lib/harvest/base.rb,
lib/harvest/model.rb,
lib/harvest/client.rb,
lib/harvest/errors.rb,
lib/harvest/invoice.rb,
lib/harvest/contact.rb,
lib/harvest/expense.rb,
lib/harvest/project.rb,
lib/harvest/api/base.rb,
lib/harvest/api/time.rb,
lib/harvest/line_item.rb,
lib/harvest/timezones.rb,
lib/harvest/api/users.rb,
lib/harvest/api/tasks.rb,
lib/harvest/time_entry.rb,
lib/harvest/credentials.rb,
lib/harvest/api/reports.rb,
lib/harvest/api/clients.rb,
lib/harvest/api/account.rb,
lib/harvest/hardy_client.rb,
lib/harvest/api/projects.rb,
lib/harvest/api/invoices.rb,
lib/harvest/api/contacts.rb,
lib/harvest/api/expenses.rb,
lib/harvest/behavior/crud.rb,
lib/harvest/invoice_payment.rb,
lib/harvest/user_assignment.rb,
lib/harvest/task_assignment.rb,
lib/harvest/expense_category.rb,
lib/harvest/invoice_category.rb,
lib/harvest/rate_limit_status.rb,
lib/harvest/api/invoice_payments.rb,
lib/harvest/behavior/activatable.rb,
lib/harvest/api/user_assignments.rb,
lib/harvest/api/task_assignments.rb,
lib/harvest/api/invoice_categories.rb,
lib/harvest/api/expense_categories.rb

Defined Under Namespace

Modules: API, Behavior, Model, Timezones Classes: AuthenticationFailed, BadRequest, Base, Client, Contact, Credentials, Expense, ExpenseCategory, HTTPError, HardyClient, InformHarvest, InvalidCredentials, Invoice, InvoiceCategory, InvoicePayment, LineItem, NotFound, Project, RateLimitStatus, RateLimited, ServerError, Task, TaskAssignment, TimeEntry, Unavailable, User, UserAssignment

Constant Summary

VERSION =
File.read(File.expand_path(File.join(File.dirname(__FILE__), '..', 'VERSION'))).strip

Class Method Summary (collapse)

Class Method Details

+ (Harvest::Base) client(subdomain, username, password, options = {})

Creates a standard client that will raise all errors it encounters

Options

  • :ssl - Whether or not to use SSL when connecting to Harvest. This is dependent on whether your account supports it. Set to true by default

Examples

Harvest.client('mysubdomain', 'myusername', 'mypassword', :ssl => false)

Returns:



38
39
40
# File 'lib/harvested.rb', line 38

def client(subdomain, username, password, options = {})
  Harvest::Base.new(subdomain, username, password, options)
end

+ (Harvest::HardyClient) hardy_client(subdomain, username, password, options = {})

Creates a hardy client that will retry common HTTP errors it encounters and sleep() if it determines it is over your rate limit

Options

  • :ssl - Whether or not to use SSL when connecting to Harvest. This is dependent on whether your account supports it. Set to true by default

  • :retry - How many times the hardy client should retry errors. Set to 5 by default.

Examples

Harvest.hardy_client('mysubdomain', 'myusername', 'mypassword', :ssl => true, :retry => 3)

Errors

The hardy client will retry the following errors

  • Harvest::Unavailable

  • Harvest::InformHarvest

  • Net::HTTPError

  • Net::HTTPFatalError

  • Errno::ECONNRESET

Rate Limits

The hardy client will make as many requests as it can until it detects it has gone over the rate limit. Then it will sleep() for the how ever long it takes for the limit to reset. You can find more information about the Rate Limiting at www.getharvest.com/api

Returns:

See Also:



64
65
66
67
# File 'lib/harvested.rb', line 64

def hardy_client(subdomain, username, password, options = {})
  retries = options.delete(:retry)
  Harvest::HardyClient.new(client(subdomain, username, password, options), (retries || 5))
end