bling_api 0.1.12 → 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: 3a9b0f526f08f2c5b00645fe1a2e3cdb0e76391af1c2e932a3d0114d2f167e48
4
- data.tar.gz: f2a89160bf223a8b706019331f2d4fc173afa38b0d9093ebc0c4b44e7e1598c4
3
+ metadata.gz: 88bb995ea4b968c75226590cc0a739d7a949741ec49cd0ee8cd9969423b8e3aa
4
+ data.tar.gz: da78e33666e15132b8237675b0920166e4620afc8261ec854f0000780db6388f
5
5
  SHA512:
6
- metadata.gz: e7b5e8cccc865d8a8dbc208259d94670bcfe52ea085282750780b81ca0a9bfe8799146d52c793d447cf035689a36692869e1f2dfa9adcc6fbc3c20ad0113db55
7
- data.tar.gz: 9a7b51430e21382ff55966ff1fa3bb060d433f32a995a130b24a0748ba6eade0ed46f0d9a968bf9fdc09517df4bb4b7eb8240282e2d40428c9146acca3071cd3
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"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bling_api (0.1.10)
4
+ bling_api (0.2.0)
5
5
  ac
6
6
  base64
7
7
 
@@ -2,56 +2,65 @@ 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
+ response.json["data"]
24
+ end
25
+
26
+ def get_seller(seller_id)
27
+ response = get("/vendedores/#{seller_id}") { _1.json["data"] }
28
+ response.json["data"]
29
+ end
30
+
31
+ def get_sellers(page, limit, situation)
32
+ response = get("/vendedores?pagina=#{page}&limite=#{limit}&situacaoContato=#{situation}") { _1.json["data"] }
23
33
  response.json["data"]
24
34
  end
25
35
 
26
36
  def find_contact_by_document_number(document_number)
27
- response = get("/contatos?numeroDocumento=#{document_number.gsub(/\D/, "")}") {_1.json["data"]}
37
+ response = get("/contatos?numeroDocumento=#{document_number.gsub(/\D/, "")}") { _1.json["data"] }
28
38
  response.json["data"].first
29
39
  end
30
40
 
31
41
  def find_product_by_sku(sku)
32
- response = get("/produtos?codigo=#{sku}") {_1.json["data"]}
42
+ response = get("/produtos?codigo=#{sku}") { _1.json["data"] }
33
43
  response.json["data"].first
34
44
  end
35
45
 
36
46
  def create_contact(body)
37
- response = post("/contatos", body: body, headers: @headers) {_1.json["data"]}
47
+ response = post("/contatos", body: body, headers: @headers) { _1.json["data"] }
38
48
  response.json["data"]
39
49
  end
40
50
 
41
51
  def create_order(body)
42
- response = post("/pedidos/vendas", body: body, headers: @headers) {_1.json["data"]}
52
+ response = post("/pedidos/vendas", body: body, headers: @headers) { _1.json["data"] }
43
53
  response.json["data"]
44
54
  end
45
55
 
46
56
  def refresh_token(client_id:, client_secret:, refresh_token:)
47
57
  headers = {
48
58
  "Content-Type": "application/x-www-form-urlencoded",
49
- "Authorization": "Basic #{Base64.strict_encode64("#{client_id}:#{client_secret}")}"
59
+ Authorization: "Basic #{Base64.strict_encode64("#{client_id}:#{client_secret}")}"
50
60
  }
51
61
  body = "grant_type=refresh_token&refresh_token=#{refresh_token}"
52
- 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"] }
53
63
  response.json
54
64
  end
55
-
56
65
  end
57
- end
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
@@ -0,0 +1,40 @@
1
+ module BlingApi
2
+ class Seller
3
+ def self.get_sellers page: 1, limit: 100, situation: "A"
4
+ sellers = Client.new(BlingApi.configuration.access_token).get_sellers(page, limit, situation)
5
+ build_hash_sellers(sellers)
6
+ end
7
+
8
+ def self.find_by_id id
9
+ seller = Client.new(BlingApi.configuration.access_token).get_seller(id)
10
+ new(**build_hash(seller))
11
+ end
12
+
13
+ def self.build_hash_sellers sellers
14
+ sellers.map do |seller|
15
+ {
16
+ id: seller.dig("id"),
17
+ nome: seller.dig("contato", "nome"),
18
+ situacao: seller.dig("contato", "situacao")
19
+ }
20
+ end
21
+ end
22
+
23
+ attr_reader :id, :nome, :situacao
24
+ def initialize(id:, nome:, situacao:)
25
+ @id = id
26
+ @nome = nome
27
+ @situacao = situacao
28
+ end
29
+
30
+ private
31
+
32
+ def self.build_hash json_response
33
+ {
34
+ id: json_response.dig("id"),
35
+ nome: json_response.dig("contato", "nome"),
36
+ situacao: json_response.dig("contato", "situacao")
37
+ }
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BlingApi
4
- VERSION = "0.1.12"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/bling_api.rb CHANGED
@@ -8,6 +8,7 @@ require_relative "bling_api/client"
8
8
  require_relative "bling_api/customer"
9
9
  require_relative "bling_api/order"
10
10
  require_relative "bling_api/product"
11
+ require_relative "bling_api/seller"
11
12
 
12
13
  module BlingApi
13
14
  class Error < StandardError; 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.1.12
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-14 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: []
@@ -55,6 +55,7 @@ files:
55
55
  - lib/bling_api/customer.rb
56
56
  - lib/bling_api/order.rb
57
57
  - lib/bling_api/product.rb
58
+ - lib/bling_api/seller.rb
58
59
  - lib/bling_api/version.rb
59
60
  - lib/generators/bling_api/install/install_generator.rb
60
61
  - lib/generators/bling_api/install/templates/initializer.rb
@@ -64,7 +65,7 @@ licenses:
64
65
  metadata:
65
66
  homepage_uri: https://github.com/CaioGarcia1
66
67
  source_code_uri: https://github.com/CaioGarcia1
67
- post_install_message:
68
+ post_install_message:
68
69
  rdoc_options: []
69
70
  require_paths:
70
71
  - lib
@@ -79,8 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
80
  - !ruby/object:Gem::Version
80
81
  version: '0'
81
82
  requirements: []
82
- rubygems_version: 3.4.6
83
- signing_key:
83
+ rubygems_version: 3.5.3
84
+ signing_key:
84
85
  specification_version: 4
85
86
  summary: ''
86
87
  test_files: []