Class: Colppy::Customer
- Defined in:
- lib/colppy/resources/customer.rb
Constant Summary collapse
- ATTRIBUTES_MAPPER =
{ RazonSocial: :name, NombreFantasia: :fantasy_name, DirPostal: :address, DirPostalCiudad: :address_city, DirPostalCodigoPostal: :address_zipcode, DirPostalProvincia: :address_state, DirPostalPais: :address_country, DirFiscal: :legal_address, DirFiscalCiudad: :legal_address_city, DirFiscalCodigoPostal: :legal_address_zipcode, DirFiscalProvincia: :legal_address_state, DirFiscalPais: :legal_address_country, Telefono: :phone_number, Fax: :fax_number, Activo: :active, idCondicionPago: :payment_condition_id, idCondicionIva: :tax_condition_id, CUIT: :cuit, dni: :dni, idTipoPercepcion: :tax_perception_id, NroCuenta: :account_number, CBU: :cbu, Banco: :bank, porcentajeIVA: :tax, Email: :email, Saldo: :balance }.freeze
- PROTECTED_DATA_KEYS =
[:id, :company_id, :name].freeze
- DATA_KEYS_SETTERS =
(ATTRIBUTES_MAPPER.values - PROTECTED_DATA_KEYS).freeze
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Attributes inherited from Resource
Class Method Summary collapse
- .all(client, company) ⇒ Object
- .get(client, company, id) ⇒ Object
- .list(client, company, parameters = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(client: nil, company: nil, **params) ⇒ Customer
constructor
A new instance of Customer.
- #new? ⇒ Boolean
- #save ⇒ Object
Methods inherited from Resource
Methods included from Utils
Constructor Details
#initialize(client: nil, company: nil, **params) ⇒ Customer
Returns a new instance of Customer.
91 92 93 94 95 96 97 98 |
# File 'lib/colppy/resources/customer.rb', line 91 def initialize(client: nil, company: nil, **params) @client = client if client && client.is_a?(Colppy::Client) @company = company if company && company.is_a?(Colppy::Company) @id = params.delete(:idCliente) || params.delete(:id) @name = params.delete(:RazonSocial) || params.delete(:name) super(params) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/colppy/resources/customer.rb', line 3 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/colppy/resources/customer.rb', line 3 def name @name end |
Class Method Details
.all(client, company) ⇒ Object
37 38 39 |
# File 'lib/colppy/resources/customer.rb', line 37 def all(client, company) list(client, company) end |
.get(client, company, id) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/colppy/resources/customer.rb', line 58 def get(client, company, id) response = client.call( :customer, :read, extended_parameters(client, company, { idCliente: id }) ) if response[:success] new(response[:data].merge(client: client, company: company)) else response end end |
.list(client, company, parameters = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/colppy/resources/customer.rb', line 41 def list(client, company, parameters = {}) call_parameters = base_params.merge(parameters) response = client.call( :customer, :list, extended_parameters(client, company, call_parameters) ) if response[:success] results = response[:data].map do |params| new(params.merge(client: client, company: company)) end parse_list_response(results, response[:total].to_i, call_parameters) else response end end |
Instance Method Details
#new? ⇒ Boolean
105 106 107 |
# File 'lib/colppy/resources/customer.rb', line 105 def new? id.nil? || id.empty? end |
#save ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/colppy/resources/customer.rb', line 109 def save ensure_client_valid! && ensure_company_valid! response = @client.call( :customer, operation, save_parameters ) if response[:success] response_data = response[:data] case operation when :create @id = response_data[:idCliente] when :update @data[:NombreFantasia] = response_data[:nombreCliente] end self else false end end |