stripe-ruby/lib/stripe/list_object.rb
Kyle Conroy e3a68bb3b9 Replace api_key with an options hash
For now, only two options are supported: `api_key` and
`idempotency_key`. In the future, we'll be adding support for additional
headers as needed.
2014-12-17 23:23:46 -08:00

38 lines
1.1 KiB
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 retrieve(id, api_key=nil)
api_key ||= @api_key
response, api_key = Stripe.request(:get,"#{url}/#{CGI.escape(id)}", api_key)
Util.convert_to_stripe_object(response, api_key)
end
def create(params={}, opts={})
api_key, headers = Util.parse_opts(opts)
api_key ||= @api_key
response, api_key = Stripe.request(:post, url, api_key, params, headers)
Util.convert_to_stripe_object(response, api_key)
end
def all(params={}, opts={})
api_key, headers = Util.parse_opts(opts)
api_key ||= @api_key
response, api_key = Stripe.request(:get, url, api_key, params, headers)
Util.convert_to_stripe_object(response, api_key)
end
end
end