bling_api 0.1.10 → 0.1.11
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 +4 -4
- data/Gemfile.lock +44 -44
- data/README.md +37 -37
- data/lib/bling_api/customer.rb +99 -98
- data/lib/bling_api/order.rb +95 -95
- data/lib/bling_api/product.rb +28 -28
- data/lib/bling_api/version.rb +5 -5
- data/lib/bling_api.rb +30 -30
- data/lib/generators/bling_api/install/install_generator.rb +10 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27d162f29e177e25c375a3568e8f019c3090bc1e8e4365f2ba397e692d5d9af8
|
4
|
+
data.tar.gz: 8fa35e70e66a37e5f2f7fa0fd297c050ac631fc9ec2400d9ba3b1d1711d6db2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f9380ad598d6b0c6f9d105d13b3bd081f69e50a8dcc9819bcad9dcfb20940f081a0dd329ba96d76af8b23bef29c386c8a74e2e9e60e67d27c6d3c67d9a42099
|
7
|
+
data.tar.gz: 4030fb571a210cdce2a5aa82af18d24ee286ec729e9680defd93a2a4f10daf9b3475269450111507487f95d2ef128a8846aaf92cdf410a5d561b977414e9b103
|
data/Gemfile.lock
CHANGED
@@ -1,44 +1,44 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
bling_api (0.1.10)
|
5
|
-
ac
|
6
|
-
base64
|
7
|
-
|
8
|
-
GEM
|
9
|
-
remote: https://rubygems.org/
|
10
|
-
specs:
|
11
|
-
ac (0.1.1)
|
12
|
-
typhoeus
|
13
|
-
attr_extras (7.1.0)
|
14
|
-
base64 (0.2.0)
|
15
|
-
concurrent-ruby (1.2.2)
|
16
|
-
diff-lcs (1.5.0)
|
17
|
-
ethon (0.16.0)
|
18
|
-
ffi (>= 1.15.0)
|
19
|
-
ffi (1.16.3)
|
20
|
-
optimist (3.1.0)
|
21
|
-
patience_diff (1.2.0)
|
22
|
-
optimist (~> 3.0)
|
23
|
-
rake (13.1.0)
|
24
|
-
super_diff (0.10.0)
|
25
|
-
attr_extras (>= 6.2.4)
|
26
|
-
diff-lcs
|
27
|
-
patience_diff
|
28
|
-
tldr (0.9.5)
|
29
|
-
concurrent-ruby (~> 1.2)
|
30
|
-
super_diff (~> 0.10)
|
31
|
-
typhoeus (1.4.0)
|
32
|
-
ethon (>= 0.9.0)
|
33
|
-
|
34
|
-
PLATFORMS
|
35
|
-
arm64-darwin-22
|
36
|
-
x86_64-linux
|
37
|
-
|
38
|
-
DEPENDENCIES
|
39
|
-
bling_api!
|
40
|
-
rake (~> 13.0)
|
41
|
-
tldr
|
42
|
-
|
43
|
-
BUNDLED WITH
|
44
|
-
2.4.20
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bling_api (0.1.10)
|
5
|
+
ac
|
6
|
+
base64
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ac (0.1.1)
|
12
|
+
typhoeus
|
13
|
+
attr_extras (7.1.0)
|
14
|
+
base64 (0.2.0)
|
15
|
+
concurrent-ruby (1.2.2)
|
16
|
+
diff-lcs (1.5.0)
|
17
|
+
ethon (0.16.0)
|
18
|
+
ffi (>= 1.15.0)
|
19
|
+
ffi (1.16.3)
|
20
|
+
optimist (3.1.0)
|
21
|
+
patience_diff (1.2.0)
|
22
|
+
optimist (~> 3.0)
|
23
|
+
rake (13.1.0)
|
24
|
+
super_diff (0.10.0)
|
25
|
+
attr_extras (>= 6.2.4)
|
26
|
+
diff-lcs
|
27
|
+
patience_diff
|
28
|
+
tldr (0.9.5)
|
29
|
+
concurrent-ruby (~> 1.2)
|
30
|
+
super_diff (~> 0.10)
|
31
|
+
typhoeus (1.4.0)
|
32
|
+
ethon (>= 0.9.0)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
arm64-darwin-22
|
36
|
+
x86_64-linux
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
bling_api!
|
40
|
+
rake (~> 13.0)
|
41
|
+
tldr
|
42
|
+
|
43
|
+
BUNDLED WITH
|
44
|
+
2.4.20
|
data/README.md
CHANGED
@@ -1,37 +1,37 @@
|
|
1
|
-
# BlingApi
|
2
|
-
|
3
|
-
TODO: Delete this and the text below, and describe your gem
|
4
|
-
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bling_api`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add bling_api to your Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'bling_api'
|
13
|
-
```
|
14
|
-
|
15
|
-
Bundle your dependencies and run the installation generator:
|
16
|
-
|
17
|
-
```shell
|
18
|
-
bin/rails generate bling_api:install
|
19
|
-
```
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
TODO: Write usage instructions here
|
24
|
-
|
25
|
-
## Development
|
26
|
-
|
27
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
-
|
29
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
-
|
31
|
-
## Contributing
|
32
|
-
|
33
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bling_api.
|
34
|
-
|
35
|
-
## License
|
36
|
-
|
37
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
1
|
+
# BlingApi
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bling_api`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add bling_api to your Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'bling_api'
|
13
|
+
```
|
14
|
+
|
15
|
+
Bundle your dependencies and run the installation generator:
|
16
|
+
|
17
|
+
```shell
|
18
|
+
bin/rails generate bling_api:install
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bling_api.
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/bling_api/customer.rb
CHANGED
@@ -1,98 +1,99 @@
|
|
1
|
-
module BlingApi
|
2
|
-
class Customer
|
3
|
-
|
4
|
-
def self.find_by_tax_id tax_id
|
5
|
-
response_json = Client.new(BlingApi.configuration.access_token).find_contact_by_document_number(tax_id)
|
6
|
-
if response_json
|
7
|
-
contact = Client.new(BlingApi.configuration.access_token).get_contact(response_json["id"])
|
8
|
-
new(**build_hash(contact))
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.find_by_id id
|
13
|
-
contact = Client.new(BlingApi.configuration.access_token).get_contact(id)
|
14
|
-
new(**build_hash(contact))
|
15
|
-
end
|
16
|
-
|
17
|
-
attr_reader :nome, :pessoa_juridica, :telefone, :numero_documento, :id, :email, :endereco, :endereco_cobranca, :cod_contribuinte
|
18
|
-
def initialize(nome:, pessoa_juridica:, numero_documento:, id:nil, telefone:nil, email:nil, endereco:nil, endereco_cobranca:nil, cod_contribuinte:nil)
|
19
|
-
@id = id
|
20
|
-
@nome = nome
|
21
|
-
@pessoa_juridica = pessoa_juridica
|
22
|
-
@telefone = telefone
|
23
|
-
@numero_documento = numero_documento
|
24
|
-
@email = email
|
25
|
-
@endereco = endereco&.with_indifferent_access
|
26
|
-
@endereco_cobranca = endereco_cobranca&.with_indifferent_access
|
27
|
-
@cod_contribuinte = cod_contribuinte
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
"
|
34
|
-
"
|
35
|
-
"
|
36
|
-
"
|
37
|
-
"
|
38
|
-
"
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
"
|
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
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
1
|
+
module BlingApi
|
2
|
+
class Customer
|
3
|
+
|
4
|
+
def self.find_by_tax_id tax_id
|
5
|
+
response_json = Client.new(BlingApi.configuration.access_token).find_contact_by_document_number(tax_id)
|
6
|
+
if response_json
|
7
|
+
contact = Client.new(BlingApi.configuration.access_token).get_contact(response_json["id"])
|
8
|
+
new(**build_hash(contact))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find_by_id id
|
13
|
+
contact = Client.new(BlingApi.configuration.access_token).get_contact(id)
|
14
|
+
new(**build_hash(contact))
|
15
|
+
end
|
16
|
+
|
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:)
|
19
|
+
@id = id
|
20
|
+
@nome = nome
|
21
|
+
@pessoa_juridica = pessoa_juridica
|
22
|
+
@telefone = telefone
|
23
|
+
@numero_documento = numero_documento
|
24
|
+
@email = email
|
25
|
+
@endereco = endereco&.with_indifferent_access
|
26
|
+
@endereco_cobranca = endereco_cobranca&.with_indifferent_access
|
27
|
+
@cod_contribuinte = cod_contribuinte
|
28
|
+
@situacao = situacao
|
29
|
+
end
|
30
|
+
|
31
|
+
def build_json
|
32
|
+
{
|
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
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def update attributes
|
64
|
+
attributes.each do |key, value|
|
65
|
+
if key == :endereco || key == :endereco_cobranca
|
66
|
+
value.each do |k, v|
|
67
|
+
self.send(key)[k] = v
|
68
|
+
end
|
69
|
+
else
|
70
|
+
instance_variable_set("@#{key}", value)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
Client.new(BlingApi.configuration.access_token).update_contact(id, JSON.dump(build_json))
|
74
|
+
self.class.find_by_id(self.id)
|
75
|
+
end
|
76
|
+
|
77
|
+
def create
|
78
|
+
response = Client.new(BlingApi.configuration.access_token).create_contact(JSON.dump(build_json))
|
79
|
+
self.class.find_by_id(response["id"])
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def self.build_hash json_response
|
85
|
+
{
|
86
|
+
id: json_response["id"],
|
87
|
+
nome: json_response["nome"],
|
88
|
+
telefone: json_response["telefone"],
|
89
|
+
pessoa_juridica: json_response["tipo"] == "J",
|
90
|
+
numero_documento: json_response["numeroDocumento"],
|
91
|
+
cod_contribuinte: json_response["indicadorIe"],
|
92
|
+
email: json_response["email"],
|
93
|
+
endereco: json_response["endereco"]["geral"],
|
94
|
+
endereco_cobranca: json_response["endereco"]["cobranca"]
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
data/lib/bling_api/order.rb
CHANGED
@@ -1,96 +1,96 @@
|
|
1
|
-
module BlingApi
|
2
|
-
class Order
|
3
|
-
|
4
|
-
def self.find_by_id id
|
5
|
-
response = Client.new(BlingApi.configuration.access_token).get_order(id)
|
6
|
-
new(**build_hash(response))
|
7
|
-
end
|
8
|
-
|
9
|
-
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)
|
11
|
-
@id = id
|
12
|
-
@numero = numero
|
13
|
-
@id_contato = id_contato
|
14
|
-
@items = items
|
15
|
-
@parcelas = parcelas
|
16
|
-
@numero_loja = numero_loja
|
17
|
-
@data = data
|
18
|
-
@total_produtos = total_produtos
|
19
|
-
@total = total
|
20
|
-
@id_loja = id_loja
|
21
|
-
@numero_pedido_compra = numero_pedido_compra
|
22
|
-
@observacoes = observacoes
|
23
|
-
@observacoes_internas = observacoes_internas
|
24
|
-
@valor_desconto = valor_desconto
|
25
|
-
@id_categoria = id_categoria
|
26
|
-
@transporte = transporte
|
27
|
-
@id_vendedor = id_vendedor
|
28
|
-
@pessoa_juridica = pessoa_juridica
|
29
|
-
@numero_documento = numero_documento
|
30
|
-
end
|
31
|
-
|
32
|
-
def build_json
|
33
|
-
{
|
34
|
-
"numeroLoja": numero_loja,
|
35
|
-
"data": data,
|
36
|
-
"loja": {
|
37
|
-
"id": id_loja
|
38
|
-
},
|
39
|
-
"contato": {
|
40
|
-
"id": id_contato,
|
41
|
-
"tipoPessoa": pessoa_juridica ? "J" : "F",
|
42
|
-
"numeroDocumento": numero_documento
|
43
|
-
},
|
44
|
-
"itens": items,
|
45
|
-
"vendedor": {
|
46
|
-
"id": id_vendedor
|
47
|
-
},
|
48
|
-
"transporte": transporte,
|
49
|
-
"parcelas": parcelas,
|
50
|
-
"desconto": {
|
51
|
-
"valor": valor_desconto,
|
52
|
-
"unidade": "REAL"
|
53
|
-
},
|
54
|
-
"totalProdutos": total_produtos,
|
55
|
-
"total": total,
|
56
|
-
"observacoes": observacoes,
|
57
|
-
"observacoesInternas": observacoes_internas,
|
58
|
-
"categoria": {
|
59
|
-
"id": id_categoria
|
60
|
-
}
|
61
|
-
}
|
62
|
-
end
|
63
|
-
|
64
|
-
def create
|
65
|
-
response = Client.new(BlingApi.configuration.access_token).create_order(JSON.dump(build_json))
|
66
|
-
self.class.find_by_id(response["id"])
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
|
71
|
-
def self.build_hash json_response
|
72
|
-
{
|
73
|
-
id: json_response["id"],
|
74
|
-
id_contato: json_response["contato"]["id"],
|
75
|
-
pessoa_juridica: json_response.dig("contato", "tipoPessoa") == "J",
|
76
|
-
numero_documento: json_response.dig("contato", "numeroDocumento"),
|
77
|
-
items: json_response["itens"],
|
78
|
-
parcelas: json_response["parcelas"],
|
79
|
-
numero_loja: json_response["numeroLoja"],
|
80
|
-
numero: json_response["numero"],
|
81
|
-
data: json_response["data"],
|
82
|
-
total_produtos: json_response["totalProdutos"],
|
83
|
-
total: json_response["total"],
|
84
|
-
id_loja: json_response["loja"]["id"],
|
85
|
-
numero_pedido_compra: json_response["numeroPedidoCompra"],
|
86
|
-
observacoes: json_response["observacoes"],
|
87
|
-
observacoes_internas: json_response["observacoesInternas"],
|
88
|
-
valor_desconto: json_response["desconto"]["valor"],
|
89
|
-
id_categoria: json_response["categoria"]["id"],
|
90
|
-
transporte: json_response["transporte"],
|
91
|
-
id_vendedor: json_response["vendedor"]["id"]
|
92
|
-
}
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
1
|
+
module BlingApi
|
2
|
+
class Order
|
3
|
+
|
4
|
+
def self.find_by_id id
|
5
|
+
response = Client.new(BlingApi.configuration.access_token).get_order(id)
|
6
|
+
new(**build_hash(response))
|
7
|
+
end
|
8
|
+
|
9
|
+
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)
|
11
|
+
@id = id
|
12
|
+
@numero = numero
|
13
|
+
@id_contato = id_contato
|
14
|
+
@items = items
|
15
|
+
@parcelas = parcelas
|
16
|
+
@numero_loja = numero_loja
|
17
|
+
@data = data
|
18
|
+
@total_produtos = total_produtos
|
19
|
+
@total = total
|
20
|
+
@id_loja = id_loja
|
21
|
+
@numero_pedido_compra = numero_pedido_compra
|
22
|
+
@observacoes = observacoes
|
23
|
+
@observacoes_internas = observacoes_internas
|
24
|
+
@valor_desconto = valor_desconto
|
25
|
+
@id_categoria = id_categoria
|
26
|
+
@transporte = transporte
|
27
|
+
@id_vendedor = id_vendedor
|
28
|
+
@pessoa_juridica = pessoa_juridica
|
29
|
+
@numero_documento = numero_documento
|
30
|
+
end
|
31
|
+
|
32
|
+
def build_json
|
33
|
+
{
|
34
|
+
"numeroLoja": numero_loja,
|
35
|
+
"data": data,
|
36
|
+
"loja": {
|
37
|
+
"id": id_loja
|
38
|
+
},
|
39
|
+
"contato": {
|
40
|
+
"id": id_contato,
|
41
|
+
"tipoPessoa": pessoa_juridica ? "J" : "F",
|
42
|
+
"numeroDocumento": numero_documento
|
43
|
+
},
|
44
|
+
"itens": items,
|
45
|
+
"vendedor": {
|
46
|
+
"id": id_vendedor
|
47
|
+
},
|
48
|
+
"transporte": transporte,
|
49
|
+
"parcelas": parcelas,
|
50
|
+
"desconto": {
|
51
|
+
"valor": valor_desconto,
|
52
|
+
"unidade": "REAL"
|
53
|
+
},
|
54
|
+
"totalProdutos": total_produtos,
|
55
|
+
"total": total,
|
56
|
+
"observacoes": observacoes,
|
57
|
+
"observacoesInternas": observacoes_internas,
|
58
|
+
"categoria": {
|
59
|
+
"id": id_categoria
|
60
|
+
}
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def create
|
65
|
+
response = Client.new(BlingApi.configuration.access_token).create_order(JSON.dump(build_json))
|
66
|
+
self.class.find_by_id(response["id"])
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def self.build_hash json_response
|
72
|
+
{
|
73
|
+
id: json_response["id"],
|
74
|
+
id_contato: json_response["contato"]["id"],
|
75
|
+
pessoa_juridica: json_response.dig("contato", "tipoPessoa") == "J",
|
76
|
+
numero_documento: json_response.dig("contato", "numeroDocumento"),
|
77
|
+
items: json_response["itens"],
|
78
|
+
parcelas: json_response["parcelas"],
|
79
|
+
numero_loja: json_response["numeroLoja"],
|
80
|
+
numero: json_response["numero"],
|
81
|
+
data: json_response["data"],
|
82
|
+
total_produtos: json_response["totalProdutos"],
|
83
|
+
total: json_response["total"],
|
84
|
+
id_loja: json_response["loja"]["id"],
|
85
|
+
numero_pedido_compra: json_response["numeroPedidoCompra"],
|
86
|
+
observacoes: json_response["observacoes"],
|
87
|
+
observacoes_internas: json_response["observacoesInternas"],
|
88
|
+
valor_desconto: json_response["desconto"]["valor"],
|
89
|
+
id_categoria: json_response["categoria"]["id"],
|
90
|
+
transporte: json_response["transporte"],
|
91
|
+
id_vendedor: json_response["vendedor"]["id"]
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
96
|
end
|
data/lib/bling_api/product.rb
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
module BlingApi
|
2
|
-
class Product
|
3
|
-
|
4
|
-
def self.find_by_sku sku
|
5
|
-
response_json = Client.new(BlingApi.configuration.access_token).find_product_by_sku(sku)
|
6
|
-
if response_json
|
7
|
-
new(**build_hash(response_json))
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
attr_reader :id, :nome, :sku
|
12
|
-
def initialize(id:, nome:, sku:)
|
13
|
-
@id = id
|
14
|
-
@nome = nome
|
15
|
-
@sku = sku
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def self.build_hash json_response
|
21
|
-
{
|
22
|
-
id: json_response["id"],
|
23
|
-
nome: json_response["nome"],
|
24
|
-
sku: json_response["codigo"]
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
1
|
+
module BlingApi
|
2
|
+
class Product
|
3
|
+
|
4
|
+
def self.find_by_sku sku
|
5
|
+
response_json = Client.new(BlingApi.configuration.access_token).find_product_by_sku(sku)
|
6
|
+
if response_json
|
7
|
+
new(**build_hash(response_json))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :id, :nome, :sku
|
12
|
+
def initialize(id:, nome:, sku:)
|
13
|
+
@id = id
|
14
|
+
@nome = nome
|
15
|
+
@sku = sku
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def self.build_hash json_response
|
21
|
+
{
|
22
|
+
id: json_response["id"],
|
23
|
+
nome: json_response["nome"],
|
24
|
+
sku: json_response["codigo"]
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
29
|
end
|
data/lib/bling_api/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module BlingApi
|
4
|
-
VERSION = "0.1.
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BlingApi
|
4
|
+
VERSION = "0.1.11"
|
5
|
+
end
|
data/lib/bling_api.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "ac"
|
4
|
-
require "base64"
|
5
|
-
require "active_support/core_ext/hash/indifferent_access"
|
6
|
-
require_relative "bling_api/version"
|
7
|
-
require_relative "bling_api/client"
|
8
|
-
require_relative "bling_api/customer"
|
9
|
-
require_relative "bling_api/order"
|
10
|
-
require_relative "bling_api/product"
|
11
|
-
|
12
|
-
module BlingApi
|
13
|
-
class Error < StandardError; end
|
14
|
-
|
15
|
-
class Configuration
|
16
|
-
attr_accessor :access_token
|
17
|
-
|
18
|
-
def initialize
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class << self
|
23
|
-
attr_accessor :configuration
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.configure
|
27
|
-
self.configuration ||= Configuration.new
|
28
|
-
yield configuration
|
29
|
-
end
|
30
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ac"
|
4
|
+
require "base64"
|
5
|
+
require "active_support/core_ext/hash/indifferent_access"
|
6
|
+
require_relative "bling_api/version"
|
7
|
+
require_relative "bling_api/client"
|
8
|
+
require_relative "bling_api/customer"
|
9
|
+
require_relative "bling_api/order"
|
10
|
+
require_relative "bling_api/product"
|
11
|
+
|
12
|
+
module BlingApi
|
13
|
+
class Error < StandardError; end
|
14
|
+
|
15
|
+
class Configuration
|
16
|
+
attr_accessor :access_token
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class << self
|
23
|
+
attr_accessor :configuration
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.configure
|
27
|
+
self.configuration ||= Configuration.new
|
28
|
+
yield configuration
|
29
|
+
end
|
30
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module BlingApi
|
2
|
-
module Generators
|
3
|
-
class InstallGenerator < Rails::Generators::Base
|
4
|
-
source_root File.expand_path("templates", __dir__)
|
5
|
-
def copy_initializer
|
6
|
-
template "initializer.rb", "config/initializers/bling_api.rb"
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
1
|
+
module BlingApi
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("templates", __dir__)
|
5
|
+
def copy_initializer
|
6
|
+
template "initializer.rb", "config/initializers/bling_api.rb"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
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.
|
4
|
+
version: 0.1.11
|
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-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ac
|