Sha256: 93532d86368857d4754d35ad72ed6a7f387c5bf6ff89e47eb891f7477dcc914b

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 KB

Contents

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
stripe-1.18.0 lib/stripe/list_object.rb
stripe-1.17.3 lib/stripe/list_object.rb
stripe-1.17.2 lib/stripe/list_object.rb
stripe-1.17.1 lib/stripe/list_object.rb
stripe-1.16.1 lib/stripe/list_object.rb