Sha256: 0bef40bfc666cb8a5f8e87a5d5f2d0605925b6625e465eb9a4b634414c744cb5

Contents?: true

Size: 1.04 KB

Versions: 16

Compression:

Stored size: 1.04 KB

Contents

module Pingpp
  class ListObject < PingppObject

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

    def create(params={}, api_key=nil)
      api_key ||= @api_key
      response, api_key = Pingpp.request(:post, url, api_key, params)
      Util.convert_to_pingpp_object(response, api_key)
    end

    def all(params={}, api_key=nil)
      api_key ||= @api_key
      response, api_key = Pingpp.request(:get, url, api_key, params)
      Util.convert_to_pingpp_object(response, api_key)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
pingpp-2.0.15 lib/pingpp/list_object.rb
pingpp-2.0.14 lib/pingpp/list_object.rb
pingpp-2.0.13 lib/pingpp/list_object.rb
pingpp-2.0.12 lib/pingpp/list_object.rb
pingpp-2.0.11 lib/pingpp/list_object.rb
pingpp-2.0.8 lib/pingpp/list_object.rb
pingpp-2.0.7 lib/pingpp/list_object.rb
pingpp-2.0.6 lib/pingpp/list_object.rb
pingpp-2.0.5 lib/pingpp/list_object.rb
pingpp-2.0.4 lib/pingpp/list_object.rb
pingpp-2.0.3 lib/pingpp/list_object.rb
pingpp-2.0.2 lib/pingpp/list_object.rb
pingpp-2.0.1 lib/pingpp/list_object.rb
pingpp-2.0.0 lib/pingpp/list_object.rb
pingpp-1.0.3 lib/pingpp/list_object.rb
pingpp-1.0.2 lib/pingpp/list_object.rb