Class: Harvest::Reports

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

Instance Attribute Summary

Attributes inherited from Base

#domain, #email, #password, #use_ssl

Instance Method Summary collapse

Methods inherited from Base

#initialize, #rate_limit_status

Constructor Details

This class inherits a constructor from Harvest::Base

Instance Method Details

#project_entries(project_id, from, to, user_id = nil) ⇒ Object

GET /projects/#project_id/entries?from=YYYYMMDD&to=YYYYMMDD



9
10
11
12
13
# File 'lib/harvest/reports.rb', line 9

def project_entries(project_id, from, to, user_id=nil)
  opts = {:from => from, :to => to}
  opts[:user_id] = user_id if user_id
  Mash.new(self.class.get("/projects/#{project_id}/entries", :query => opts)).day_entries
end

#project_totals(from = 7.days.ago, to = Date.today) ⇒ Object

[‘proj1’, 25.5], [‘proj2’, 33.3]


25
26
27
28
29
30
31
32
# File 'lib/harvest/reports.rb', line 25

def project_totals(from=7.days.ago, to=Date.today)
  @pt = []
  projects.each do |p|
    hrs = total_project_hours(p.id, from, to)
    @pt << [p.name, hrs] if hrs > 0
  end
  @pt
end

#projectsObject

GET /projects



4
5
6
# File 'lib/harvest/reports.rb', line 4

def projects
  Mash.new(self.class.get("/projects")).projects
end

#total_project_hours(project_id, from, to, user_id = nil) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/harvest/reports.rb', line 15

def total_project_hours(project_id, from, to, user_id=nil)
  pe = project_entries(project_id, from, to, user_id)
  total = 0.0
  if pe
    pe.each {|msh| total += msh.hours}
  end
  total
end