Class: Iugu::APIResource
Instance Attribute Summary
Attributes inherited from Object
#attributes, #errors, #unsaved_attributes
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Object
#add_accessor, #copy, #initialize, #method_missing, #modified_attributes, #set_attributes
Constructor Details
This class inherits a constructor from Iugu::Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Iugu::Object
Class Method Details
.endpoint_url ⇒ Object
17
18
19
|
# File 'lib/iugu/api_resource.rb', line 17
def self.endpoint_url
"#{Iugu.base_uri}#{self.object_base_uri}"
end
|
.object_base_uri ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/iugu/api_resource.rb', line 33
def self.object_base_uri
pluralized_models = ["account", "customer", "payment_method", "invoice", "subscription", "plan"]
if pluralized_models.include? self.object_type
"#{self.object_type}s"
else
object_type
end
end
|
.object_type ⇒ Object
13
14
15
|
# File 'lib/iugu/api_resource.rb', line 13
def self.object_type
Iugu::Utils.underscore name.to_s.split("::")[-1]
end
|
.relative_url(options = "") ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/iugu/api_resource.rb', line 21
def self.relative_url(options = "")
id = case options
when Hash
options[:id] || options["id"]
when Iugu::APIResource
options.id
else
options
end
id ? "/#{id}" : ""
end
|
.url(options = nil) ⇒ Object
5
6
7
|
# File 'lib/iugu/api_resource.rb', line 5
def self.url(options = nil)
endpoint_url + relative_url(options)
end
|
Instance Method Details
#is_new? ⇒ Boolean
9
10
11
|
# File 'lib/iugu/api_resource.rb', line 9
def is_new?
@attributes["id"].nil?
end
|