Class: E2B::SandboxPaginator

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

Instance Attribute Summary

Attributes inherited from BasePaginator

#next_token

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BasePaginator

#has_next?, #next_items

Constructor Details

#initialize(http_client:, query: nil, limit: 100, next_token: nil) ⇒ SandboxPaginator

Returns a new instance of SandboxPaginator.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/e2b/paginator.rb', line 31

def initialize(http_client:, query: nil, limit: 100, next_token: nil)
  normalized_query = normalize_query(query)

  super(limit: limit, next_token: next_token) do |limit:, next_token:|
    params = { limit: limit }
    params[:nextToken] = next_token if next_token
    if normalized_query[:metadata]
      params[:metadata] = self.class.(normalized_query[:metadata])
    end
    params[:state] = normalized_query[:state] if normalized_query[:state]

    response = http_client.get("/v2/sandboxes", params: params, detailed: true)
    sandboxes = extract_sandboxes(response.body)

    [
      Array(sandboxes).map { |sandbox_data| Models::SandboxInfo.from_hash(sandbox_data) },
      response.headers["x-next-token"]
    ]
  end
end

Class Method Details

.encode_metadata(metadata) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/e2b/paginator.rb', line 52

def self.()
  encoded_pairs = .to_h.each_with_object({}) do |(key, value), result|
    result[URI.encode_www_form_component(key.to_s)] = URI.encode_www_form_component(value.to_s)
  end

  URI.encode_www_form(encoded_pairs)
end