Class: BadBill::Invoice
- Inherits:
-
BaseResource
- Object
- BaseResource
- BadBill::Invoice
- Defined in:
- lib/badbill/invoice.rb
Overview
The resource handles all invoices.
Instance Attribute Summary
Attributes inherited from BaseResource
Class Method Summary collapse
-
.group_by(*type) ⇒ Array<Invoices>
Get aggregated list of invoices.
Instance Method Summary collapse
-
#cancel ⇒ Boolean
Cancel an invoice.
-
#complete(template_id = nil) ⇒ Boolean
Closes a statement in the draft status (DRAFT).
-
#email(to, from = nil, subject = nil, body = nil, more = {}) ⇒ Boolean
Sends an invoice by email.
-
#pdf ⇒ Hashie::Mash
Get the PDF invoice.
-
#upload_signature(file) ⇒ Boolean
Uploads a digital signature for a given invoice.
Methods inherited from BaseResource
all, create, #delete, #error, find, #initialize, #save
Methods included from Resource
#call, #delete, #get, #post, #put
Methods included from ForwardMethods
Constructor Details
This class inherits a constructor from BadBill::BaseResource
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class BadBill::ForwardMethods
Class Method Details
.group_by(*type) ⇒ Array<Invoices>
Get aggregated list of invoices.
BE CAREFUL: The returned objects are not really invoices. See www.billomat.com/en/api/invoices/ for the format.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/badbill/invoice.rb', line 21 def self.group_by *type if type.respond_to?(:join) type = type.join(',') end all = get resource_name, group_by: type return all if all.error data = all.__send__('invoice-groups').__send__('invoice-group') if data.kind_of? Array data else [data] end end |
Instance Method Details
#cancel ⇒ Boolean
Cancel an invoice.
71 72 73 74 |
# File 'lib/badbill/invoice.rb', line 71 def cancel resp = put resource_name, "#{id}/cancel" !resp end |
#complete(template_id = nil) ⇒ Boolean
Closes a statement in the draft status (DRAFT). Here, the status of open (OPEN) or overdue (OVERDUE) is set and a PDF is generated and stored in the file system.
60 61 62 63 64 65 66 |
# File 'lib/badbill/invoice.rb', line 60 def complete template_id=nil data = { complete: {} } data[:complete] = { template_id: template_id } if template_id resp = put resource_name, "#{id}/complete", data !resp end |
#email(to, from = nil, subject = nil, body = nil, more = {}) ⇒ Boolean
Sends an invoice by email.
from, subject or body can be replaced by more.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/badbill/invoice.rb', line 89 def email to, from=nil, subject=nil, body=nil, more={} data = { recipients: {} } if more.empty? && from.kind_of?(Hash) more = from from = nil end if more.empty? && subject.kind_of?(Hash) more = subject subject = nil end if more.empty? && body.kind_of?(Hash) more = body body = nil end data[:from] = from if from data[:subject] = subject if subject data[:body] = body if body data.merge! more data[:recipients][:to] = to resp = post resource_name, "#{id}/email", email: data !resp end |
#pdf ⇒ Hashie::Mash
Get the PDF invoice.
45 46 47 48 49 50 |
# File 'lib/badbill/invoice.rb', line 45 def pdf resp = get resource_name, "#{id}/pdf" ret = resp.pdf ret.id = ret.id.to_i ret end |
#upload_signature(file) ⇒ Boolean
Uploads a digital signature for a given invoice.
The status of the invoice may not be DRAFT.
126 127 128 129 130 131 132 133 134 |
# File 'lib/badbill/invoice.rb', line 126 def upload_signature file return false if data.status == 'DRAFT' file = File.open(file, 'r') unless file.respond_to?(:read) base64 = Base64.encode64 file.read put resource_name, "#{id}/upload-signature", { signature: { base64file: base64 } } true end |