Class: Telnyx::Internal::DefaultFlatPagination
- Inherits:
-
Object
- Object
- Telnyx::Internal::DefaultFlatPagination
- Includes:
- Type::BasePage
- Defined in:
- lib/telnyx/internal/default_flat_pagination.rb,
sig/telnyx/internal/default_flat_pagination.rbs
Overview
Defined Under Namespace
Classes: Meta
Instance Attribute Summary collapse
Instance Method Summary collapse
- #auto_paging_each(&blk) {|| ... } ⇒ Object
-
#initialize(client:, req:, headers:, page_data:) ⇒ DefaultFlatPagination
constructor
private
A new instance of DefaultFlatPagination.
- #inspect ⇒ String private
- #next_page ⇒ self
- #next_page? ⇒ Boolean
Methods included from Type::BasePage
Constructor Details
#initialize(client:, req:, headers:, page_data:) ⇒ DefaultFlatPagination
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 DefaultFlatPagination.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/telnyx/internal/default_flat_pagination.rb', line 72 def initialize(client:, req:, headers:, page_data:) super case page_data in {data: Array => data} @data = data.map { Telnyx::Internal::Type::Converter.coerce(@model, _1) } else end case page_data in {meta: Hash | nil => } = Telnyx::Internal::Type::Converter.coerce( Telnyx::Internal::DefaultFlatPagination::Meta, ) else end end |
Instance Attribute Details
#data ⇒ Array<generic<Elem>>?
20 21 22 |
# File 'lib/telnyx/internal/default_flat_pagination.rb', line 20 def data @data end |
Instance Method Details
#auto_paging_each(&blk) {|| ... } ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/telnyx/internal/default_flat_pagination.rb', line 52 def auto_paging_each(&blk) unless block_given? raise ArgumentError.new("A block must be given to ##{__method__}") end page = self loop do page.data&.each(&blk) break unless page.next_page? page = page.next_page end end |
#inspect ⇒ String
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.
93 94 95 96 97 |
# File 'lib/telnyx/internal/default_flat_pagination.rb', line 93 def inspect model = Telnyx::Internal::Type::Converter.inspect(@model, depth: 1) "#<#{self.class}[#{model}]:0x#{object_id.to_s(16)}>" end |
#next_page ⇒ self
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/telnyx/internal/default_flat_pagination.rb', line 32 def next_page unless next_page? = "No more pages available. Please check #next_page? before calling ##{__method__}" raise RuntimeError.new() end req = @req.merge( { query: @req.fetch(:query, {}).except( :"page[number]", :"page[number]".to_s ).merge("page[number]": (&.page_number || 1).to_i.succ) } ) @client.request(req) end |
#next_page? ⇒ Boolean
26 27 28 |
# File 'lib/telnyx/internal/default_flat_pagination.rb', line 26 def next_page? !data.to_a.empty? && (&.page_number.nil? || &.total_pages.nil? || (&.page_number&.< &.total_pages)) end |