bling_api 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b555184d85bd2868cae8cf4e87a26a11cecd56985e36036c85c42238e1e9f7e
4
- data.tar.gz: 192812d80aed357f1011193abc56e6593fbeaf63222a6e59f0bd6d7c56b1329b
3
+ metadata.gz: 88bb995ea4b968c75226590cc0a739d7a949741ec49cd0ee8cd9969423b8e3aa
4
+ data.tar.gz: da78e33666e15132b8237675b0920166e4620afc8261ec854f0000780db6388f
5
5
  SHA512:
6
- metadata.gz: d2c9bcee577fb4417ba47b9c64d60d5ed25da255627f58dd3ab96d7cae8331d857ed5ade00e521b9f903abd3e305a161d66d05584ed754bcc447665e59d92c8c
7
- data.tar.gz: 703fc27931310b047beb60bd19375a5a6c24dcf1cf53d646826a80400bc0e78b2f06f13959bd71720bbb025a550b52a31a0ae4d2058329cc51a1bc4ebce27e01
6
+ metadata.gz: 81a0fbc0e3ff7774182f165475c13d768ee26838bd42c83c0160536a0765bdf6c7f242b55129fa354b26c02ac90ab4214e24decc1525b6b7878d5e045639c840
7
+ data.tar.gz: dacf2bf50114acbcae008090ba57777eff587d46dadeb443af59f69736d536bcb926843aeeb6bbb4c4f680aa5ecfb51608794b058da2fc77142b3a14abb8c6c5
data/Gemfile CHANGED
@@ -6,4 +6,4 @@ source "https://rubygems.org"
6
6
  gemspec
7
7
 
8
8
  gem "rake", "~> 13.0"
9
- gem "tldr"
9
+ gem "tldr"
@@ -2,24 +2,24 @@ module BlingApi
2
2
  class Client < Ac::Base
3
3
  BASE_URL = "https://www.bling.com.br/Api/v3"
4
4
  attr_reader :access_token
5
- def initialize(access_token=nil)
5
+ def initialize(access_token = nil)
6
6
  @headers = {
7
7
  "Content-Type": "application/json"
8
8
  }
9
- super access_token
9
+ super(access_token)
10
10
  end
11
11
 
12
12
  def update_contact(contact_id, body)
13
- response = put("/contatos/#{contact_id}", body: body, headers: @headers){_1.code==204}
13
+ response = put("/contatos/#{contact_id}", body: body, headers: @headers) { _1.code == 204 }
14
14
  end
15
15
 
16
16
  def get_order(order_id)
17
- response = get("/pedidos/vendas/#{order_id}") {_1.json["data"]}
17
+ response = get("/pedidos/vendas/#{order_id}") { _1.json["data"] }
18
18
  response.json["data"]
19
19
  end
20
20
 
21
21
  def get_contact(contact_id)
22
- response = get("/contatos/#{contact_id}") {_1.json["data"]}
22
+ response = get("/contatos/#{contact_id}") { _1.json["data"] }
23
23
  response.json["data"]
24
24
  end
25
25
 
@@ -34,34 +34,33 @@ module BlingApi
34
34
  end
35
35
 
36
36
  def find_contact_by_document_number(document_number)
37
- response = get("/contatos?numeroDocumento=#{document_number.gsub(/\D/, "")}") {_1.json["data"]}
37
+ response = get("/contatos?numeroDocumento=#{document_number.gsub(/\D/, "")}") { _1.json["data"] }
38
38
  response.json["data"].first
39
39
  end
40
40
 
41
41
  def find_product_by_sku(sku)
42
- response = get("/produtos?codigo=#{sku}") {_1.json["data"]}
42
+ response = get("/produtos?codigo=#{sku}") { _1.json["data"] }
43
43
  response.json["data"].first
44
44
  end
45
45
 
46
46
  def create_contact(body)
47
- response = post("/contatos", body: body, headers: @headers) {_1.json["data"]}
47
+ response = post("/contatos", body: body, headers: @headers) { _1.json["data"] }
48
48
  response.json["data"]
49
49
  end
50
50
 
51
51
  def create_order(body)
52
- response = post("/pedidos/vendas", body: body, headers: @headers) {_1.json["data"]}
52
+ response = post("/pedidos/vendas", body: body, headers: @headers) { _1.json["data"] }
53
53
  response.json["data"]
54
54
  end
55
55
 
56
56
  def refresh_token(client_id:, client_secret:, refresh_token:)
57
57
  headers = {
58
58
  "Content-Type": "application/x-www-form-urlencoded",
59
- "Authorization": "Basic #{Base64.strict_encode64("#{client_id}:#{client_secret}")}"
59
+ Authorization: "Basic #{Base64.strict_encode64("#{client_id}:#{client_secret}")}"
60
60
  }
61
61
  body = "grant_type=refresh_token&refresh_token=#{refresh_token}"
62
- response = post("/oauth/token", body: body, headers: headers) {_1.json["refresh_token"]}
62
+ response = post("/oauth/token", body: body, headers: headers) { _1.json["refresh_token"] }
63
63
  response.json
64
64
  end
65
-
66
65
  end
67
66
  end
@@ -1,6 +1,5 @@
1
1
  module BlingApi
2
2
  class Customer
3
-
4
3
  def self.find_by_tax_id tax_id
5
4
  response_json = Client.new(BlingApi.configuration.access_token).find_contact_by_document_number(tax_id)
6
5
  if response_json
@@ -14,49 +13,59 @@ module BlingApi
14
13
  new(**build_hash(contact))
15
14
  end
16
15
 
17
- attr_reader :nome, :pessoa_juridica, :telefone, :numero_documento, :id, :email, :endereco, :endereco_cobranca, :cod_contribuinte, :situacao
18
- def initialize(nome:, pessoa_juridica:, numero_documento:, id:nil, telefone:nil, email:nil, endereco:nil, endereco_cobranca:nil, cod_contribuinte:nil, situacao:nil)
16
+ attr_reader :nome, :pessoa_juridica, :telefone, :celular, :numero_documento, :rg, :orgao_emissor, :id, :email, :endereco, :endereco_cobranca, :cod_contribuinte, :situacao, :ie, :fantasia
17
+ def initialize(nome:, 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)
19
18
  @id = id
20
19
  @nome = nome
21
20
  @pessoa_juridica = pessoa_juridica
22
21
  @telefone = telefone
22
+ @celular = celular
23
23
  @numero_documento = numero_documento
24
+ @orgao_emissor = orgao_emissor
25
+ @rg = rg
24
26
  @email = email
25
27
  @endereco = endereco&.with_indifferent_access
26
28
  @endereco_cobranca = endereco_cobranca&.with_indifferent_access
27
29
  @cod_contribuinte = cod_contribuinte
30
+ @ie = ie
28
31
  @situacao = situacao
32
+ @fantasia = fantasia
29
33
  end
30
-
34
+
31
35
  def build_json
32
36
  {
33
- "nome": nome,
34
- "telefone": telefone,
35
- "tipo": pessoa_juridica ? "J" : "F",
36
- "indicadorIe": cod_contribuinte,
37
- "numeroDocumento": numero_documento,
38
- "email": email,
39
- "situacao": situacao,
40
- "endereco": {
41
- "geral": {
42
- "endereco": endereco["endereco"],
43
- "cep": endereco["cep"],
44
- "bairro": endereco["bairro"],
45
- "municipio": endereco["municipio"],
46
- "uf": endereco["uf"],
47
- "numero": endereco["numero"],
48
- "complemento": endereco["complemento"]
49
- },
50
- "cobranca": {
51
- "endereco": endereco_cobranca["endereco"],
52
- "cep": endereco_cobranca["cep"],
53
- "bairro": endereco_cobranca["bairro"],
54
- "municipio": endereco_cobranca["municipio"],
55
- "uf": endereco_cobranca["uf"],
56
- "numero": endereco_cobranca["numero"],
57
- "complemento": endereco_cobranca["complemento"]
58
- }
37
+ nome: nome,
38
+ telefone: telefone,
39
+ celular: celular,
40
+ tipo: pessoa_juridica ? "J" : "F",
41
+ indicadorIe: cod_contribuinte,
42
+ ie: ie,
43
+ numeroDocumento: numero_documento,
44
+ orgaoEmissor: orgao_emissor,
45
+ rg: rg,
46
+ fantasia: fantasia,
47
+ email: email,
48
+ situacao: situacao,
49
+ endereco: {
50
+ geral: {
51
+ endereco: endereco["endereco"],
52
+ cep: endereco["cep"],
53
+ bairro: endereco["bairro"],
54
+ municipio: endereco["municipio"],
55
+ uf: endereco["uf"],
56
+ numero: endereco["numero"],
57
+ complemento: endereco["complemento"]
58
+ },
59
+ cobranca: {
60
+ endereco: endereco_cobranca["endereco"],
61
+ cep: endereco_cobranca["cep"],
62
+ bairro: endereco_cobranca["bairro"],
63
+ municipio: endereco_cobranca["municipio"],
64
+ uf: endereco_cobranca["uf"],
65
+ numero: endereco_cobranca["numero"],
66
+ complemento: endereco_cobranca["complemento"]
59
67
  }
68
+ }
60
69
  }
61
70
  end
62
71
 
@@ -64,14 +73,14 @@ module BlingApi
64
73
  attributes.each do |key, value|
65
74
  if key == :endereco || key == :endereco_cobranca
66
75
  value.each do |k, v|
67
- self.send(key)[k] = v
76
+ send(key)[k] = v
68
77
  end
69
78
  else
70
- instance_variable_set("@#{key}", value)
79
+ instance_variable_set(:"@#{key}", value)
71
80
  end
72
81
  end
73
82
  Client.new(BlingApi.configuration.access_token).update_contact(id, JSON.dump(build_json))
74
- self.class.find_by_id(self.id)
83
+ self.class.find_by_id(id)
75
84
  end
76
85
 
77
86
  def create
@@ -86,14 +95,18 @@ module BlingApi
86
95
  id: json_response["id"],
87
96
  nome: json_response["nome"],
88
97
  telefone: json_response["telefone"],
98
+ celular: json_response["celular"],
99
+ fantasia: json_response["fantasia"],
89
100
  pessoa_juridica: json_response["tipo"] == "J",
90
101
  numero_documento: json_response["numeroDocumento"],
102
+ rg: json_response["rg"],
103
+ orgao_emissor: json_response["orgaoEmissor"],
91
104
  cod_contribuinte: json_response["indicadorIe"],
105
+ ie: json_response["ie"],
92
106
  email: json_response["email"],
93
107
  endereco: json_response["endereco"]["geral"],
94
- endereco_cobranca: json_response["endereco"]["cobranca"]
108
+ endereco_cobranca: json_response["endereco"]["cobranca"]
95
109
  }
96
110
  end
97
-
98
111
  end
99
112
  end
@@ -1,13 +1,12 @@
1
1
  module BlingApi
2
2
  class Order
3
-
4
3
  def self.find_by_id id
5
4
  response = Client.new(BlingApi.configuration.access_token).get_order(id)
6
5
  new(**build_hash(response))
7
6
  end
8
7
 
9
8
  attr_reader :id, :numero, :id_contato, :items, :parcelas, :numero_loja, :data, :total_produtos, :total, :id_loja, :numero_pedido_compra, :observacoes, :observacoes_internas, :valor_desconto, :id_categoria, :transporte, :id_vendedor, :pessoa_juridica, :numero_documento
10
- def initialize(id:nil, numero:nil, id_contato:, items:, parcelas:nil, numero_loja:, data:, total_produtos:, total:, id_loja:, numero_pedido_compra:nil, observacoes:, observacoes_internas:, valor_desconto:, id_categoria:, transporte:nil, id_vendedor:, pessoa_juridica:nil, numero_documento:nil)
9
+ def initialize(id_contato:, items:, numero_loja:, data:, total_produtos:, total:, id_loja:, observacoes:, observacoes_internas:, valor_desconto:, id_categoria:, id_vendedor:, id: nil, numero: nil, parcelas: nil, numero_pedido_compra: nil, transporte: nil, pessoa_juridica: nil, numero_documento: nil)
11
10
  @id = id
12
11
  @numero = numero
13
12
  @id_contato = id_contato
@@ -31,32 +30,32 @@ module BlingApi
31
30
 
32
31
  def build_json
33
32
  {
34
- "numeroLoja": numero_loja,
35
- "data": data,
36
- "loja": {
37
- "id": id_loja
33
+ numeroLoja: numero_loja,
34
+ data: data,
35
+ loja: {
36
+ id: id_loja
38
37
  },
39
- "contato": {
40
- "id": id_contato,
41
- "tipoPessoa": pessoa_juridica ? "J" : "F",
42
- "numeroDocumento": numero_documento
38
+ contato: {
39
+ id: id_contato,
40
+ tipoPessoa: pessoa_juridica ? "J" : "F",
41
+ numeroDocumento: numero_documento
43
42
  },
44
- "itens": items,
45
- "vendedor": {
46
- "id": id_vendedor
43
+ itens: items,
44
+ vendedor: {
45
+ id: id_vendedor
47
46
  },
48
- "transporte": transporte,
49
- "parcelas": parcelas,
50
- "desconto": {
51
- "valor": valor_desconto,
52
- "unidade": "REAL"
47
+ transporte: transporte,
48
+ parcelas: parcelas,
49
+ desconto: {
50
+ valor: valor_desconto,
51
+ unidade: "REAL"
53
52
  },
54
- "totalProdutos": total_produtos,
55
- "total": total,
56
- "observacoes": observacoes,
57
- "observacoesInternas": observacoes_internas,
58
- "categoria": {
59
- "id": id_categoria
53
+ totalProdutos: total_produtos,
54
+ total: total,
55
+ observacoes: observacoes,
56
+ observacoesInternas: observacoes_internas,
57
+ categoria: {
58
+ id: id_categoria
60
59
  }
61
60
  }
62
61
  end
@@ -91,6 +90,5 @@ module BlingApi
91
90
  id_vendedor: json_response["vendedor"]["id"]
92
91
  }
93
92
  end
94
-
95
93
  end
96
- end
94
+ end
@@ -1,6 +1,5 @@
1
1
  module BlingApi
2
2
  class Product
3
-
4
3
  def self.find_by_sku sku
5
4
  response_json = Client.new(BlingApi.configuration.access_token).find_product_by_sku(sku)
6
5
  if response_json
@@ -24,6 +23,5 @@ module BlingApi
24
23
  sku: json_response["codigo"]
25
24
  }
26
25
  end
27
-
28
26
  end
29
- end
27
+ end
@@ -1,6 +1,5 @@
1
1
  module BlingApi
2
2
  class Seller
3
-
4
3
  def self.get_sellers page: 1, limit: 100, situation: "A"
5
4
  sellers = Client.new(BlingApi.configuration.access_token).get_sellers(page, limit, situation)
6
5
  build_hash_sellers(sellers)
@@ -10,7 +9,7 @@ module BlingApi
10
9
  seller = Client.new(BlingApi.configuration.access_token).get_seller(id)
11
10
  new(**build_hash(seller))
12
11
  end
13
-
12
+
14
13
  def self.build_hash_sellers sellers
15
14
  sellers.map do |seller|
16
15
  {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BlingApi
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -1,3 +1,3 @@
1
1
  BlingApi.configure do |config|
2
2
  config.access_token = nil
3
- end
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bling_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - caio
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-19 00:00:00.000000000 Z
11
+ date: 2024-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ac
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description:
41
+ description:
42
42
  email:
43
43
  - caioif4@gmail.com
44
44
  executables: []
@@ -65,7 +65,7 @@ licenses:
65
65
  metadata:
66
66
  homepage_uri: https://github.com/CaioGarcia1
67
67
  source_code_uri: https://github.com/CaioGarcia1
68
- post_install_message:
68
+ post_install_message:
69
69
  rdoc_options: []
70
70
  require_paths:
71
71
  - lib
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  version: '0'
82
82
  requirements: []
83
83
  rubygems_version: 3.5.3
84
- signing_key:
84
+ signing_key:
85
85
  specification_version: 4
86
86
  summary: ''
87
87
  test_files: []