Class: Payjp::ListObject

Inherits:
PayjpObject show all
Includes:
APIOperations::Request
Defined in:
lib/payjp/list_object.rb

Instance Method Summary collapse

Methods included from APIOperations::Request

included

Methods inherited from PayjpObject

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

Constructor Details

This class inherits a constructor from Payjp::PayjpObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Payjp::PayjpObject

Instance Method Details

#[](k) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/payjp/list_object.rb', line 5

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

#all(params = {}, opts = {}) ⇒ Object



28
29
30
31
# File 'lib/payjp/list_object.rb', line 28

def all(params = {}, opts = {})
  response, opts = request(:get, url, params, opts)
  Util.convert_to_payjp_object(response, opts)
end

#create(params = {}, opts = {}) ⇒ Object



23
24
25
26
# File 'lib/payjp/list_object.rb', line 23

def create(params = {}, opts = {})
  response, opts = request(:post, url, params, opts)
  Util.convert_to_payjp_object(response, opts)
end

#each(&blk) ⇒ Object



14
15
16
# File 'lib/payjp/list_object.rb', line 14

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

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



18
19
20
21
# File 'lib/payjp/list_object.rb', line 18

def retrieve(id, opts = {})
  response, opts = request(:get, "#{url}/#{CGI.escape(id)}", {}, opts)
  Util.convert_to_payjp_object(response, opts)
end