Class: Anthropic::Internal::TokenPage
- Inherits:
-
Object
- Object
- Anthropic::Internal::TokenPage
- Includes:
- Anthropic::Internal::Type::BasePage
- Defined in:
- lib/anthropic/internal/token_page.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary collapse
- #auto_paging_each(&blk) {|| ... } ⇒ void
-
#initialize(client:, req:, headers:, page_data:) ⇒ TokenPage
constructor
private
A new instance of TokenPage.
- #inspect ⇒ String private
- #next_page ⇒ self
- #next_page? ⇒ Boolean
Methods included from Anthropic::Internal::Type::BasePage
Constructor Details
#initialize(client:, req:, headers:, page_data:) ⇒ TokenPage
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 TokenPage.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/anthropic/internal/token_page.rb', line 68 def initialize(client:, req:, headers:, page_data:) super case page_data in {data: Array => data} @data = data.map { Anthropic::Internal::Type::Converter.coerce(@model, _1) } else end @has_more = page_data[:has_more] @next_page_ = page_data[:next_page] end |
Instance Attribute Details
#data ⇒ Array<generic<Elem>>?
20 21 22 |
# File 'lib/anthropic/internal/token_page.rb', line 20 def data @data end |
#has_more ⇒ Boolean
23 24 25 |
# File 'lib/anthropic/internal/token_page.rb', line 23 def has_more @has_more end |
#next_page_ ⇒ String?
26 27 28 |
# File 'lib/anthropic/internal/token_page.rb', line 26 def next_page_ @next_page_ end |
Instance Method Details
#auto_paging_each(&blk) {|| ... } ⇒ void
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/anthropic/internal/token_page.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.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.
83 84 85 86 87 88 89 |
# File 'lib/anthropic/internal/token_page.rb', line 83 def inspect # rubocop:disable Layout/LineLength model = Anthropic::Internal::Type::Converter.inspect(@model, depth: 1) "#<#{self.class}[#{model}]:0x#{object_id.to_s(16)} has_more=#{has_more.inspect} next_page_=#{next_page_.inspect}>" # rubocop:enable Layout/LineLength end |
#next_page ⇒ self
35 36 37 38 39 40 41 42 43 |
# File 'lib/anthropic/internal/token_page.rb', line 35 def next_page unless next_page? = "No more pages available. Please check #next_page? before calling ##{__method__}" raise RuntimeError.new() end req = Anthropic::Internal::Util.deep_merge(@req, {query: {page_token: next_page_}}) @client.request(req) end |
#next_page? ⇒ Boolean
29 30 31 |
# File 'lib/anthropic/internal/token_page.rb', line 29 def next_page? has_more end |