Sha256: 372cdb445c2cf5de65678cd5752de2d3e36fbd3720acd4b45ddb87e2f2d88ad5

Contents?: true

Size: 961 Bytes

Versions: 2

Compression:

Stored size: 961 Bytes

Contents

module Peakium
  class ListObject < PeakiumObject

    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 all(params={}, api_key=nil)
      response, api_key = Peakium.request(:get, endpoint_url, api_key, params)
      Util.convert_to_peakium_object(response, api_key)
      self.set_endpoint_url(endpoint_url, params)
    end

    def set_endpoint_url(endpoint_url, params)
      # Set the URL for list objects
      url = endpoint_url;
      url += "#{(endpoint_url.include? '?') ? '&' : '?'}#{Peakium.uri_encode(params)}" if params && params.any?
      self.endpoint_url = url
      self
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
peakium-0.1.4 lib/peakium/list_object.rb
peakium-0.1.3 lib/peakium/list_object.rb