3d0157a5
Isaac Lewis
add logoff
|
1
2
|
require "syspro/syspro_object"
require "syspro/api_operations/request"
|
db76748d
Isaac Lewis
cop a bunch of St...
|
3
4
|
module Syspro
|
3d0157a5
Isaac Lewis
add logoff
|
5
6
|
class ApiResource < SysproObject
include Syspro::ApiOperations::Request
|
db76748d
Isaac Lewis
cop a bunch of St...
|
7
8
9
10
11
12
|
def self.class_name
name.split("::")[-1]
end
def self.resource_url
|
3d0157a5
Isaac Lewis
add logoff
|
13
|
if self == ApiResource
|
db76748d
Isaac Lewis
cop a bunch of St...
|
14
15
|
raise NotImplementedError, "APIResource is an abstract class. You should perform actions on its subclasses (Charge, Customer, etc.)"
end
|
3d0157a5
Isaac Lewis
add logoff
|
16
|
"/#{CGI.escape(class_name.downcase)}"
|
db76748d
Isaac Lewis
cop a bunch of St...
|
17
18
19
|
end
def resource_url
|
3d0157a5
Isaac Lewis
add logoff
|
20
21
22
23
|
#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.resource_url}/#{CGI.escape(id)}"
|
db76748d
Isaac Lewis
cop a bunch of St...
|
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
end
def refresh
resp, opts = request(:get, resource_url, @retrieve_params)
initialize_from(resp.data, opts)
end
def self.retrieve(id, opts = {})
opts = Util.normalize_opts(opts)
instance = new(id, opts)
instance.refresh
instance
end
end
end
|