Class: FreeAgent::InvoicesResource
- Inherits:
-
Resource
- Object
- Resource
- FreeAgent::InvoicesResource
show all
- Defined in:
- lib/free_agent/resources/invoices.rb
Instance Attribute Summary
Attributes inherited from Resource
#client
Instance Method Summary
collapse
Methods inherited from Resource
#initialize
Instance Method Details
#convert_to_credit_note(id:) ⇒ Object
78
79
80
81
|
# File 'lib/free_agent/resources/invoices.rb', line 78
def convert_to_credit_note(id:)
response = put_request("invoices/#{id}/transitions/convert_to_credit_note", body: {})
response.success?
end
|
#create(contact:, dated_on:, payment_terms_in_days: 0, **params) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/free_agent/resources/invoices.rb', line 30
def create(contact:, dated_on:, payment_terms_in_days: 0, **params)
attributes = {contact: contact, dated_on: dated_on, payment_terms_in_days: payment_terms_in_days}
response = post_request("invoices", body: {invoice: attributes.merge(params)})
Invoice.new(response.body["invoice"]) if response.success?
end
|
#delete(id:) ⇒ Object
47
48
49
50
|
# File 'lib/free_agent/resources/invoices.rb', line 47
def delete(id:)
response = delete_request("invoices/#{id}")
response.success?
end
|
#direct_debit(id:) ⇒ Object
83
84
85
86
|
# File 'lib/free_agent/resources/invoices.rb', line 83
def direct_debit(id:)
response = post_request("invoices/#{id}/direct_debit", body: {})
response.success?
end
|
#duplicate(id:) ⇒ Object
37
38
39
40
|
# File 'lib/free_agent/resources/invoices.rb', line 37
def duplicate(id:)
response = post_request("invoices/#{id}/duplicate", body: {})
Invoice.new(response.body["invoice"]) if response.success?
end
|
#email(id:, to:, **params) ⇒ Object
52
53
54
55
56
|
# File 'lib/free_agent/resources/invoices.rb', line 52
def email(id:, to:, **params)
attributes = {to: to}
response = post_request("invoices/#{id}/send_email", body: {invoice: {email: attributes.merge(params)}})
response.success?
end
|
#list(**params) ⇒ Object
4
5
6
7
|
# File 'lib/free_agent/resources/invoices.rb', line 4
def list(**params)
response = get_request("invoices", params: params)
Collection.from_response(response, type: Invoice, key: "invoices")
end
|
9
10
11
12
|
# File 'lib/free_agent/resources/invoices.rb', line 9
def list_for_contact(contact:, **params)
response = get_request("invoices?contact=#{contact}", params: params)
Collection.from_response(response, type: Invoice, key: "invoices")
end
|
#list_for_project(project:, **params) ⇒ Object
14
15
16
17
|
# File 'lib/free_agent/resources/invoices.rb', line 14
def list_for_project(project:, **params)
response = get_request("invoices?project=#{project}", params: params)
Collection.from_response(response, type: Invoice, key: "invoices")
end
|
#mark_as_cancelled(id:) ⇒ Object
73
74
75
76
|
# File 'lib/free_agent/resources/invoices.rb', line 73
def mark_as_cancelled(id:)
response = put_request("invoices/#{id}/transitions/mark_as_cancelled", body: {})
response.success?
end
|
#mark_as_draft(id:) ⇒ Object
68
69
70
71
|
# File 'lib/free_agent/resources/invoices.rb', line 68
def mark_as_draft(id:)
response = put_request("invoices/#{id}/transitions/mark_as_draft", body: {})
response.success?
end
|
#mark_as_scheduled(id:) ⇒ Object
63
64
65
66
|
# File 'lib/free_agent/resources/invoices.rb', line 63
def mark_as_scheduled(id:)
response = put_request("invoices/#{id}/transitions/mark_as_scheduled", body: {})
response.success?
end
|
#mark_as_sent(id:) ⇒ Object
58
59
60
61
|
# File 'lib/free_agent/resources/invoices.rb', line 58
def mark_as_sent(id:)
response = put_request("invoices/#{id}/transitions/mark_as_sent", body: {})
response.success?
end
|
#retrieve(id:) ⇒ Object
19
20
21
22
|
# File 'lib/free_agent/resources/invoices.rb', line 19
def retrieve(id:)
response = get_request("invoices/#{id}")
Invoice.new(response.body["invoice"])
end
|
#retrieve_pdf(id:) ⇒ Object
Returns a Base64-encoded PDF
25
26
27
28
|
# File 'lib/free_agent/resources/invoices.rb', line 25
def retrieve_pdf(id:)
response = get_request("invoices/#{id}/pdf")
response.body["pdf"]["content"] if response.success?
end
|
#update(id:, **params) ⇒ Object
42
43
44
45
|
# File 'lib/free_agent/resources/invoices.rb', line 42
def update(id:, **params)
response = put_request("invoices/#{id}", body: {invoice: params})
Invoice.new(response.body["invoice"]) if response.success?
end
|