Class: Bitly::API::PaginatedList
- Defined in:
- lib/bitly/api/paginated_list.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#next_url ⇒ Object
readonly
Returns the value of attribute next_url.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#prev_url ⇒ Object
readonly
Returns the value of attribute prev_url.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Attributes inherited from List
Instance Method Summary collapse
- #has_next_page? ⇒ Boolean
- #has_prev_page? ⇒ Boolean
-
#initialize(response:, client:) ⇒ PaginatedList
constructor
A new instance of PaginatedList.
- #item_factory(item) ⇒ Object
- #item_key ⇒ Object
- #next_page ⇒ Object
- #prev_page ⇒ Object
Methods inherited from List
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_url ⇒ Object (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 |
#page ⇒ Object (readonly)
Returns the value of attribute page.
8 9 10 |
# File 'lib/bitly/api/paginated_list.rb', line 8 def page @page end |
#prev_url ⇒ Object (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 |
#size ⇒ Object (readonly)
Returns the value of attribute size.
8 9 10 |
# File 'lib/bitly/api/paginated_list.rb', line 8 def size @size end |
#total ⇒ Object (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
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
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
43 44 45 |
# File 'lib/bitly/api/paginated_list.rb', line 43 def item_factory(item) raise NotImplementedError end |
#item_key ⇒ Object
39 40 41 |
# File 'lib/bitly/api/paginated_list.rb', line 39 def item_key raise NotImplementedError end |
#next_page ⇒ Object
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_page ⇒ Object
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 |