Module: Finix::Resource
- Includes:
- HalResource
- Included in:
- Application, Authorization, Dispute, Error, Evidence, FeeProfile, Identity, Merchant, MerchantProfile, PaymentInstrument, Processor, Refund, RiskProfile, Settlement, Token, Transfer, UnknownResource, User, Verification, Webhook
- Defined in:
- lib/finix/resources/resource.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary
Attributes included from HalResource
#attributes, #hyperlinks
Class Method Summary
collapse
Instance Method Summary
collapse
#load_page_from_response!, #method_missing
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Finix::HalResource
Class Method Details
.included(base) ⇒ Object
99
100
101
|
# File 'lib/finix/resources/resource.rb', line 99
def self.included(base)
base.extend ClassMethods
end
|
Instance Method Details
#copy_from(other) ⇒ Object
89
90
91
92
93
|
# File 'lib/finix/resources/resource.rb', line 89
def copy_from(other)
other.instance_variables.each do |ivar|
instance_variable_set ivar, other.instance_variable_get(ivar)
end
end
|
#fetch(*arguments) ⇒ Object
Also known as:
find
37
38
39
|
# File 'lib/finix/resources/resource.rb', line 37
def fetch(*arguments)
self.class.find *arguments
end
|
#initialize(*args) ⇒ Object
#refresh(the_response = nil) ⇒ Object
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/finix/resources/resource.rb', line 78
def refresh(the_response = nil)
if the_response
return if the_response.body.to_s.length.zero?
fresh = self.class.construct_from_response the_response.body
else
fresh = self.find(@hyperlinks[:self])
end
fresh and copy_from fresh
self
end
|
#sanitize ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/finix/resources/resource.rb', line 64
def sanitize
to_submit = {}
@attributes.each do |key, value|
to_submit[key] = value unless value.is_a? Finix::Resource
end
to_submit
end
|
#save(options = {}, href = nil) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/finix/resources/resource.rb', line 43
def save(options = {}, href = nil)
options = options.is_a?(Finix::Resource) ? options.attributes : options
@attributes = @attributes.merge options
href ||= @hyperlinks[:self]
method = :post
if href.nil?
href = Finix.get_href self.class
elsif not @attributes[:id].nil?
method = :put
end
attributes_to_submit = self.sanitize
begin
@response = Finix.send(method, href, attributes_to_submit)
rescue Exception
raise
end
refresh @response
end
|
#to_s ⇒ Object
95
96
97
|
# File 'lib/finix/resources/resource.rb', line 95
def to_s
"#{self.class.name.split('::').last || ''} #{@attributes}"
end
|