Class: TogglBillable::Reports::Details

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

Instance Attribute Summary

Attributes inherited from Base

#options, #params, #report

Instance Method Summary collapse

Methods inherited from Base

#billable_items, #initialize, #last_month_billable

Constructor Details

This class inherits a constructor from TogglBillable::Reports::Base

Instance Method Details

#get_report(options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/toggl_billable/reports/details.rb', line 4

def get_report(options = {})
  params[:since]       = options[:start_date]
  params[:until]       = options[:end_date]
  params[:grouping]    = options[:grouping] if options[:grouping]
  params[:subgrouping] = options[:subgrouping] if options[:grouping]
  params[:page]        = options[:page] || 1
  params[:order_field] = options[:oder_field] || 'date'
  count = 0

  result = {}

  loop do
    request = "details?user_agent=reports&#{hash_to_params}"
    response = JSON.parse(Client.report_get(request).body)

    if result.size == 0
      result = response
    else
      result['data'] += response['data']
    end

    count += response['data'].count
    break if count >= response['total_count']

    params[:page] += 1
  end

  result
end