Class: Bitly::API::PaginatedList

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

Instance Attribute Summary collapse

Attributes inherited from List

#response

Instance Method Summary collapse

Methods inherited from List

#each

Constructor Details

#initialize(response:, client:) ⇒ PaginatedList

Returns a new instance of PaginatedList.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bitly/api/paginated_list.rb', line 10

def initialize(response: , client:)
  @client = client
  super(items: items_from_response(response: response), response: response)
  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.



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

def next_url
  @next_url
end

#pageObject (readonly)

Returns the value of attribute page.



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

def page
  @page
end

#prev_urlObject (readonly)

Returns the value of attribute prev_url.



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

def prev_url
  @prev_url
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

#totalObject (readonly)

Returns the value of attribute total.



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

def total
  @total
end

Instance Method Details

#has_next_page?Boolean

Returns:

  • (Boolean)


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

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

#has_prev_page?Boolean

Returns:

  • (Boolean)


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

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

#item_factory(item) ⇒ Object

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/bitly/api/paginated_list.rb', line 43

def item_factory(item)
  raise NotImplementedError
end

#item_keyObject

Raises:

  • (NotImplementedError)


39
40
41
# File 'lib/bitly/api/paginated_list.rb', line 39

def item_key
  raise NotImplementedError
end

#next_pageObject



31
32
33
# File 'lib/bitly/api/paginated_list.rb', line 31

def next_page
  has_next_page? ? get_page(uri: URI(next_url)) : nil
end

#prev_pageObject



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

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