Class: Harvest::API::Reports

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

Constant Summary

TIME_FORMAT =
'%Y%m%d'

Instance Attribute Summary

Attributes inherited from Base

#credentials

Instance Method Summary collapse

Methods inherited from Base

api_model, #initialize

Constructor Details

This class inherits a constructor from Harvest::API::Base

Instance Method Details

#expenses_by_project(project, start_date, end_date, options = {}) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/harvest/api/reports.rb', line 38

def expenses_by_project(project, start_date, end_date, options = {})
  query = { from: start_date.strftime(TIME_FORMAT), to: end_date.strftime(TIME_FORMAT) }
  query[:updated_since] = options.delete(:updated_since).to_s if options[:updated_since]
  query.update(options)

  response = request(:get, credentials, "/projects/#{project.to_i}/expenses", query: query)
  Harvest::Expense.parse(response.parsed_response)
end

#expenses_by_user(user, start_date, end_date, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/harvest/api/reports.rb', line 29

def expenses_by_user(user, start_date, end_date, options = {})
  query = { from: start_date.strftime(TIME_FORMAT), to: end_date.strftime(TIME_FORMAT) }
  query[:updated_since] = options.delete(:updated_since).to_s if options[:updated_since]
  query.update(options)

  response = request(:get, credentials, "/people/#{user.to_i}/expenses", query: query)
  Harvest::Expense.parse(response.parsed_response)
end

#projects_by_client(client) ⇒ Object



47
48
49
50
# File 'lib/harvest/api/reports.rb', line 47

def projects_by_client(client)
  response = request(:get, credentials, "/projects?client=#{client.to_i}")
  Harvest::Project.parse(response.parsed_response)
end

#time_by_project(project, start_date, end_date, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/harvest/api/reports.rb', line 7

def time_by_project(project, start_date, end_date, options = {})
  query = { from: start_date.strftime(TIME_FORMAT), to: end_date.strftime(TIME_FORMAT) }
  query[:user_id]       = options.delete(:user).to_i if options[:user]
  query[:billable]      = (options.delete(:billable) ? "yes" : "no") unless options[:billable].nil?
  query[:updated_since] = options.delete(:updated_since).to_s if options[:updated_since]
  query.update(options)

  response = request(:get, credentials, "/projects/#{project.to_i}/entries", query: query)
  Harvest::TimeEntry.parse(JSON.parse(response.body).map {|h| h["day_entry"]})
end

#time_by_user(user, start_date, end_date, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/harvest/api/reports.rb', line 18

def time_by_user(user, start_date, end_date, options = {})
  query = { from: start_date.strftime(TIME_FORMAT), to: end_date.strftime(TIME_FORMAT) }
  query[:project_id]    = options.delete(:project).to_i if options[:project]
  query[:billable]      = (options.delete(:billable) ? "yes" : "no") unless options[:billable].nil?
  query[:updated_since] = options.delete(:updated_since).to_s if options[:updated_since]
  query.update(options)

  response = request(:get, credentials, "/people/#{user.to_i}/entries", query: query)
  Harvest::TimeEntry.parse(JSON.parse(response.body).map {|h| h["day_entry"]})
end