Class: FinchAPI::Internal::ResponsesPage

Inherits:
Object
  • Object
show all
Includes:
Type::BasePage
Defined in:
lib/finch_api/internal/responses_page.rb

Overview

Examples:

if responses_page.has_next?
  responses_page = responses_page.next_page
end
responses_page.auto_paging_each do |pay_statement_item|
  puts(pay_statement_item)
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Type::BasePage

#to_enum

Constructor Details

#initialize(client:, req:, headers:, page_data:) ⇒ ResponsesPage

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ResponsesPage.

Parameters:



56
57
58
59
60
61
62
63
64
# File 'lib/finch_api/internal/responses_page.rb', line 56

def initialize(client:, req:, headers:, page_data:)
  super

  case page_data
  in {responses: Array => responses}
    @responses = responses.map { FinchAPI::Internal::Type::Converter.coerce(@model, _1) }
  else
  end
end

Instance Attribute Details

#responsesArray<generic<Elem>>?

Returns:

  • (Array<generic<Elem>>, nil)


20
21
22
# File 'lib/finch_api/internal/responses_page.rb', line 20

def responses
  @responses
end

Instance Method Details

#auto_paging_each(&blk) {|| ... } ⇒ Object

Parameters:

  • blk (Proc)

Yield Parameters:

  • (generic<Elem>)


36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/finch_api/internal/responses_page.rb', line 36

def auto_paging_each(&blk)
  unless block_given?
    raise ArgumentError.new("A block must be given to ##{__method__}")
  end

  page = self
  loop do
    page.responses&.each(&blk)

    break unless page.next_page?
    page = page.next_page
  end
end

#inspectString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


69
70
71
72
73
# File 'lib/finch_api/internal/responses_page.rb', line 69

def inspect
  model = FinchAPI::Internal::Type::Converter.inspect(@model, depth: 1)

  "#<#{self.class}[#{model}]:0x#{object_id.to_s(16)}>"
end

#next_pageself

Returns:

  • (self)

Raises:

  • (FinchAPI::HTTP::Error)


29
30
31
# File 'lib/finch_api/internal/responses_page.rb', line 29

def next_page
  RuntimeError.new("No more pages available.")
end

#next_page?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/finch_api/internal/responses_page.rb', line 23

def next_page?
  false
end