Class: Telnyx::Internal::DefaultPaginationForMessagingTollfree

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

Overview

Examples:

if default_pagination_for_messaging_tollfree.has_next?
  default_pagination_for_messaging_tollfree = default_pagination_for_messaging_tollfree.next_page
end
default_pagination_for_messaging_tollfree.auto_paging_each do |request|
  puts(request)
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Type::BasePage

#to_enum

Constructor Details

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

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 DefaultPaginationForMessagingTollfree.

Parameters:



68
69
70
71
72
73
74
75
76
77
# File 'lib/telnyx/internal/default_pagination_for_messaging_tollfree.rb', line 68

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

  case page_data
  in {records: Array => records}
    @records = records.map { Telnyx::Internal::Type::Converter.coerce(@model, _1) }
  else
  end
  @total_records = page_data[:total_records]
end

Instance Attribute Details

#recordsArray<generic<Elem>>?

Returns:

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


20
21
22
# File 'lib/telnyx/internal/default_pagination_for_messaging_tollfree.rb', line 20

def records
  @records
end

#total_recordsInteger

Returns:

  • (Integer)


23
24
25
# File 'lib/telnyx/internal/default_pagination_for_messaging_tollfree.rb', line 23

def total_records
  @total_records
end

Instance Method Details

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

Parameters:

  • blk (Proc)

Yield Parameters:

  • (generic<Elem>)


48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/telnyx/internal/default_pagination_for_messaging_tollfree.rb', line 48

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

  page = self
  loop do
    page.records&.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)


82
83
84
85
86
# File 'lib/telnyx/internal/default_pagination_for_messaging_tollfree.rb', line 82

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

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

#next_pageself

Returns:

  • (self)

Raises:

  • (Telnyx::HTTP::Error)


32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/telnyx/internal/default_pagination_for_messaging_tollfree.rb', line 32

def next_page
  unless next_page?
    message = "No more pages available. Please check #next_page? before calling ##{__method__}"
    raise RuntimeError.new(message)
  end

  req = Telnyx::Internal::Util.deep_merge(
    @req,
    {query: {page: @req.fetch(:query).fetch(:page, 1).to_i.succ}}
  )
  @client.request(req)
end

#next_page?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/telnyx/internal/default_pagination_for_messaging_tollfree.rb', line 26

def next_page?
  !records.to_a.empty?
end