Class: Bitly::API::Bitlink::PaginatedList

Inherits:
List
  • Object
show all
Defined in:
lib/bitly/api/bitlink/paginated_list.rb

Instance Attribute Summary collapse

Attributes inherited from List

#response

Instance Method Summary collapse

Methods inherited from List

#each

Constructor Details

#initialize(items:, response:, client:) ⇒ PaginatedList

Returns a new instance of PaginatedList.



11
12
13
14
15
16
17
18
19
20
21
22
# 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

Instance Attribute Details

#next_urlObject (readonly)

Returns the value of attribute next_url.



9
10
11
# File 'lib/bitly/api/bitlink/paginated_list.rb', line 9

def next_url
  @next_url
end

#pageObject (readonly)

Returns the value of attribute page.



9
10
11
# File 'lib/bitly/api/bitlink/paginated_list.rb', line 9

def page
  @page
end

#prev_urlObject (readonly)

Returns the value of attribute prev_url.



9
10
11
# File 'lib/bitly/api/bitlink/paginated_list.rb', line 9

def prev_url
  @prev_url
end

#sizeObject (readonly)

Returns the value of attribute size.



9
10
11
# File 'lib/bitly/api/bitlink/paginated_list.rb', line 9

def size
  @size
end

#totalObject (readonly)

Returns the value of attribute total.



9
10
11
# File 'lib/bitly/api/bitlink/paginated_list.rb', line 9

def total
  @total
end

Instance Method Details

#has_next_page?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/bitly/api/bitlink/paginated_list.rb', line 24

def has_next_page?
  !next_url.nil? && !next_url.empty?
end

#has_prev_page?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/bitly/api/bitlink/paginated_list.rb', line 28

def has_prev_page?
  !prev_url.nil? && !prev_url.empty?
end

#next_pageObject



32
33
34
# 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_pageObject



36
37
38
# File 'lib/bitly/api/bitlink/paginated_list.rb', line 36

def prev_page
  has_prev_page? ? get_page(uri: URI(prev_url)) : nil
end