mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-10-04 00:00:47 -04:00
40 lines
1.1 KiB
Ruby
40 lines
1.1 KiB
Ruby
module Stripe
|
|
class ListObject < StripeObject
|
|
include Stripe::APIOperations::Request
|
|
|
|
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 retrieve(id, opts={})
|
|
if id.kind_of?(Hash) # overloaded id
|
|
retrieve_params = id
|
|
id = retrieve_params.delete(:id)
|
|
else
|
|
retrieve_params = {}
|
|
end
|
|
response, opts = request(:get,"#{url}/#{CGI.escape(id)}", retrieve_params, opts)
|
|
Util.convert_to_stripe_object(response, opts)
|
|
end
|
|
|
|
def create(params={}, opts={})
|
|
response, opts = request(:post, url, params, opts)
|
|
Util.convert_to_stripe_object(response, opts)
|
|
end
|
|
|
|
def all(params={}, opts={})
|
|
response, opts = request(:get, url, params, opts)
|
|
Util.convert_to_stripe_object(response, opts)
|
|
end
|
|
end
|
|
end
|