Class: BlingApi::Customer
- Inherits:
-
Object
- Object
- BlingApi::Customer
- Defined in:
- lib/bling_api/customer.rb
Instance Attribute Summary collapse
-
#celular ⇒ Object
readonly
Returns the value of attribute celular.
-
#cod_contribuinte ⇒ Object
readonly
Returns the value of attribute cod_contribuinte.
-
#codigo ⇒ Object
readonly
Returns the value of attribute codigo.
-
#dados_adicionais ⇒ Object
readonly
Returns the value of attribute dados_adicionais.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#endereco ⇒ Object
readonly
Returns the value of attribute endereco.
-
#endereco_cobranca ⇒ Object
readonly
Returns the value of attribute endereco_cobranca.
-
#fantasia ⇒ Object
readonly
Returns the value of attribute fantasia.
-
#financeiro ⇒ Object
readonly
Returns the value of attribute financeiro.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#ie ⇒ Object
readonly
Returns the value of attribute ie.
-
#nome ⇒ Object
readonly
Returns the value of attribute nome.
-
#numero_documento ⇒ Object
readonly
Returns the value of attribute numero_documento.
-
#orgao_emissor ⇒ Object
readonly
Returns the value of attribute orgao_emissor.
-
#pais ⇒ Object
readonly
Returns the value of attribute pais.
-
#pessoa_contato ⇒ Object
readonly
Returns the value of attribute pessoa_contato.
-
#pessoa_juridica ⇒ Object
readonly
Returns the value of attribute pessoa_juridica.
-
#rg ⇒ Object
readonly
Returns the value of attribute rg.
-
#situacao ⇒ Object
readonly
Returns the value of attribute situacao.
-
#telefone ⇒ Object
readonly
Returns the value of attribute telefone.
-
#tipos_contato ⇒ Object
readonly
Returns the value of attribute tipos_contato.
-
#vendedor ⇒ Object
readonly
Returns the value of attribute vendedor.
Class Method Summary collapse
Instance Method Summary collapse
- #build_json ⇒ Object
- #create ⇒ Object
-
#initialize(nome:, codigo: nil, pessoa_juridica:, numero_documento:, rg: nil, orgao_emissor: nil, id: nil, telefone: nil, celular: nil, email: nil, endereco: nil, endereco_cobranca: nil, cod_contribuinte: nil, situacao: nil, ie: nil, fantasia: nil, financeiro: nil, pais: nil, tipos_contato: nil, pessoa_contato: nil, vendedor: nil, dados_adicionais: nil) ⇒ Customer
constructor
A new instance of Customer.
- #phone_formatted(phone) ⇒ Object
- #update(attributes) ⇒ Object
Constructor Details
#initialize(nome:, codigo: nil, pessoa_juridica:, numero_documento:, rg: nil, orgao_emissor: nil, id: nil, telefone: nil, celular: nil, email: nil, endereco: nil, endereco_cobranca: nil, cod_contribuinte: nil, situacao: nil, ie: nil, fantasia: nil, financeiro: nil, pais: nil, tipos_contato: nil, pessoa_contato: nil, vendedor: nil, dados_adicionais: nil) ⇒ Customer
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/bling_api/customer.rb', line 18 def initialize(nome:, codigo: nil, pessoa_juridica:, numero_documento:, rg: nil, orgao_emissor: nil, id: nil, telefone: nil, celular: nil, email: nil, endereco: nil, endereco_cobranca: nil, cod_contribuinte: nil, situacao: nil, ie: nil, fantasia: nil, financeiro: nil, pais: nil, tipos_contato: nil, pessoa_contato: nil, vendedor: nil, dados_adicionais: nil) @id = id @nome = nome @pessoa_juridica = pessoa_juridica @codigo = codigo @telefone = telefone @celular = celular @numero_documento = numero_documento @orgao_emissor = orgao_emissor @rg = rg @email = email @endereco = endereco&.with_indifferent_access @endereco_cobranca = endereco_cobranca&.with_indifferent_access @cod_contribuinte = cod_contribuinte @ie = ie @situacao = situacao @fantasia = fantasia @financeiro = financeiro @pais = pais @tipos_contato = tipos_contato @pessoa_contato = pessoa_contato @vendedor = vendedor @dados_adicionais = dados_adicionais end |
Instance Attribute Details
#celular ⇒ Object (readonly)
Returns the value of attribute celular.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def celular @celular end |
#cod_contribuinte ⇒ Object (readonly)
Returns the value of attribute cod_contribuinte.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def cod_contribuinte @cod_contribuinte end |
#codigo ⇒ Object (readonly)
Returns the value of attribute codigo.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def codigo @codigo end |
#dados_adicionais ⇒ Object (readonly)
Returns the value of attribute dados_adicionais.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def dados_adicionais @dados_adicionais end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def email @email end |
#endereco ⇒ Object (readonly)
Returns the value of attribute endereco.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def endereco @endereco end |
#endereco_cobranca ⇒ Object (readonly)
Returns the value of attribute endereco_cobranca.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def endereco_cobranca @endereco_cobranca end |
#fantasia ⇒ Object (readonly)
Returns the value of attribute fantasia.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def fantasia @fantasia end |
#financeiro ⇒ Object (readonly)
Returns the value of attribute financeiro.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def financeiro @financeiro end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def id @id end |
#ie ⇒ Object (readonly)
Returns the value of attribute ie.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def ie @ie end |
#nome ⇒ Object (readonly)
Returns the value of attribute nome.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def nome @nome end |
#numero_documento ⇒ Object (readonly)
Returns the value of attribute numero_documento.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def numero_documento @numero_documento end |
#orgao_emissor ⇒ Object (readonly)
Returns the value of attribute orgao_emissor.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def orgao_emissor @orgao_emissor end |
#pais ⇒ Object (readonly)
Returns the value of attribute pais.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def pais @pais end |
#pessoa_contato ⇒ Object (readonly)
Returns the value of attribute pessoa_contato.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def pessoa_contato @pessoa_contato end |
#pessoa_juridica ⇒ Object (readonly)
Returns the value of attribute pessoa_juridica.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def pessoa_juridica @pessoa_juridica end |
#rg ⇒ Object (readonly)
Returns the value of attribute rg.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def rg @rg end |
#situacao ⇒ Object (readonly)
Returns the value of attribute situacao.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def situacao @situacao end |
#telefone ⇒ Object (readonly)
Returns the value of attribute telefone.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def telefone @telefone end |
#tipos_contato ⇒ Object (readonly)
Returns the value of attribute tipos_contato.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def tipos_contato @tipos_contato end |
#vendedor ⇒ Object (readonly)
Returns the value of attribute vendedor.
17 18 19 |
# File 'lib/bling_api/customer.rb', line 17 def vendedor @vendedor end |
Class Method Details
.build_hash(json_response) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/bling_api/customer.rb', line 111 def self.build_hash json_response { id: json_response["id"], nome: json_response["nome"], codigo: json_response["codigo"], situacao: json_response["situacao"], telefone: json_response["telefone"], celular: json_response["celular"], fantasia: json_response["fantasia"], pessoa_juridica: json_response["tipo"] == "J", numero_documento: json_response["numeroDocumento"], rg: json_response["rg"], orgao_emissor: json_response["orgaoEmissor"], cod_contribuinte: json_response["indicadorIe"], ie: json_response["ie"], email: json_response["email"], endereco: json_response["endereco"]["geral"], endereco_cobranca: json_response["endereco"]["cobranca"], vendedor: json_response["vendedor"], dados_adicionais: json_response["dadosAdicionais"], financeiro: json_response["financeiro"], pais: json_response["pais"], tipos_contato: json_response["tiposContato"], pessoa_contato: json_response["pessoaContato"] } end |
.find_by_id(id) ⇒ Object
12 13 14 15 |
# File 'lib/bling_api/customer.rb', line 12 def self.find_by_id id contact = Client.new(BlingApi.configuration.access_token).get_contact(id) new(**build_hash(contact)) end |
.find_by_tax_id(tax_id) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/bling_api/customer.rb', line 4 def self.find_by_tax_id tax_id response_json = Client.new(BlingApi.configuration.access_token).find_contact_by_document_number(tax_id) if response_json contact = Client.new(BlingApi.configuration.access_token).get_contact(response_json["id"]) new(**build_hash(contact)) end end |
Instance Method Details
#build_json ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/bling_api/customer.rb', line 43 def build_json { nome: nome, telefone: phone_formatted(telefone), codigo: codigo, celular: phone_formatted(celular), tipo: pessoa_juridica ? "J" : "F", indicadorIe: cod_contribuinte, ie: ie, numeroDocumento: numero_documento, orgaoEmissor: orgao_emissor, rg: rg, fantasia: fantasia, email: email, situacao: situacao, vendedor: vendedor, dadosAdicionais: dados_adicionais, pais: pais, tiposContato: tipos_contato, pessoaContato: pessoa_contato, financeiro: financeiro, endereco: { geral: { endereco: endereco["endereco"], cep: endereco["cep"], bairro: endereco["bairro"], municipio: endereco["municipio"], uf: endereco["uf"], numero: endereco["numero"], complemento: endereco["complemento"] }, cobranca: { endereco: endereco_cobranca["endereco"], cep: endereco_cobranca["cep"], bairro: endereco_cobranca["bairro"], municipio: endereco_cobranca["municipio"], uf: endereco_cobranca["uf"], numero: endereco_cobranca["numero"], complemento: endereco_cobranca["complemento"] } } } end |
#create ⇒ Object
101 102 103 104 |
# File 'lib/bling_api/customer.rb', line 101 def create response = Client.new(BlingApi.configuration.access_token).create_contact(JSON.dump(build_json)) self.class.find_by_id(response["id"]) end |
#phone_formatted(phone) ⇒ Object
106 107 108 109 |
# File 'lib/bling_api/customer.rb', line 106 def phone_formatted(phone) return "" unless phone phone.gsub(/^\+55/, "") end |
#update(attributes) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/bling_api/customer.rb', line 87 def update attributes attributes.each do |key, value| if key == :endereco || key == :endereco_cobranca value.each do |k, v| send(key)[k] = v end else instance_variable_set(:"@#{key}", value) end end Client.new(BlingApi.configuration.access_token).update_contact(id, JSON.dump(build_json)) self.class.find_by_id(id) end |