Class: Telnyx::Internal::DefaultPaginationForQueues

Inherits:
Object
  • Object
show all
Includes:
Type::BasePage
Defined in:
lib/telnyx/internal/default_pagination_for_queues.rb,
sig/telnyx/internal/default_pagination_for_queues.rbs

Overview

Examples:

if default_pagination_for_queues.has_next?
  default_pagination_for_queues = default_pagination_for_queues.next_page
end
default_pagination_for_queues.auto_paging_each do |queue|
  puts(queue)
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Type::BasePage

#to_enum

Constructor Details

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

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

Parameters:

API:

  • private



74
75
76
77
78
79
80
81
82
# File 'lib/telnyx/internal/default_pagination_for_queues.rb', line 74

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

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

Instance Attribute Details

#queuesArray<generic<Elem>>?

Returns:



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

def queues
  @queues
end

Instance Method Details

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

Parameters:

Yield Parameters:

  • (generic<Elem>)


54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/telnyx/internal/default_pagination_for_queues.rb', line 54

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

  page = self
  loop do
    page.queues&.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:

API:

  • private



87
88
89
90
91
# File 'lib/telnyx/internal/default_pagination_for_queues.rb', line 87

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

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

#next_pageself

Returns:

Raises:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/telnyx/internal/default_pagination_for_queues.rb', line 29

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

  req = @req.merge(
    {
      query: @req.fetch(:query, {}).except(
        :Page,
        :Page.to_s
      ).merge(Page: @req.fetch(:query, {}).fetch(
        :Page,
        @req.fetch(:query, {}).fetch(
          :Page.to_s, 1
        )
      ).to_i.succ)
    }
  )
  @client.request(req)
end

#next_page?Boolean

Returns:



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

def next_page?
  !queues.to_a.empty?
end