Class: Clearbooks::Client
- Inherits:
-
Object
- Object
- Clearbooks::Client
- Extended by:
- Savon::Model
- Defined in:
- lib/clearbooks/library/client.rb
Overview
You should not use it directly. Use static methods in Clearbooks module instead.
Instance Method Summary collapse
-
#allocate_payment(params) ⇒ Hash
- :success, :msg
-
Operation results and brief message.
-
#create_entity(entity) ⇒ Hash
- :entity_id
-
ID of the created entity.
-
#create_invoice(invoice) ⇒ Hash
- :due, :invoice_id, :invoice_prefix, :invoice_number
-
according to official API docs.
-
#create_journal(journal) ⇒ Hash
- :journal_id
-
ID of the created journal.
-
#create_payment(payment) ⇒ Hash
- :payment_id
-
ID of the created payment.
-
#create_project(project) ⇒ Hash
- :project_id
-
ID of the created project.
-
#delete_entity(entity_id) ⇒ Boolean
True if the request was successful, otherwise false.
-
#delete_journal(journal_id) ⇒ Boolean
True if the request was successful, otherwise false.
-
#list_account_codes ⇒ Array, AccountCode
An array or projects.
-
#list_entities(query = {}) ⇒ Array, Entity
An array or entities.
-
#list_invoices(query = {}) ⇒ Array, Invoice
An array or invoices.
-
#list_projects(query = {}) ⇒ Array, Project
An array or projects.
-
#update_entity(entity) ⇒ Hash
Operation taken from WSDL schema secure.clearbooks.co.uk/api/wsdl/.
-
#void_invoice(ledger, invoice_id) ⇒ Hash
Operation taken from WSDL schema secure.clearbooks.co.uk/api/wsdl/.
Instance Method Details
#allocate_payment(params) ⇒ Hash
Returns [:success, :msg] Operation results and brief message.
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/clearbooks/library/client.rb', line 291 def allocate_payment params invoices = params[:invoices].map do |i| { :@id => i[:id], :@amount => i[:amount] } end payment = { :@paymentId => params[:payment_id], :@entityId => params[:entity_id], :@type => params[:type], :invoices => { invoice: invoices } } response = super message: {payment: payment} response = response.to_hash response = response[:allocate_payment_response][:status] { success: response[:@success].to_b, msg: response[:@msg] } end |
#create_entity(entity) ⇒ Hash
Returns [:entity_id] ID of the created entity.
136 137 138 139 140 |
# File 'lib/clearbooks/library/client.rb', line 136 def create_entity entity response = super message: entity.to_savon response = response.to_hash { entity_id: response[:create_entity_response][:create_entity_return].to_i } end |
#create_invoice(invoice) ⇒ Hash
Returns [:due, :invoice_id, :invoice_prefix, :invoice_number] according to official API docs.
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/clearbooks/library/client.rb', line 85 def create_invoice invoice response = super message: invoice.to_savon response = response.to_hash response = response[:create_invoice_response][:create_invoice_return] { due: BigDecimal.new(response[:@due]), invoice_id: response[:@invoice_id].to_i, invoice_prefix: response[:@invoice_prefix], invoice_number: response[:@invoice_number] } end |
#create_journal(journal) ⇒ Hash
Returns [:journal_id] ID of the created journal.
249 250 251 252 253 |
# File 'lib/clearbooks/library/client.rb', line 249 def create_journal journal response = super message: journal.to_savon response = response.to_hash { journal_id: response[:create_journal_response][:create_journal_return][:@journal_id].to_i } end |
#create_payment(payment) ⇒ Hash
Returns [:payment_id] ID of the created payment.
278 279 280 281 282 |
# File 'lib/clearbooks/library/client.rb', line 278 def create_payment payment response = super message: payment.to_savon response = response.to_hash { payment_id: response[:create_payment_response][:create_payment_return][:@payment_id].to_i } end |
#create_project(project) ⇒ Hash
Returns [:project_id] ID of the created project.
208 209 210 211 212 |
# File 'lib/clearbooks/library/client.rb', line 208 def create_project project response = super message: project.to_savon response = response.to_hash { project_id: response[:create_project_response][:create_project_return][:@project_id].to_i } end |
#delete_entity(entity_id) ⇒ Boolean
Returns True if the request was successful, otherwise false.
191 192 193 194 195 |
# File 'lib/clearbooks/library/client.rb', line 191 def delete_entity entity_id response = super message: {entityId: entity_id} response = response.to_hash response[:delete_entity_response][:delete_entity_success] end |
#delete_journal(journal_id) ⇒ Boolean
Returns True if the request was successful, otherwise false.
264 265 266 267 268 |
# File 'lib/clearbooks/library/client.rb', line 264 def delete_journal journal_id response = super message: {journalId: journal_id} response = response.to_hash response[:delete_journal_response][:journal_success] end |
#list_account_codes ⇒ Array, AccountCode
Returns An array or projects.
236 237 238 239 240 |
# File 'lib/clearbooks/library/client.rb', line 236 def list_account_codes response = super response = response.to_hash AccountCode.build response[:list_account_codes_response][:account_codes][:account_code] end |
#list_entities(query = {}) ⇒ Array, Entity
Returns An array or entities.
174 175 176 177 178 179 |
# File 'lib/clearbooks/library/client.rb', line 174 def list_entities query = {} attributes = {query: query.except(:id)} response = super message: {query: {id: query[:id]}, attributes!: attributes} response = response.to_hash Entity.build response[:list_entities_response][:entities][:entity] end |
#list_invoices(query = {}) ⇒ Array, Invoice
Returns An array or invoices.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/clearbooks/library/client.rb', line 55 def list_invoices query = {} defaults = { ledger: :sales } attributes = defaults.merge(query) entity_id = attributes.delete :entity_id invoice_id = attributes.delete :id children = {} children[:entityId] = {'xsd:integer' => entity_id} if entity_id children[:id] = {'xsd:integer' => invoice_id} if invoice_id response = super message: {query: children, attributes!: {query: attributes}} response = response.to_hash Invoice.build response[:list_invoices_response][:create_invoices_return].andand[:invoice] end |
#list_projects(query = {}) ⇒ Array, Project
Returns An array or projects.
223 224 225 226 227 |
# File 'lib/clearbooks/library/client.rb', line 223 def list_projects query = {} response = super message: {query: query} response = response.to_hash Project.build response[:list_projects_response][:projects][:project] end |
#update_entity(entity) ⇒ Hash
Operation taken from WSDL schema secure.clearbooks.co.uk/api/wsdl/
162 163 164 165 166 |
# File 'lib/clearbooks/library/client.rb', line 162 def update_entity entity response = super message: {entityId: entity.id}.merge(entity.to_savon) response = response.to_hash { entity_id: response[:update_entity_response][:update_entity_return].to_i } end |
#void_invoice(ledger, invoice_id) ⇒ Hash
Operation taken from WSDL schema secure.clearbooks.co.uk/api/wsdl/
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/clearbooks/library/client.rb', line 105 def void_invoice ledger, invoice_id = { invoice: { :@type => ledger, :@id => invoice_id } } response = super message: response = response.to_hash response[:void_invoice_response][:void_success] end |