Sha256: b153ff65da93a3c9bcf969143cc6e8c1df41ade4792b130f1c64897d4549d9ba

Contents?: true

Size: 967 Bytes

Versions: 9

Compression:

Stored size: 967 Bytes

Contents

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={})
      response, opts = request(:get,"#{url}/#{CGI.escape(id)}", {}, 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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
stripe-1.23.0 lib/stripe/list_object.rb
stripe-1.22.0 lib/stripe/list_object.rb
stripe-1.21.0 lib/stripe/list_object.rb
stripe-1.20.4 lib/stripe/list_object.rb
stripe-1.20.3 lib/stripe/list_object.rb
stripe-1.20.2 lib/stripe/list_object.rb
stripe-1.20.1 lib/stripe/list_object.rb
stripe-1.20.0 lib/stripe/list_object.rb
stripe-1.19.0 lib/stripe/list_object.rb