mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-12-08 00:01:02 -05:00
Our list calls return their results wrapped in an object so that we can include extra information. We use this, e.g., to include the URL to query for more records in the Transfer#transactions sublist. When you get a ListObject, if you want to actually manipulate it as a list, you have to call `#data` first to get the actual underlying list. This adds an exception to the `#[]` method to make what's going on clearer. Fixes #68
23 lines
616 B
Ruby
23 lines
616 B
Ruby
module Stripe
|
|
class ListObject < StripeObject
|
|
def [](k)
|
|
case k
|
|
when String, Symbol
|
|
super
|
|
else
|
|
raise ArgumentError.new("You tried to access the #{k.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[#{k.inspect}])")
|
|
end
|
|
end
|
|
|
|
def each(&blk)
|
|
self.data.each(&blk)
|
|
end
|
|
|
|
def all(filters={})
|
|
response, api_key = Stripe.request(:get, url, @api_key, filters)
|
|
Util.convert_to_stripe_object(response, api_key)
|
|
end
|
|
|
|
end
|
|
end
|