Class: Harvest

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

Constant Summary collapse

VERSION =
'0.1.1'

Instance Method Summary collapse

Constructor Details

#initialize(domain, email, password) ⇒ Harvest

Returns a new instance of Harvest.



12
13
14
15
16
# File 'lib/harvest.rb', line 12

def initialize(domain, email, password)
  @domain = domain
  @email = email
  @password = password
end

Instance Method Details

#expense_categoriesObject

returns all expense categories and caches the results see www.getharvest.com/api/expenses



68
69
70
# File 'lib/harvest.rb', line 68

def expense_categories
  @expense_categories ||= request("/expense_categories").expense_categories
end

#expense_category(id) ⇒ Object

returns a specific expense_category see www.getharvest.com/api/expenses



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

def expense_category(id)
  self.expense_categories.find {|e| e.id.to_i == id.to_i}
end

#projectsObject

returns all the projects created in this Harvest account see www.getharvest.com/api/projects for data available



26
27
28
# File 'lib/harvest.rb', line 26

def projects
  request("/projects").projects
end

#report(from, to, project_and_or_person_id) ⇒ Object

returns all tasks and expenses for a given project or person in the given time period. The expenses and entries are mixed in the same array returned. Use .expense? to determine what type it is. Reference www.getharvest.com/api/reporting to get data available for each type



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/harvest.rb', line 35

def report(from, to, project_and_or_person_id)
  entries = []
  
  %w(entries expenses).each do |type|
    if project_and_or_person_id.has_key?(:project_id)
      t = request("/projects/#{project_and_or_person_id[:project_id]}/#{type}?from=#{from.strftime("%Y%m%d")}&to=#{to.strftime("%Y%m%d")}")
      temp = (type == "entries" ? t.day_entries : t.expenses)
      entries += temp.select {|entry| !(entries.any? {|match| match.id == entry.id })}
    end
  
    if project_and_or_person_id.has_key?(:person_id)
      t = request("/people/#{project_and_or_person_id[:person_id]}/#{type}?from=#{from.strftime("%Y%m%d")}&to=#{to.strftime("%Y%m%d")}")
      temp = (type == "entries" ? t.day_entries : t.expenses)
      entries += temp.select {|entry| !(entries.any? {|match| match.id == entry.id })}
    end
  end
  entries
end

#task(id) ⇒ Object

return a specific task see www.getharvest.com/api/tasks



62
63
64
# File 'lib/harvest.rb', line 62

def task(id)
  self.tasks.find {|t| t.id.to_i == id.to_i}
end

#tasksObject

returns all tasks and caches the results see www.getharvest.com/api/tasks



56
57
58
# File 'lib/harvest.rb', line 56

def tasks
  @tasks ||= request("/tasks").tasks
end

#users(params = {}) ⇒ Object

returns all the users created in this Harvest account see www.getharvest.com/api/people for data available



20
21
22
# File 'lib/harvest.rb', line 20

def users(params={})
  request("/people", params).users
end