Class: Harvest::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/harvest/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token: nil, account_id: nil, client_id: nil) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
12
13
14
15
# File 'lib/harvest/base.rb', line 6

def initialize(access_token: nil, account_id: nil, client_id: nil)
  @credentials = if access_token && 
    BasicAuthCredentials.new(access_token: access_token,
      account_id: )
  elsif access_token
    OAuthCredentials.new(access_token: access_token, client_id: client_id)
  else
    fail 'You must provide either :access_token and :account_id or an oauth :client_id'
  end
end

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



3
4
5
# File 'lib/harvest/base.rb', line 3

def credentials
  @credentials
end

#requestObject (readonly)

Returns the value of attribute request.



3
4
5
# File 'lib/harvest/base.rb', line 3

def request
  @request
end

Instance Method Details

#accountHarvest::API::Account

All API actions surrounding accounts

Examples

harvest..rate_limit_status # Returns a Harvest::RateLimitStatus


23
24
25
# File 'lib/harvest/base.rb', line 23

def 
  @account ||= Harvest::API::Account.new(credentials)
end

#clientsHarvest::API::Clients

All API Actions surrounding Clients

Examples

harvest.clients.all() # Returns all clients in the system

harvest.clients.find(100) # Returns the client with id = 100

client = Harvest::Client.new(:name => 'SuprCorp')
saved_client = harvest.clients.create(client) # returns a saved version of Harvest::Client

client = harvest.clients.find(205)
client.name = 'SuprCorp LTD.'
updated_client = harvest.clients.update(client) # returns an updated version of Harvest::Client

client = harvest.clients.find(205)
harvest.clients.delete(client) # returns 205

client = harvest.clients.find(301)
deactivated_client = harvest.clients.deactivate(client) # returns an updated deactivated client
activated_client = harvest.clients.activate(client) # returns an updated activated client


51
52
53
# File 'lib/harvest/base.rb', line 51

def clients
  @clients ||= Harvest::API::Clients.new(credentials)
end

#companyObject

base_uri | string | The Harvest URL for the company. full_domain | string | The Harvest domain for the company. name | string | The name of the company. is_active | boolean | Whether the company is active or archived. week_start_day | string | The week day used as the start of the week. Returns one of: Saturday, Sunday, or Monday. wants_timestamp_timers | boolean | Whether time is tracked via duration or start and end times. time_format | string | The format used to display time in Harvest. Returns either decimal or hours_minutes. plan_type | string | The type of plan the company is on. Examples: trial, free, or simple-v4 clock | string | Used to represent whether the company is using a 12-hour or 24-hour clock. Returns either 12h or 24h. decimal_symbol | string | Symbol used when formatting decimals. thousands_separator | string | Separator used when formatting numbers. color_scheme | string | The color scheme being used in the Harvest web client. expense_feature | boolean| Whether the expense module is enabled. invoice_feature | boolean | Whether the invoice module is enabled. estimate_feature | boolean | Whether the estimate module is enabled. approval_feature | boolean | Whether the approval module is enabled.



329
330
331
# File 'lib/harvest/base.rb', line 329

def company
  @company ||= Harvest::API::Company.new(credentials)
end

#contactsHarvest::API::Contacts

All API Actions surrounding Client Contacts

Examples

harvest.contacts.all() # Returns all contacts in the system
harvest.contacts.all(10) # Returns all contacts for the client id=10 in the system

harvest.contacts.find(100) # Returns the contact with id = 100

contact = Harvest::Contact.new(:first_name => 'Jane', :last_name => 'Doe', :client_id => 10)
saved_contact = harvest.contacts.create(contact) # returns a saved version of Harvest::Contact

contact = harvest.contacts.find(205)
contact.first_name = 'Jilly'
updated_contact = harvest.contacts.update(contact) # returns an updated version of Harvest::Contact

contact = harvest.contacts.find(205)
harvest.contacts.delete(contact) # returns 205


75
76
77
# File 'lib/harvest/base.rb', line 75

def contacts
  @contacts ||= Harvest::API::Contacts.new(credentials)
end

#expense_categoriesHarvest::API::ExpenseCategories

All API Actions surrounding managing expense categories

Examples

harvest.expense_categories.all() # Returns all expense categories in the system

harvest.expense_categories.find(100) # Returns the expense category with id = 100

category = Harvest::ExpenseCategory.new(:name => 'Mileage', :unit_price => 0.485)
saved_category = harvest.expense_categories.create(category) # returns a saved version of Harvest::ExpenseCategory

category = harvest.clients.find(205)
category.name = 'Travel'
updated_category = harvest.expense_categories.update(category) # returns an updated version of Harvest::ExpenseCategory

category = harvest.expense_categories.find(205)
harvest.expense_categories.delete(category) # returns 205


239
240
241
# File 'lib/harvest/base.rb', line 239

def expense_categories
  @expense_categories ||= Harvest::API::ExpenseCategories.new(credentials)
end

#expensesObject

All API Actions surrounding expenses

Examples

harvest.expenses.all() # Returns all expenses for the current week
harvest.expenses.all(Time.parse('11/12/2009')) # returns all expenses for the week of 11/12/2009

harvest.expenses.find(100) # Returns the expense with id = 100


250
251
252
# File 'lib/harvest/base.rb', line 250

def expenses
  @expenses ||= Harvest::API::Expenses.new(credentials)
end

#invoice_categoriesObject



262
263
264
# File 'lib/harvest/base.rb', line 262

def invoice_categories
  @invoice_categories ||= Harvest::API::InvoiceCategories.new(credentials)
end

#invoice_messagesObject

id | integer | Unique ID for the message. sent_by | string | Name of the user that created the message. sent_by_email | string | Email of the user that created the message. sent_from | string | Name of the user that the message was sent from. sent_from_email | string | Email of the user that message was sent from. recipients | array | Array of invoice message recipients. subject | string | The message subject. body | string | The message body. include_link_to_client_invoice | boolean | Whether to include a link to the client invoice in the message body. Not used when thank_you is true. attach_pdf | boolean | Whether to attach the invoice PDF to the message email. send_me_a_copy | boolean | Whether to email a copy of the message to the current user. thank_you | boolean | Whether this is a thank you message. event_type | string | The type of invoice event that occurred with the message: send, close, draft, re-open, or view. reminder | boolean | Whether this is a reminder message. send_reminder_on | date | The date the reminder email will be sent. created_at | datetime | Date and time the message was created. updated_at | datetime | Date and time the message was last updated.



309
310
311
# File 'lib/harvest/base.rb', line 309

def invoice_messages
  @invoice_messages ||= Harvest::API::InvoiceMessages.new(credentials)
end

#invoice_paymentsHarvest::API::InvoicePayments

All API Actions surrounding invoice payments

Examples

invoice = harvest.invoices.find(100)
harvest.invoice_payments.all(invoice) # returns all payments for the invoice  (as Harvest::InvoicePayment)

invoice = harvest.invoices.find(100)
harvest.invoice_payments.find(invoice, 5) # returns the payment with ID 5 that is assigned to the invoice

invoice = harvest.invoices.find(100)
payment = Harvest::InvoicePayment.new(:invoice_id => invoice.id)
saved_payment = harvest.invoice_payments.create(payment) # returns a saved version of the payment

invoice = harvest.invoices.find(100)
payment = harvest.invoice_payments.find(invoice, 5)
harvest.invoice_payments.delete(payment) # returns 5


288
289
290
# File 'lib/harvest/base.rb', line 288

def invoice_payments
  @invoice_payments ||= Harvest::API::InvoicePayments.new(credentials)
end

#invoicesObject



266
267
268
# File 'lib/harvest/base.rb', line 266

def invoices
  @invoices ||= Harvest::API::Invoices.new(credentials)
end

#projectsHarvest::API::Projects

All API Actions surrounding Projects

Examples

harvest.projects.all() # Returns all projects in the system

harvest.projects.find(100) # Returns the project with id = 100

project = Harvest::Project.new(:name => 'SuprGlu' :client_id => 10)
saved_project = harvest.projects.create(project) # returns a saved version of Harvest::Project

project = harvest.projects.find(205)
project.name = 'SuprSticky'
updated_project = harvest.projects.update(project) # returns an updated version of Harvest::Project

project = harvest.project.find(205)
harvest.projects.delete(project) # returns 205

project = harvest.projects.find(301)
deactivated_project = harvest.projects.deactivate(project) # returns an updated deactivated project
activated_project = harvest.projects.activate(project) # returns an updated activated project

project = harvest.projects.find(401)
harvest.projects.create_task(project, 'Bottling Glue') # creates and assigns a task to the project


106
107
108
# File 'lib/harvest/base.rb', line 106

def projects
  @projects ||= Harvest::API::Projects.new(credentials)
end

#reportsObject



258
259
260
# File 'lib/harvest/base.rb', line 258

def reports
  @reports ||= Harvest::API::Reports.new(credentials)
end

#task_assignmentsHarvest::API::TaskAssignments

All API Actions surrounding assigning tasks to projects

Examples

project = harvest.projects.find(101)
harvest.task_assignments.all(project) # returns all tasks assigned to the project  (as Harvest::TaskAssignment)

project = harvest.projects.find(201)
harvest.task_assignments.find(project, 5) # returns the task assignment with ID 5 that is assigned to the project

project = harvest.projects.find(301)
task = harvest.tasks.find(100)
assignment = Harvest::TaskAssignment.new(:task_id => task.id, :project_id => project.id)
saved_assignment = harvest.task_assignments.create(assignment) # returns a saved version of the task assignment

project = harvest.projects.find(401)
assignment = harvest.task_assignments.find(project, 15)
assignment.hourly_rate = 150
updated_assignment = harvest.task_assignments.update(assignment) # returns an updated assignment

project = harvest.projects.find(501)
assignment = harvest.task_assignments.find(project, 25)
harvest.task_assignments.delete(assignment) # returns 25


188
189
190
# File 'lib/harvest/base.rb', line 188

def task_assignments
  @task_assignments ||= Harvest::API::TaskAssignments.new(credentials)
end

#tasksHarvest::API::Tasks

All API Actions surrounding Tasks

Examples

harvest.tasks.all() # Returns all tasks in the system

harvest.tasks.find(100) # Returns the task with id = 100

task = Harvest::Task.new(:name => 'Server Administration' :default => true)
saved_task = harvest.tasks.create(task) # returns a saved version of Harvest::Task

task = harvest.tasks.find(205)
task.name = 'Server Administration'
updated_task = harvest.tasks.update(task) # returns an updated version of Harvest::Task

task = harvest.task.find(205)
harvest.tasks.delete(task) # returns 205


129
130
131
# File 'lib/harvest/base.rb', line 129

def tasks
  @tasks ||= Harvest::API::Tasks.new(credentials)
end

#time_entriesObject



254
255
256
# File 'lib/harvest/base.rb', line 254

def time_entries
  @time_entries ||= Harvest::API::TimeEntry.new(credentials)
end

#user_assignmentsHarvest::API::UserAssignments

All API Actions surrounding assigning users to projects

Examples

project = harvest.projects.find(101)
harvest.user_project_assignments.all(project) # returns all users assigned to the project  (as Harvest::UserAssignment)

project = harvest.projects.find(201)
harvest.user_project_assignments.find(project, 5) # returns the user assignment with ID 5 that is assigned to the project

project = harvest.projects.find(301)
user = harvest.users.find(100)
assignment = Harvest::UserAssignment.new(:user_id => user.id, :project_id => project.id)
saved_assignment = harvest.user_project_assignments.create(assignment) # returns a saved version of the user assignment

project = harvest.projects.find(401)
assignment = harvest.user_project_assignments.find(project, 15)
assignment.project_manager = true
updated_assignment = harvest.user_project_assignments.update(assignment) # returns an updated assignment

project = harvest.projects.find(501)
assignment = harvest.user_project_assignments.find(project, 25)
harvest.user_project_assignments.delete(assignment) # returns 25


216
217
218
# File 'lib/harvest/base.rb', line 216

def user_assignments
  @user_assignments ||= Harvest::API::UserAssignments.new(credentials)
end

#usersHarvest::API::Users

All API Actions surrounding Users

Examples

harvest.users.all() # Returns all users in the system

harvest.users.find(100) # Returns the user with id = 100

user = Harvest::User.new(:first_name => 'Edgar', :last_name => 'Ruth', :email => '[email protected]', :password => 'mypassword', :timezone => :cst, :admin => false, :telephone => '444-4444')
saved_user = harvest.users.create(user) # returns a saved version of Harvest::User

user = harvest.users.find(205)
user.email = '[email protected]'
updated_user = harvest.users.update(user) # returns an updated version of Harvest::User

user = harvest.users.find(205)
harvest.users.delete(user) # returns 205

user = harvest.users.find(301)
deactivated_user = harvest.users.deactivate(user) # returns an updated deactivated user
activated_user = harvest.users.activate(user) # returns an updated activated user

user = harvest.users.find(401)
harvest.users.reset_password(user) # will trigger the reset password feature of harvest and shoot the user an email


160
161
162
# File 'lib/harvest/base.rb', line 160

def users
  @users ||= Harvest::API::Users.new(credentials)
end