Module: Harvest

Defined in:
lib/harvested.rb,
lib/harvest/task.rb,
lib/harvest/base.rb,
lib/harvest/user.rb,
lib/harvest/model.rb,
lib/harvest/errors.rb,
lib/harvest/client.rb,
lib/harvest/invoice.rb,
lib/harvest/version.rb,
lib/harvest/expense.rb,
lib/harvest/project.rb,
lib/harvest/contact.rb,
lib/harvest/api/time.rb,
lib/harvest/api/base.rb,
lib/harvest/line_item.rb,
lib/harvest/timezones.rb,
lib/harvest/api/tasks.rb,
lib/harvest/api/users.rb,
lib/harvest/time_entry.rb,
lib/harvest/api/account.rb,
lib/harvest/credentials.rb,
lib/harvest/api/reports.rb,
lib/harvest/api/clients.rb,
lib/harvest/api/invoices.rb,
lib/harvest/api/contacts.rb,
lib/harvest/hardy_client.rb,
lib/harvest/api/expenses.rb,
lib/harvest/api/projects.rb,
lib/harvest/behavior/crud.rb,
lib/harvest/task_assignment.rb,
lib/harvest/user_assignment.rb,
lib/harvest/invoice_payment.rb,
lib/harvest/expense_category.rb,
lib/harvest/invoice_category.rb,
lib/harvest/rate_limit_status.rb,
lib/harvest/trackable_project.rb,
lib/harvest/api/task_assignments.rb,
lib/harvest/api/invoice_payments.rb,
lib/harvest/api/user_assignments.rb,
lib/harvest/behavior/activatable.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, BasicAuthCredentials, Client, Contact, Expense, ExpenseCategory, HTTPError, HardyClient, InformHarvest, Invoice, InvoiceCategory, InvoicePayment, LineItem, NotFound, OAuthCredentials, Project, RateLimitStatus, RateLimited, ServerError, Task, TaskAssignment, TimeEntry, TrackableProject, Unavailable, User, UserAssignment

Constant Summary

VERSION =
"3.0.0.rc1"

Class Method Summary (collapse)

Class Method Details

+ (Harvest::Base) client(subdomain: nil, username: nil, password: nil, access_token: nil)

Creates a standard client that will raise all errors it encounters

Options

  • Basic Authentication

    • :subdomain - Your Harvest subdomain

    • :username - Your Harvest username

    • :password - Your Harvest password

  • OAuth

    • :access_token - An OAuth 2.0 access token

Examples

Harvest.client(subdomain: 'mysubdomain', username: 'myusername', password: 'mypassword')
Harvest.client(access_token: 'myaccesstoken')


44
45
46
# File 'lib/harvested.rb', line 44

def client(subdomain: nil, username: nil, password: nil, access_token: nil)
  Harvest::Base.new(subdomain: subdomain, username: username, password: password, access_token: access_token)
end

+ (Harvest::HardyClient) hardy_client(subdomain: nil, username: nil, password: nil, access_token: nil, retries: 5)

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

Options

  • Basic Authentication

    • :subdomain - Your Harvest subdomain

    • :username - Your Harvest username

    • :password - Your Harvest password

  • OAuth

    • :access_token - An OAuth 2.0 access token

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

Examples

Harvest.hardy_client(subdomain: 'mysubdomain', username: 'myusername', password: 'mypassword', retry: 3)

Harvest.hardy_client(access_token: 'myaccesstoken', retries: 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

See Also:



78
79
80
# File 'lib/harvested.rb', line 78

def hardy_client(subdomain: nil, username: nil, password: nil, access_token: nil, retries: 5)
  Harvest::HardyClient.new(client(subdomain: subdomain, username: username, password: password, access_token: access_token), retries)
end