class Bitly::API::Bitlink::PaginatedList
Attributes
next_url[R]
page[R]
prev_url[R]
size[R]
total[R]
Public Class Methods
new(items:, response: , client:)
click to toggle source
Calls superclass method
Bitly::API::List::new
# File lib/bitly/api/bitlink/paginated_list.rb, line 11 def initialize(items:, response: , client:) super(items: items, response: response) @client = client if response.body["pagination"] pagination = response.body["pagination"] @next_url = pagination["next"] @prev_url = pagination["prev"] @size = pagination["size"] @page = pagination["page"] @total = pagination["total"] end end
Public Instance Methods
has_next_page?()
click to toggle source
# File lib/bitly/api/bitlink/paginated_list.rb, line 24 def has_next_page? !next_url.nil? && !next_url.empty? end
has_prev_page?()
click to toggle source
# File lib/bitly/api/bitlink/paginated_list.rb, line 28 def has_prev_page? !prev_url.nil? && !prev_url.empty? end
next_page()
click to toggle source
# File lib/bitly/api/bitlink/paginated_list.rb, line 32 def next_page has_next_page? ? get_page(uri: URI(next_url)) : nil end
prev_page()
click to toggle source
# File lib/bitly/api/bitlink/paginated_list.rb, line 36 def prev_page has_prev_page? ? get_page(uri: URI(prev_url)) : nil end
Private Instance Methods
get_page(uri:)
click to toggle source
# File lib/bitly/api/bitlink/paginated_list.rb, line 42 def get_page(uri:) response = @client.request(path: uri.path.gsub(/\/v4/, ""), params: CGI.parse(uri.query)) bitlinks = response.body["links"].map do |link| Bitlink.new(data: link, client: @client) end self.class.new(items: bitlinks, response: response, client: @client) end