Sha256: 78a376df4783ff62daa45b2b50376f304a9dbf94befc845d3f16dc38c72ed307

Contents?: true

Size: 1.12 KB

Versions: 9

Compression:

Stored size: 1.12 KB

Contents

module Paid
  class ListObject < PaidObject

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

    def create(params={}, opts={})
      api_key, headers = Util.parse_opts(opts)
      api_key ||= @api_key
      response, api_key = Paid.request(:post, url, api_key, params, headers)
      Util.convert_to_paid_object(response, api_key)
    end

    def all(params={}, opts={})
      api_key, headers = Util.parse_opts(opts)
      api_key ||= @api_key
      response, api_key = Paid.request(:get, url, api_key, params, headers)
      Util.convert_to_paid_object(response, api_key)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
paid-0.1.0 lib/paid/list_object.rb
paid-0.0.8 lib/paid/list_object.rb
paid-0.0.7 lib/paid/list_object.rb
paid-0.0.6 lib/paid/list_object.rb
paid-0.0.5 lib/paid/list_object.rb
paid-0.0.4 lib/paid/list_object.rb
paid-0.0.3 lib/paid/list_object.rb
paid-0.0.2 lib/paid/list_object.rb
paid-0.0.1 lib/paid/list_object.rb