Class: TogglAPI::ReportsClient
- Inherits:
-
BaseClient
- Object
- BaseClient
- TogglAPI::ReportsClient
- Defined in:
- lib/toggl_api/reports_client.rb
Overview
The Toggl API Client
Constant Summary collapse
- API_URL =
"https://toggl.com/reports/api/v2"
Constants inherited from BaseClient
BaseClient::DEFAULT_USER_AGENT
Instance Attribute Summary
Attributes inherited from BaseClient
Instance Method Summary collapse
- #fetch_reports(params) ⇒ Object
- #fetch_reports_details_raw(params) ⇒ Object
- #fetch_reports_summary_raw(params) ⇒ Object
Methods inherited from BaseClient
#default_api_token, #default_headers, #default_user_agent, #default_workspace_id, #initialize
Constructor Details
This class inherits a constructor from TogglAPI::BaseClient
Instance Method Details
#fetch_reports(params) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/toggl_api/reports_client.rb', line 17 def fetch_reports(params) raise "Must give a block" unless block_given? page = 1 current_total = 0 loop do results_raw = fetch_reports_details_raw( params.merge(page: page) ) yield(results_raw["data"]) current_total += results_raw["data"].count break if current_total == results_raw["total_count"] page += 1 end end |
#fetch_reports_details_raw(params) ⇒ Object
33 34 35 |
# File 'lib/toggl_api/reports_client.rb', line 33 def fetch_reports_details_raw(params) fetch_reports_raw(api_url(:details), params) end |
#fetch_reports_summary_raw(params) ⇒ Object
37 38 39 |
# File 'lib/toggl_api/reports_client.rb', line 37 def fetch_reports_summary_raw(params) fetch_reports_raw(api_url(:summary), params) end |