class Passworks::CollectionProxy

Attributes

client[R]
collection_name[R]
collection_uuid[R]
options[R]

Public Class Methods

new(client, collection_name, collection_uuid=nil, options={}) click to toggle source
# File lib/passworks/collection_proxy.rb, line 11
def initialize(client, collection_name, collection_uuid=nil, options={})
  @collection_name  = collection_name
  @collection_uuid  = collection_uuid
  @client           = client
  @options          = options
end

Public Instance Methods

each() { |resource_class| ... } click to toggle source
# File lib/passworks/collection_proxy.rb, line 18
def each(&block)
  next_page = nil
  loop do
    if next_page
      response = client.get(collection_url, options.merge({query: {page: next_page}}))
    else
      response = client.get(collection_url, options)
    end
    response.data.each do |item_data|
      yield resource_class.new(client, collection_name, item_data)
    end
    # Kaminari returns next_page as an empty string if there aren't more pages
    next_page = response.next_page.to_s.to_i
    break if next_page == 0
  end
  self
end

Private Instance Methods

collection_url() click to toggle source
# File lib/passworks/collection_proxy.rb, line 38
def collection_url
  if collection_uuid
    "#{collection_name}/#{collection_uuid}/passes"
  else
    collection_name
  end
end