Class: Harvest::API::Reports
- Inherits:
-
Base
- Object
- Base
- Harvest::API::Reports
- Defined in:
- lib/forecast/api/reports.rb
Constant Summary collapse
- TIME_FORMAT =
'%Y%m%d'
Instance Method Summary collapse
- #expenses_by_project(project, start_date, end_date, options = {}) ⇒ Object
- #expenses_by_user(user, start_date, end_date, options = {}) ⇒ Object
- #projects_by_client(client) ⇒ Object
- #time_by_project(project, start_date, end_date, options = {}) ⇒ Object
- #time_by_user(user, start_date, end_date, options = {}) ⇒ Object
Instance Method Details
#expenses_by_project(project, start_date, end_date, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/forecast/api/reports.rb', line 38 def expenses_by_project(project, start_date, end_date, = {}) query = { from: start_date.strftime(TIME_FORMAT), to: end_date.strftime(TIME_FORMAT) } query[:updated_since] = .delete(:updated_since).to_s if [:updated_since] query.update() 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/forecast/api/reports.rb', line 29 def expenses_by_user(user, start_date, end_date, = {}) query = { from: start_date.strftime(TIME_FORMAT), to: end_date.strftime(TIME_FORMAT) } query[:updated_since] = .delete(:updated_since).to_s if [:updated_since] query.update() 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/forecast/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/forecast/api/reports.rb', line 7 def time_by_project(project, start_date, end_date, = {}) query = { from: start_date.strftime(TIME_FORMAT), to: end_date.strftime(TIME_FORMAT) } query[:user_id] = .delete(:user).to_i if [:user] query[:billable] = (.delete(:billable) ? "yes" : "no") unless [:billable].nil? query[:updated_since] = .delete(:updated_since).to_s if [:updated_since] query.update() 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/forecast/api/reports.rb', line 18 def time_by_user(user, start_date, end_date, = {}) query = { from: start_date.strftime(TIME_FORMAT), to: end_date.strftime(TIME_FORMAT) } query[:project_id] = .delete(:project).to_i if [:project] query[:billable] = (.delete(:billable) ? "yes" : "no") unless [:billable].nil? query[:updated_since] = .delete(:updated_since).to_s if [:updated_since] query.update() response = request(:get, credentials, "/people/#{user.to_i}/entries", query: query) Harvest::TimeEntry.parse(JSON.parse(response.body).map {|h| h["day_entry"]}) end |