Class: Payjp::APIResource

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Payjp::APIOperations::Request

included

Methods inherited from PayjpObject

#[], #[]=, #_dump, _load, #as_json, construct_from, #each, #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

Class Method Details

.class_nameObject



5
6
7
# File 'lib/payjp/api_resource.rb', line 5

def self.class_name
  name.split('::')[-1]
end

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



28
29
30
31
32
33
# File 'lib/payjp/api_resource.rb', line 28

def self.retrieve(id, opts = {})
  opts = Util.normalize_opts(opts)
  instance = new(id, opts)
  instance.refresh
  instance
end

.urlObject



9
10
11
12
13
14
# File 'lib/payjp/api_resource.rb', line 9

def self.url
  if self == APIResource
    raise NotImplementedError.new('APIResource is an abstract class.  You should perform actions on its subclasses (Charge, Customer, etc.)')
  end
  "/v1/#{CGI.escape(class_name.downcase)}s"
end

Instance Method Details

#refreshObject



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

def refresh
  response, opts = request(:get, url, @retrieve_params)
  refresh_from(response, opts)
end

#urlObject



16
17
18
19
20
21
# File 'lib/payjp/api_resource.rb', line 16

def url
  unless id = self['id']
    raise InvalidRequestError.new("Could not determine which URL to request: #{self.class} instance has invalid ID: #{id.inspect}", 'id')
  end
  "#{self.class.url}/#{CGI.escape(id)}"
end