Class: IletimerkeziSdk::Services::SummaryService

Inherits:
Object
  • Object
show all
Defined in:
lib/iletimerkezi_sdk/services/summary_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(http_client, api_key, api_hash) ⇒ SummaryService

Returns a new instance of SummaryService.



4
5
6
7
8
9
10
11
# File 'lib/iletimerkezi_sdk/services/summary_service.rb', line 4

def initialize(http_client, api_key, api_hash)
  @http_client = http_client
  @api_key = api_key
  @api_hash = api_hash
  @last_start_date = nil
  @last_end_date = nil
  @last_page = nil
end

Instance Method Details

#list(start_date, end_date, page = 1) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/iletimerkezi_sdk/services/summary_service.rb', line 13

def list(start_date, end_date, page = 1)
  @last_start_date = start_date
  @last_end_date = end_date
  @last_page = page
  
  payload = {
    request: {
      authentication: {
        key: @api_key,
        hash: @api_hash
      },
      filter: {
        start: start_date,
        end: end_date
      },
      page: page
    }
  }
  
  response = @http_client.post('get-reports/json', json: payload)
  IletimerkeziSdk::Responses::SummaryResponse.new(response[:body], response[:status], page)
end

#nextObject



36
37
38
39
40
# File 'lib/iletimerkezi_sdk/services/summary_service.rb', line 36

def next
  return nil unless @last_start_date && @last_end_date && @last_page
  
  list(@last_start_date, @last_end_date, @last_page + 1)
end