Class: Nova::API::Resource::Payable
- Inherits:
-
Bill
show all
- Defined in:
- lib/nova/api/resource/payable.rb
Constant Summary
Constants inherited
from Bill
Bill::ALLOWED_ATTRIBUTES
Constants inherited
from Base
Base::PRODUCTION_HOST, Base::SCHEME, Base::STAGING_HOST
Utils::BaseStruct::DATE_REGEX
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
authorization_header, base_url, configuration, do_get, do_get_search, perform_get
#allowed_attributes, generate_valid_value_for, initialize_empty_model_with_id, value_for_field
Class Method Details
.create(parameters) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/nova/api/resource/payable.rb', line 17
def self.create(parameters)
model = new parameters
model.attributes.delete(:id)
model.save
end
|
.destroy(id) ⇒ Object
31
32
33
34
35
|
# File 'lib/nova/api/resource/payable.rb', line 31
def self.destroy(id)
model = initialize_empty_model_with_id(self, id, date: Date.today.iso8601, first_due_date: Date.today.iso8601)
model.destroy
end
|
.endpoint ⇒ Object
5
6
7
|
# File 'lib/nova/api/resource/payable.rb', line 5
def self.endpoint
'/api/payables'
end
|
.find(id) ⇒ Object
13
14
15
|
# File 'lib/nova/api/resource/payable.rb', line 13
def self.find(id)
do_get("#{endpoint}/#{id}", nil, initialize_empty_model_with_id(self, id, date: Date.today.iso8601, first_due_date: Date.today.iso8601))
end
|
.list(parameters = {}) ⇒ Object
9
10
11
|
# File 'lib/nova/api/resource/payable.rb', line 9
def self.list(parameters = {})
do_get_search(endpoint, parameters.to_h)
end
|
.save_invoice(id, parameters) ⇒ Object
37
38
39
40
41
|
# File 'lib/nova/api/resource/payable.rb', line 37
def self.save_invoice(id, parameters)
model = initialize_empty_model_with_id(self, id, date: Date.today.iso8601, first_due_date: Date.today.iso8601)
model.save_invoice(parameters)
end
|
.update(id, parameters) ⇒ Object
25
26
27
28
29
|
# File 'lib/nova/api/resource/payable.rb', line 25
def self.update(id, parameters)
model = new parameters.merge(id: id)
model.update
end
|
Instance Method Details
#destroy ⇒ Object
63
64
65
66
67
|
# File 'lib/nova/api/resource/payable.rb', line 63
def destroy
protect_operation_from_missing_value
do_delete("#{endpoint}")
end
|
#endpoint ⇒ Object
43
44
45
46
47
|
# File 'lib/nova/api/resource/payable.rb', line 43
def endpoint
protect_operation_from_missing_value
"/api/payables/#{id}"
end
|
#save ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/nova/api/resource/payable.rb', line 49
def save
if id.nil?
do_post(self.class.endpoint, allowed_attributes)
else
do_patch("#{endpoint}", allowed_attributes)
end
end
|
#save_invoice(parameters) ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/nova/api/resource/payable.rb', line 69
def save_invoice(parameters)
protect_operation_from_missing_value
invoice = Invoice.new(parameters.merge(bill_id: id))
do_post("#{endpoint}/invoices", invoice.allowed_attributes, invoice)
end
|
#update ⇒ Object
57
58
59
60
61
|
# File 'lib/nova/api/resource/payable.rb', line 57
def update
protect_operation_from_missing_value
do_patch("#{endpoint}", allowed_attributes)
end
|