Class: E2B::SnapshotPaginator

Inherits:
BasePaginator show all
Defined in:
lib/e2b/paginator.rb

Instance Attribute Summary

Attributes inherited from BasePaginator

#next_token

Instance Method Summary collapse

Methods inherited from BasePaginator

#has_next?, #next_items

Constructor Details

#initialize(http_client:, sandbox_id: nil, limit: 100, next_token: nil) ⇒ SnapshotPaginator

Returns a new instance of SnapshotPaginator.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/e2b/paginator.rb', line 81

def initialize(http_client:, sandbox_id: nil, limit: 100, next_token: nil)
  super(limit: limit, next_token: next_token) do |limit:, next_token:|
    params = { limit: limit }
    params[:sandboxID] = sandbox_id if sandbox_id
    params[:nextToken] = next_token if next_token

    response = http_client.get("/snapshots", params: params, detailed: true)
    snapshots = response.body.is_a?(Array) ? response.body : []

    [
      snapshots.map { |snapshot_data| Models::SnapshotInfo.from_hash(snapshot_data) },
      response.headers["x-next-token"]
    ]
  end
end