Module: Harvest

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

Defined Under Namespace

Modules: API, Behavior, Model, Timezones Classes: Account, AuthenticationFailed, BadRequest, Base, BasicAuthCredentials, Client, Company, Contact, Expense, ExpenseCategory, HTTPError, HardyClient, InformHarvest, Invoice, InvoiceCategory, InvoiceMessage, InvoicePayment, LineItem, NotFound, OAuthCredentials, Project, RateLimited, Receipt, ServerError, Task, TaskAssignment, TimeEntry, Unavailable, User, UserAssignment

Constant Summary collapse

VERSION =
'5.0.3'

Class Method Summary collapse

Class Method Details

.client(access_token: nil, account_id: nil, client_id: nil) ⇒ Harvest::Base

Creates a standard client that will raise all errors it encounters

Options

  • Basic Authentication V2

    • :access_token - Your Harvest access_token

    • :account_id - Your Harvest account_id

    • :client_id - An OAuth 2.0 access token

Examples

Harvest.client(access_token: 'token', account_id: '123')
Harvest.client(access_token: 'myaccesstoken', client_id: '1')

Returns:



50
51
52
53
# File 'lib/harvested2.rb', line 50

def client(access_token: nil, account_id: nil, client_id: nil)
  Harvest::Base.new(access_token: access_token, account_id: ,
    client_id: client_id)
end

.hardy_client(access_token: nil, account_id: nil, client_id: nil, retries: 5) ⇒ Harvest::HardyClient

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

    • :access_token - Your Harvest access_token

    • :account_id - Your Harvest account_id

    • :client_id - 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(access_token: 'token', account_id: '123', retry: 3)

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

Returns:

See Also:



88
89
90
91
92
93
94
# File 'lib/harvested2.rb', line 88

def hardy_client(access_token: nil, account_id: nil, client_id: nil, retries: 5)
  Harvest::HardyClient.new(client(
    access_token: access_token,
    account_id: ,
    client_id: client_id),
    retries)
end