Class: Pingpp::ListObject

Inherits:
PingppObject show all
Includes:
APIOperations::Create, APIOperations::List, APIOperations::Request
Defined in:
lib/pingpp/list_object.rb

Instance Method Summary collapse

Methods included from APIOperations::Create

#create

Methods included from APIOperations::Request

included

Methods included from APIOperations::List

#list

Methods inherited from PingppObject

#==, #[]=, #_dump, _load, #as_json, construct_from, #initialize, #inspect, #keys, #refresh_from, #respond_to?, #serialize_params, #to_hash, #to_json, #to_s, #values

Constructor Details

This class inherits a constructor from Pingpp::PingppObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Pingpp::PingppObject

Instance Method Details

#[](k) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/pingpp/list_object.rb', line 7

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

#each(&blk) ⇒ Object



16
17
18
# File 'lib/pingpp/list_object.rb', line 16

def each(&blk)
  self.data.each(&blk)
end

#empty?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/pingpp/list_object.rb', line 20

def empty?
  self.data.empty?
end

#resource_url(opts = {}) ⇒ Object



30
31
32
33
# File 'lib/pingpp/list_object.rb', line 30

def resource_url(opts={})
  self.url ||
    raise(ArgumentError, "List object does not contain a 'url' field.")
end

#retrieve(id, opts = {}) ⇒ Object



24
25
26
27
28
# File 'lib/pingpp/list_object.rb', line 24

def retrieve(id, opts={})
  id, retrieve_params = Util.normalize_id(id)
  response, opts = request(:get, "#{resource_url(opts)}/#{CGI.escape(id)}", retrieve_params, opts)
  Util.convert_to_pingpp_object(response, opts)
end