Class: Easybill::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/easybill/client.rb

Constant Summary collapse

HTTP_RECEIVE_TIMEOUT =

default is 60 seconds which is too low

300
CLIENT_METHODS =
{
  get_customer: { op_name: 'getCustomer', result_type: 'customer' },
  get_customer_by_customer_number: { op_name: 'getCustomerByCustomerNumber', result_type: 'customer' },
  set_customer: { op_name: 'setCustomer', result_type: 'customer' },
  create_document: { op_name: 'createDocument', result_type: 'document' },
  get_documents: { op_name: 'getDocuments', result_type: 'document' },
  add_document_payment: { op_name: 'addDocumentPayment', result_type: nil },
  get_document_payments: { op_name: 'getDocumentPayments', result_type: 'payment' },
  find_documents_by_document_number: { op_name: 'findDocumentsByDocumentNumber', result_type: 'document' },
  get_document_pdf: { op_name: 'getDocumentPDF', result_type: 'document' },
  create_dunning: { op_name: 'createDunning', result_type: 'document' },
  get_document_sent: { op_name: 'getDocumentSent', result_type: 'document' }
}

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



23
24
25
# File 'lib/easybill/client.rb', line 23

def initialize(options = {})
  @options = Easybill.configuration.merge(options)
end

Instance Method Details

#clientObject



27
28
29
30
31
# File 'lib/easybill/client.rb', line 27

def client
  sekken = Sekken.new(Easybill.wsdl)
  sekken.http.receive_timeout = HTTP_RECEIVE_TIMEOUT
  sekken
end

#search_customers(term) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/easybill/client.rb', line 46

def search_customers(term)
  response = save_call do
    operation = client.operation('easybillService', 'easybillPort', :searchCustomers)
    operation.header = { 'UserAuthKey' => @options[:api_key] }
    operation.body = { SearchCustomersRequest: term }

    operation.call
  end
  return [] if response.body[:search_customers_response].nil?

  records = response.body[:search_customers_response][:search_customer]
  records = [records] if records.is_a?(Hash)
  records.map { |hsh| Easybill::Customer.new(hsh) }
end