Class: Nova::API::Resource::Receivable
- Inherits:
-
Bill
show all
- Defined in:
- lib/nova/api/resource/receivable.rb
Constant Summary
collapse
- ALLOWED_ATTRIBUTES =
Nova::API::Resource::Bill::ALLOWED_ATTRIBUTES.dup << :gross_value
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
21
22
23
24
25
26
27
|
# File 'lib/nova/api/resource/receivable.rb', line 21
def self.create(parameters)
model = new parameters
model.attributes.delete(:id)
model.save
end
|
.destroy(id) ⇒ Object
35
36
37
38
39
|
# File 'lib/nova/api/resource/receivable.rb', line 35
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
9
10
11
|
# File 'lib/nova/api/resource/receivable.rb', line 9
def self.endpoint
'/api/receivables'
end
|
.find(id) ⇒ Object
17
18
19
|
# File 'lib/nova/api/resource/receivable.rb', line 17
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
13
14
15
|
# File 'lib/nova/api/resource/receivable.rb', line 13
def self.list(parameters = {})
do_get_search(endpoint, parameters.to_h)
end
|
.save_invoice(id, parameters) ⇒ Object
41
42
43
44
45
|
# File 'lib/nova/api/resource/receivable.rb', line 41
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
29
30
31
32
33
|
# File 'lib/nova/api/resource/receivable.rb', line 29
def self.update(id, parameters)
model = new parameters.merge(id: id)
model.update
end
|
Instance Method Details
#destroy ⇒ Object
67
68
69
70
71
|
# File 'lib/nova/api/resource/receivable.rb', line 67
def destroy
protect_operation_from_missing_value
do_delete("#{endpoint}")
end
|
#endpoint ⇒ Object
47
48
49
50
51
|
# File 'lib/nova/api/resource/receivable.rb', line 47
def endpoint
protect_operation_from_missing_value
"/api/receivables/#{id}"
end
|
#save ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/nova/api/resource/receivable.rb', line 53
def save
if id.nil?
do_post(self.class.endpoint, allowed_attributes)
else
do_patch("#{endpoint}", allowed_attributes)
end
end
|
#save_invoice(parameters) ⇒ Object
73
74
75
76
77
78
79
|
# File 'lib/nova/api/resource/receivable.rb', line 73
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
61
62
63
64
65
|
# File 'lib/nova/api/resource/receivable.rb', line 61
def update
protect_operation_from_missing_value
do_patch("#{endpoint}", allowed_attributes)
end
|