Class: Stripe::V2::ListObject
- Inherits:
-
StripeObject
- Object
- StripeObject
- Stripe::V2::ListObject
- Defined in:
- lib/stripe/v2_list_object.rb
Constant Summary collapse
- OBJECT_NAME =
"list"
Constants inherited from StripeObject
StripeObject::RESERVED_FIELD_NAMES
Instance Attribute Summary
Attributes inherited from StripeObject
Class Method Summary collapse
-
.empty_list(opts = {}) ⇒ Object
An empty list object.
- .object_name ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#auto_paging_each(&blk) ⇒ Object
Iterates through each resource in all pages, making additional fetches to the API as necessary.
-
#each(&blk) ⇒ Object
Iterates through each resource in the page represented by the current ‘ListObject`.
-
#empty? ⇒ Boolean
Returns true if the page object contains no elements.
-
#fetch_next_page(opts = {}) ⇒ Object
Fetches the next page in the resource list (if there is one).
-
#reverse_each(&blk) ⇒ Object
Iterates through each resource in the page represented by the current ‘ListObject` in reverse.
Methods inherited from StripeObject
#==, #[]=, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #eql?, #hash, #initialize, #inspect, #keys, #marshal_dump, #marshal_load, protected_fields, #serialize_params, #to_hash, #to_json, #to_s, #update_attributes, #values
Constructor Details
This class inherits a constructor from Stripe::StripeObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Stripe::StripeObject
Class Method Details
.empty_list(opts = {}) ⇒ Object
An empty list object. This is returned from fetch_next_page
when we know that there isn’t a next page.
13 14 15 |
# File 'lib/stripe/v2_list_object.rb', line 13 def self.empty_list(opts = {}) ListObject.construct_from({ data: [] }, opts, nil, :v2) end |
.object_name ⇒ Object
7 8 9 |
# File 'lib/stripe/v2_list_object.rb', line 7 def self.object_name "list" end |
Instance Method Details
#[](key) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/stripe/v2_list_object.rb', line 17 def [](key) case key when String, Symbol super else raise ArgumentError, "You tried to access the #{key.inspect} index, but ListObject " \ "types only support String keys. (HINT: List calls return an " \ "object with a 'data' (which is the data array). You likely " \ "want to call #data[#{key.inspect}])" end end |
#auto_paging_each(&blk) ⇒ Object
Iterates through each resource in all pages, making additional fetches to the API as necessary.
Note that this method will make as many API calls as necessary to fetch all resources. For more granular control, please see each
and fetch_next_page
.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/stripe/v2_list_object.rb', line 51 def auto_paging_each(&blk) return enum_for(:auto_paging_each) unless block_given? page = self loop do page.each(&blk) break if page.next_page_url.nil? page = page.fetch_next_page end end |
#each(&blk) ⇒ Object
Iterates through each resource in the page represented by the current ‘ListObject`.
Note that this method makes no effort to fetch a new page when it gets to the end of the current page’s resources. See also auto_paging_each
.
35 36 37 |
# File 'lib/stripe/v2_list_object.rb', line 35 def each(&blk) data.each(&blk) end |
#empty? ⇒ Boolean
Returns true if the page object contains no elements.
65 66 67 |
# File 'lib/stripe/v2_list_object.rb', line 65 def empty? data.empty? end |
#fetch_next_page(opts = {}) ⇒ Object
Fetches the next page in the resource list (if there is one).
This method will try to respect the limit of the current page. If none was given, the default limit will be fetched again.
73 74 75 76 77 78 79 80 81 |
# File 'lib/stripe/v2_list_object.rb', line 73 def fetch_next_page(opts = {}) return self.class.empty_list(opts) if next_page_url.nil? _request( method: :get, path: next_page_url, base_address: :api ) end |
#reverse_each(&blk) ⇒ Object
Iterates through each resource in the page represented by the current ‘ListObject` in reverse.
41 42 43 |
# File 'lib/stripe/v2_list_object.rb', line 41 def reverse_each(&blk) data.reverse_each(&blk) end |