Class: Bankin::Collection
- Inherits:
-
Array
- Object
- Array
- Bankin::Collection
- Defined in:
- lib/bankin/collection.rb
Instance Method Summary collapse
-
#initialize(response, item_class, token = nil) ⇒ Collection
constructor
A new instance of Collection.
- #load_all! ⇒ Object
- #next_page! ⇒ Object
- #next_page? ⇒ Boolean
- #previous_page? ⇒ Boolean
Constructor Details
#initialize(response, item_class, token = nil) ⇒ Collection
Returns a new instance of Collection.
3 4 5 6 7 |
# File 'lib/bankin/collection.rb', line 3 def initialize(response, item_class, token = nil) @item_class = item_class @token = token populate!(response, item_class) end |
Instance Method Details
#load_all! ⇒ Object
32 33 34 35 36 37 |
# File 'lib/bankin/collection.rb', line 32 def load_all! while next_page? do next_page! end self end |
#next_page! ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bankin/collection.rb', line 17 def next_page! return unless next_page? uri = URI.parse(@next_page_uri) params = if uri.query Hash[URI::decode_www_form(uri.query)] else {} end response = Bankin.api_call(:get, uri.path, params, @token) populate!(response, @item_class) self end |
#next_page? ⇒ Boolean
9 10 11 |
# File 'lib/bankin/collection.rb', line 9 def next_page? !@next_page_uri.nil? end |
#previous_page? ⇒ Boolean
13 14 15 |
# File 'lib/bankin/collection.rb', line 13 def previous_page? !@previous_page_uri.nil? end |