class SoapyCake::AdminBatched::BatchedRequest

Constants

INITIAL_OFFSET

Both 0 and 1 return the first element. We need to set it to 1, otherwise we get an overlap in the next call. This is not documented in the API spec.

LIMIT

This value depends on the entity size. When all offers have a lot of info (e.g. geotargeting) we probably need to decrease this.

Attributes

admin[R]
limit[R]
method[R]
offset[R]
opts[R]

Public Class Methods

new(admin, method, opts, limit) click to toggle source
# File lib/soapy_cake/admin_batched.rb, line 23
def initialize(admin, method, opts, limit)
  if opts.key?(:row_limit) || opts.key?(:start_at_row)
    raise Error, 'Cannot set row_limit/start_at_row in batched mode!'
  end

  @admin = admin
  @method = method
  @opts = opts
  @offset = INITIAL_OFFSET
  @limit = limit || LIMIT
end

Public Instance Methods

to_enum() click to toggle source
# File lib/soapy_cake/admin_batched.rb, line 35
def to_enum
  Enumerator.new do |y|
    loop do
      fetch_elements(y)
      @offset += limit
    end
  end
end

Private Instance Methods

fetch_batch() click to toggle source
# File lib/soapy_cake/admin_batched.rb, line 57
def fetch_batch
  admin.public_send(method, opts.merge(row_limit: limit, start_at_row: offset))
end
fetch_elements(enumerator) click to toggle source
# File lib/soapy_cake/admin_batched.rb, line 46
def fetch_elements(enumerator)
  result = fetch_batch
  # raises StopIteration when less than `limit` elements are present
  # which is then rescued by `loop`
  if admin.xml_response?
    enumerator << result.next
  else
    limit.times { enumerator << result.next }
  end
end