bling_api 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -1
- data/README.md +101 -18
- data/lib/bling_api/client.rb +15 -10
- data/lib/bling_api/customer.rb +0 -2
- data/lib/bling_api/order.rb +0 -2
- data/lib/bling_api/product.rb +0 -2
- data/lib/bling_api/seller.rb +0 -2
- data/lib/bling_api/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 725280eed39d0e30e05931c9a9cc4728e7abc0a285b61f90c78a893098cfcdf6
|
4
|
+
data.tar.gz: 9a45a45083e53fd24515d3c83c5675364e6e071f933d568cfc03843b8c768ef1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc5a72286528d648629bd68e705d1079c295ce32e1b49aafc49c6995c47a07b276229fe8bd94edd5dcdf696ab710a2375108da1057ba656818689b98848a8f6e
|
7
|
+
data.tar.gz: cb8499a2c765182040e7754e94ecb27c8026f47a3192c9c43f04105f9545dd437302d4001118b9ff973e8b7a49336a8a5ca5d5bf59707728c54f13c8faf588ef
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,37 +1,120 @@
|
|
1
1
|
# BlingApi
|
2
2
|
|
3
|
-
|
3
|
+
Wrapper de integração com a API v3 do ERP Bling!.
|
4
4
|
|
5
|
-
|
5
|
+
[Documentação API v3 Bling!](https://developer.bling.com.br/bling-api)
|
6
6
|
|
7
|
-
|
7
|
+
### Funcionalidades:
|
8
|
+
- Clientes: create, update, find_by_id, find_by_tax_id (CPF/CNPJ)
|
9
|
+
- Pedido de venda: create, find_by_id
|
10
|
+
- Produtos: find_by_sku
|
11
|
+
- Vendedores: get_sellers (listagem), find_by_id
|
8
12
|
|
9
|
-
|
13
|
+
## Instalação
|
14
|
+
|
15
|
+
Adicionar bling_api no Gemfile:
|
10
16
|
|
11
17
|
```ruby
|
12
18
|
gem 'bling_api'
|
13
19
|
```
|
20
|
+
ou
|
21
|
+
```shell
|
22
|
+
bundle add bling_api
|
23
|
+
```
|
14
24
|
|
15
|
-
|
25
|
+
Instalar a gem:
|
16
26
|
|
17
27
|
```shell
|
18
28
|
bin/rails generate bling_api:install
|
19
29
|
```
|
20
30
|
|
21
|
-
##
|
22
|
-
|
23
|
-
TODO: Write usage instructions here
|
31
|
+
## Uso
|
24
32
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
## Contributing
|
33
|
+
Configurar access_token no initializer ou direto no código:
|
34
|
+
```ruby
|
35
|
+
BlingApi.configure do |config|
|
36
|
+
config.access_token = "ACCESS_TOKEN"
|
37
|
+
end
|
38
|
+
```
|
32
39
|
|
33
|
-
|
40
|
+
### Exemplos
|
34
41
|
|
35
|
-
|
42
|
+
#### Token
|
36
43
|
|
37
|
-
|
44
|
+
```ruby
|
45
|
+
api_client = BlingApi::Client.new.refresh_token(client_id: "123456", client_secret: "101112131415", refresh_token: "abcde12345")
|
46
|
+
#retorna o JSON da resposta
|
47
|
+
puts api_client["access_token"] # "a1b2c3d4e5"
|
48
|
+
puts api_client["expires_in"] # 21600
|
49
|
+
```
|
50
|
+
#### Produto
|
51
|
+
```ruby
|
52
|
+
# Encontrar um produto a partir do SKU
|
53
|
+
product = BlingApi::Product.find_by_sku("123456")
|
54
|
+
puts product.sku # "123456"
|
55
|
+
```
|
56
|
+
#### Pedido de venda
|
57
|
+
```ruby
|
58
|
+
# Instancia o objeto
|
59
|
+
order = BlingApi::Order.new(
|
60
|
+
id_contato: 16693257776,
|
61
|
+
items: [{
|
62
|
+
id: 16219735350,
|
63
|
+
quantidade: 1,
|
64
|
+
valor: 20.25,
|
65
|
+
produto: {
|
66
|
+
id: 16219735350
|
67
|
+
}
|
68
|
+
}],
|
69
|
+
parcelas: [{
|
70
|
+
dataVencimento: "2024-06-06",
|
71
|
+
valor: 20.25,
|
72
|
+
formaPagamento: {
|
73
|
+
id: 4776248
|
74
|
+
}
|
75
|
+
}],
|
76
|
+
numero_loja: "ABC-123",
|
77
|
+
data: "2024-06-06",
|
78
|
+
total_produtos: 20.25,
|
79
|
+
total: 20.25,
|
80
|
+
id_loja: 204683421,
|
81
|
+
numero_pedido_compra: "ABC-123",
|
82
|
+
observacoes: "Observação",
|
83
|
+
observacoes_internas: "Obervação interna",
|
84
|
+
valor_desconto: 0.00,
|
85
|
+
id_categoria: 14653794318,
|
86
|
+
transporte: {
|
87
|
+
fretePorConta: 1,
|
88
|
+
frete: 0.00,
|
89
|
+
quantidadeVolumes: 1,
|
90
|
+
contato: {
|
91
|
+
nome: "LOGISTICA S.A"
|
92
|
+
},
|
93
|
+
etiqueta: {
|
94
|
+
nome: "João da Silva",
|
95
|
+
endereco: "Rua da Saudade",
|
96
|
+
numero: "120",
|
97
|
+
complemento: "",
|
98
|
+
municipio: "São Paulo",
|
99
|
+
uf: "SP",
|
100
|
+
bairro: "Centro",
|
101
|
+
cep: "01002010",
|
102
|
+
nomePais: "Brasil"
|
103
|
+
},
|
104
|
+
volumes: [
|
105
|
+
{
|
106
|
+
servico: "SEDEX",
|
107
|
+
codigoRastreamento: ""
|
108
|
+
}
|
109
|
+
]
|
110
|
+
},
|
111
|
+
id_vendedor: 15596298834,
|
112
|
+
pessoa_juridica: false,
|
113
|
+
numero_documento: "123.123.123-87"
|
114
|
+
)
|
115
|
+
|
116
|
+
# Cria o pedido de venda
|
117
|
+
created_order = order.create
|
118
|
+
|
119
|
+
puts created_order.numero # 102030
|
120
|
+
```
|
data/lib/bling_api/client.rb
CHANGED
@@ -10,46 +10,46 @@ module BlingApi
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def update_contact(contact_id, body)
|
13
|
-
|
13
|
+
put("/contatos/#{contact_id}", body: body, headers: @headers) { |response| validate_response(response, "") }
|
14
14
|
end
|
15
15
|
|
16
16
|
def get_order(order_id)
|
17
|
-
response = get("/pedidos/vendas/#{order_id}") {
|
17
|
+
response = get("/pedidos/vendas/#{order_id}") { |response| validate_response(response, "data") }
|
18
18
|
response.json["data"]
|
19
19
|
end
|
20
20
|
|
21
21
|
def get_contact(contact_id)
|
22
|
-
response = get("/contatos/#{contact_id}") {
|
22
|
+
response = get("/contatos/#{contact_id}") { |response| validate_response(response, "data") }
|
23
23
|
response.json["data"]
|
24
24
|
end
|
25
25
|
|
26
26
|
def get_seller(seller_id)
|
27
|
-
response = get("/vendedores/#{seller_id}") {
|
27
|
+
response = get("/vendedores/#{seller_id}") { |response| validate_response(response, "data") }
|
28
28
|
response.json["data"]
|
29
29
|
end
|
30
30
|
|
31
31
|
def get_sellers(page, limit, situation)
|
32
|
-
response = get("/vendedores?pagina=#{page}&limite=#{limit}&situacaoContato=#{situation}") {
|
32
|
+
response = get("/vendedores?pagina=#{page}&limite=#{limit}&situacaoContato=#{situation}") { |response| validate_response(response, "data") }
|
33
33
|
response.json["data"]
|
34
34
|
end
|
35
35
|
|
36
36
|
def find_contact_by_document_number(document_number)
|
37
|
-
response = get("/contatos?numeroDocumento=#{document_number.gsub(/\D/, "")}") {
|
37
|
+
response = get("/contatos?numeroDocumento=#{document_number.gsub(/\D/, "")}") { |response| validate_response(response, "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}") {
|
42
|
+
response = get("/produtos?codigo=#{sku}") { |response| validate_response(response, "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) {
|
47
|
+
response = post("/contatos", body: body, headers: @headers) { |response| validate_response(response, "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) {
|
52
|
+
response = post("/pedidos/vendas", body: body, headers: @headers) { |response| validate_response(response, "data") }
|
53
53
|
response.json["data"]
|
54
54
|
end
|
55
55
|
|
@@ -59,8 +59,13 @@ module BlingApi
|
|
59
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) {
|
62
|
+
response = post("/oauth/token", body: body, headers: headers) { |response| validate_response(response, "refresh_token") }
|
63
63
|
response.json
|
64
64
|
end
|
65
|
+
|
66
|
+
def validate_response(response, required_response_key)
|
67
|
+
puts response.json unless response.success?
|
68
|
+
![500, 429].include?(response.code) || response.json.dig(*required_response_key)
|
69
|
+
end
|
65
70
|
end
|
66
71
|
end
|
data/lib/bling_api/customer.rb
CHANGED
data/lib/bling_api/order.rb
CHANGED
data/lib/bling_api/product.rb
CHANGED
data/lib/bling_api/seller.rb
CHANGED
data/lib/bling_api/version.rb
CHANGED
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: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- caio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ac
|
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '0'
|
82
82
|
requirements: []
|
83
|
-
rubygems_version: 3.5.
|
83
|
+
rubygems_version: 3.5.10
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: ''
|