class Camp3::PaginatedResponse

Wrapper class of paginated response.

Attributes

client[RW]

Public Class Methods

new(array) click to toggle source
# File lib/camp3/paginated_response.rb, line 8
def initialize(array)
  @array = array
end

Public Instance Methods

==(other) click to toggle source
# File lib/camp3/paginated_response.rb, line 12
def ==(other)
  @array == other
end
auto_paginate(&block) click to toggle source
# File lib/camp3/paginated_response.rb, line 49
def auto_paginate(&block)
  return lazy_paginate.to_a unless block_given?

  lazy_paginate.each(&block)
end
client_relative_path(link) click to toggle source
# File lib/camp3/paginated_response.rb, line 105
def client_relative_path(link)
  client_endpoint_path = URI.parse(@client.endpoint).request_uri # api/v4
  URI.parse(link).request_uri.sub(client_endpoint_path, '')
end
each_page() { |current| ... } click to toggle source
# File lib/camp3/paginated_response.rb, line 36
def each_page
  current = self
  yield current
  while current.has_next_page?
    current = current.next_page
    yield current
  end
end
first_page() click to toggle source
# File lib/camp3/paginated_response.rb, line 77
def first_page
  return nil if @client.nil? || !has_first_page?

  @client.get(client_relative_path(@links.first))
end
first_page?() click to toggle source
# File lib/camp3/paginated_response.rb, line 72
def first_page?
  !(@links.nil? || @links.first.nil?)
end
Also aliased as: has_first_page?
has_first_page?()
Alias for: first_page?
has_last_page?()
Alias for: last_page?
has_next_page?()
Alias for: next_page?
has_prev_page?()
Alias for: prev_page?
inspect() click to toggle source
# File lib/camp3/paginated_response.rb, line 16
def inspect
  @array.inspect
end
last_page() click to toggle source
# File lib/camp3/paginated_response.rb, line 66
def last_page
  return nil if @client.nil? || !has_last_page?

  @client.get(client_relative_path(@links.last))
end
last_page?() click to toggle source
# File lib/camp3/paginated_response.rb, line 61
def last_page?
  !(@links.nil? || @links.last.nil?)
end
Also aliased as: has_last_page?
lazy_paginate() click to toggle source
# File lib/camp3/paginated_response.rb, line 45
def lazy_paginate
  to_enum(:each_page).lazy.flat_map(&:to_ary)
end
method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/camp3/paginated_response.rb, line 20
def method_missing(name, *args, &block)
  if @array.respond_to?(name)
    @array.send(name, *args, &block)
  else
    super
  end
end
next_page() click to toggle source
# File lib/camp3/paginated_response.rb, line 88
def next_page
  return nil if @client.nil? || !has_next_page?

  @client.get(client_relative_path(@links.next))
end
next_page?() click to toggle source
# File lib/camp3/paginated_response.rb, line 83
def next_page?
  !(@links.nil? || @links.next.nil?)
end
Also aliased as: has_next_page?
paginate_with_limit(limit, &block) click to toggle source
# File lib/camp3/paginated_response.rb, line 55
def paginate_with_limit(limit, &block)
  return lazy_paginate.take(limit).to_a unless block_given?

  lazy_paginate.take(limit).each(&block)
end
parse_headers!(headers) click to toggle source
# File lib/camp3/paginated_response.rb, line 32
def parse_headers!(headers)
  @links = PageLinks.new headers
end
prev_page() click to toggle source
# File lib/camp3/paginated_response.rb, line 99
def prev_page
  return nil if @client.nil? || !has_prev_page?

  @client.get(client_relative_path(@links.prev))
end
prev_page?() click to toggle source
# File lib/camp3/paginated_response.rb, line 94
def prev_page?
  !(@links.nil? || @links.prev.nil?)
end
Also aliased as: has_prev_page?
respond_to_missing?(method_name, include_private = false) click to toggle source
Calls superclass method
# File lib/camp3/paginated_response.rb, line 28
def respond_to_missing?(method_name, include_private = false)
  super || @array.respond_to?(method_name, include_private)
end