tiny_erp_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 87d1791e377b8c2f57e08ee91850114bdc119b38e3e889aeca17cca0f38378ae
4
+ data.tar.gz: 274c33c3895a9dec42dcafe6786b1446380b6a515c0d7f566432d6e879244b4b
5
+ SHA512:
6
+ metadata.gz: 4ff93da0d3ab651b7f08f5e7cfc7970935bf0e6bfbc3db305ae415465690021f5dbf681f14388a07aa6f469af9d98aa41593f7123445394304c978628fcf8331
7
+ data.tar.gz: eaf77c441135536574095bfc405b9e6b393c8950621fa139992cdcdf440df820d013397fed4cf7b1d2477db2f8e3b313b7f6abaf914dd8898c371eca536b55a3
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-05-06
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at hamiltontubo@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Hamilton Tumenas Borges
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # TinyErpApi
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/tiny_erp_api`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ 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.
26
+
27
+ 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).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tiny_erp_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/tiny_erp_api/blob/main/CODE_OF_CONDUCT.md).
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
36
+
37
+ ## Code of Conduct
38
+
39
+ Everyone interacting in the TinyErpApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/tiny_erp_api/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,10 @@
1
+ module TinyErpApi
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
@@ -0,0 +1,3 @@
1
+ TinyErpApi.configure do |config|
2
+ config.access_token = nil
3
+ end
@@ -0,0 +1,78 @@
1
+ module TinyErpApi
2
+ class Client < Ac::Base
3
+ BASE_URL = "https://api.tiny.com.br/api2"
4
+ attr_reader :access_token, :query_params
5
+
6
+ def initialize(access_token = nil)
7
+ @access_token = access_token || TinyErpApi.configuration.access_token
8
+ @query_params = "token=#{@access_token}&formato=JSON"
9
+ super()
10
+ end
11
+
12
+ # Contacts
13
+ def get_contact_by_document(document_number)
14
+ params = "#{@query_params}&cnpj_cpf=#{document_number}"
15
+ response = get("/contatos.pesquisa.php?#{params}")
16
+ response.json["retorno"]["contatos"][0]
17
+ end
18
+
19
+ def get_contact_by_id(contact_id)
20
+ params = "#{@query_params}&id=#{contact_id}"
21
+ response = get("/contato.obter.php?#{params}")
22
+ response.json["retorno"]["contato"]
23
+ end
24
+
25
+ def create_contact(contact)
26
+ params = "#{@query_params}&contato=#{URI.encode_www_form_component(contact.to_json)}"
27
+ response = post("/contato.incluir.php?#{params}")
28
+ response.json["retorno"]["registros"][0]["registro"]
29
+ end
30
+
31
+ def update_contact(contact_id)
32
+ params = "#{@query_params}&contato=#{contact_id}"
33
+ response = post("/contato.alterar.php?#{params}")
34
+ response.json["retorno"]["registros"][0]["registro"]
35
+ end
36
+
37
+ # Sellers
38
+ def get_sellers(page = 1)
39
+ params = "#{@query_params}&pagina=#{page}pesquisa="
40
+ response = post("/vendedores.pesquisa.php?#{params}")
41
+ response.json["retorno"]
42
+ end
43
+
44
+ def get_seller_by_name(seller_name)
45
+ params = "#{@query_params}&pesquisa=#{URI.encode_www_form_component(seller_name)}"
46
+ response = post("/vendedores.pesquisa.php?#{params}")
47
+ response.json["retorno"]["vendedores"][0]["vendedor"]
48
+ end
49
+
50
+ # Products
51
+ def get_product_by_sku(sku)
52
+ params = "#{@query_params}&pesquisa=#{URI.encode_www_form_component(sku)}"
53
+ response = post("/produtos.pesquisa.php?#{params}")
54
+ response.json["retorno"]["produtos"][0]
55
+ end
56
+
57
+ def get_product_by_id(product_id)
58
+ params = "#{@query_params}&id=#{product_id}"
59
+ response = post("/produto.obter.php?#{params}")
60
+ response.json["retorno"]["produto"]
61
+ end
62
+
63
+ # Orders
64
+ def get_order_by_id(order_id)
65
+ params = "#{@query_params}&id=#{order_id}"
66
+ response = post("/pedido.obter.php?#{params}")
67
+ response.json["retorno"]["pedido"]
68
+ end
69
+
70
+ def create_order(order)
71
+ params = "#{@query_params}&pedido=#{URI.encode_www_form_component(order)}"
72
+ response = post("/pedido.incluir.php?#{params}")
73
+ response.json["retorno"]["registros"][0]["registro"]
74
+ end
75
+
76
+
77
+ end
78
+ end
@@ -0,0 +1,106 @@
1
+ module TinyErpApi
2
+ class Customer
3
+ attr_reader :id, :codigo, :nome, :fantasia, :tipo_pessoa, :cpf_cnpj, :ie, :rg, :im, :tipo_negocio, :endereco, :endereco_cobranca, :contatos, :fone, :fax, :celular, :email, :email_nfe, :site, :crt, :limite_credito, :situacao, :obs, :id_lista_preco, :id_vendedor, :tipos_contato, :pessoas_contato
4
+
5
+ def initialize(id: nil, codigo: nil, nome: nil, fantasia: nil, tipo_pessoa: nil, cpf_cnpj: nil, ie: nil, rg: nil, im: nil, tipo_negocio: nil, endereco: nil, endereco_cobranca: nil, contatos: nil, fone: nil, fax: nil, celular: nil, email: nil, email_nfe: nil, site: nil, crt: nil, limite_credito: nil, situacao: nil, obs: nil, id_lista_preco: nil, id_vendedor: nil, tipos_contato: nil, pessoas_contato: nil)
6
+ @id = id
7
+ @codigo = codigo
8
+ @nome = nome
9
+ @fantasia = fantasia
10
+ @tipo_pessoa = tipo_pessoa
11
+ @cpf_cnpj = cpf_cnpj
12
+ @ie = ie
13
+ @rg = rg
14
+ @im = im
15
+ @tipo_negocio = tipo_negocio
16
+ @endereco = endereco
17
+ @endereco_cobranca = endereco_cobranca
18
+ @contatos = contatos
19
+ @fone = fone
20
+ @fax = fax
21
+ @celular = celular
22
+ @email = email
23
+ @email_nfe = email_nfe
24
+ @site = site
25
+ @crt = crt
26
+ @limite_credito = limite_credito
27
+ @situacao = situacao
28
+ @obs = obs
29
+ @id_lista_preco = id_lista_preco
30
+ @id_vendedor = id_vendedor
31
+ @tipos_contato = tipos_contato
32
+ @pessoas_contato = pessoas_contato
33
+ end
34
+
35
+ def self.find_by(id)
36
+ contact = Client.new.get_contact_by_id(response_json["id"])
37
+ new(**build_hash(contact))
38
+ end
39
+
40
+ def self.find_by_document(document)
41
+ response_json = Client.new.get_contact_by_document(document)
42
+ if response_json
43
+ contact = Client.new.get_contact_by_id(response_json["id"])
44
+ end
45
+ new(**build_hash(contact))
46
+ end
47
+
48
+ def self.create(params)
49
+
50
+ end
51
+
52
+ def self.update(params)
53
+
54
+ end
55
+
56
+ def self.build_hash(json_response)
57
+ {
58
+ id: json_response["id"],
59
+ codigo: "codigo",
60
+ nome: json_response["nome"],
61
+ fantasia: json_response["fantasia"],
62
+ tipo_pessoa: json_response["tipo_pessoa"],
63
+ cpf_cnpj: json_response["cpf_cnpj"],
64
+ ie: json_response["ie"],
65
+ rg: json_response["rg"],
66
+ im: json_response["im"],
67
+ tipo_negocio: json_response["tipo_negocio"],
68
+ endereco: {
69
+ endereco: json_response["endereco"],
70
+ numero: json_response["numero"],
71
+ complemento: json_response["complemento"],
72
+ bairro: json_response["bairro"],
73
+ cep: json_response["cep"],
74
+ cidade: json_response["cidade"],
75
+ uf: json_response["uf"],
76
+ pais: json_response["pais"],
77
+ },
78
+ endereco_cobranca: {
79
+ endereco: json_response["endereco_cobranca"],
80
+ numero: json_response["numero_cobranca"],
81
+ complemento: json_response["complemento_cobranca"],
82
+ bairro: json_response["bairro_cobranca"],
83
+ cep: json_response["cep_cobranca"],
84
+ cidade: json_response["cidade_cobranca"],
85
+ uf: json_response["uf_cobranca"],
86
+ },
87
+ contatos: json_response["contatos"],
88
+ fone: json_response["fone"],
89
+ fax: json_response["fax"],
90
+ celular: json_response["celular"],
91
+ email: json_response["email"],
92
+ email_nfe: json_response["email_nfe"],
93
+ site: json_response["site"],
94
+ crt: json_response["crt"],
95
+ limite_credito: json_response["limite_credito"],
96
+ situacao: json_response["situacao"],
97
+ obs: json_response["obs"],
98
+ id_lista_preco: json_response["id_lista_preco"],
99
+ id_vendedor: json_response["id_vendedor"],
100
+ nome_vendedor: json_response["nome_vendedor"],
101
+ tipos_contato: json_response["tipos_contato"],
102
+ pessoas_contato: json_response["pessoas_contato"]
103
+ }
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,87 @@
1
+ module TinyErpApi
2
+ class Order
3
+
4
+ attr_reader :id, :data_pedido, :transportador, :forma_pagamento, :valor_frete, :valor_desconto, :numero_pedido, :observacoes, :observacoes_internas, :forma_envio, :form_frete, :parcelas, :cliente, :itens, :ecommerce, :id_vendedor, :atualizar_cliente, :deposito, :id_natureza_operacao
5
+
6
+ def initialize(id: nil, data_pedido: nil, transportador: nil, forma_pagamento: nil, valor_frete: nil, valor_desconto: nil, numero_pedido: nil, observacoes: nil, observacoes_internas: nil, forma_envio: nil, form_frete: nil, parcelas: nil, cliente:, itens:, ecommerce: nil, id_vendedor: nil, atualizar_cliente: true, deposito: nil, id_natureza_operacao: nil)
7
+ @id = id
8
+ @data_pedido = data_pedido
9
+ @transportador = transportador
10
+ @forma_pagamento = forma_pagamento
11
+ @valor_frete = valor_frete
12
+ @valor_desconto = valor_desconto
13
+ @numero_pedido = numero_pedido
14
+ @observacoes = observacoes
15
+ @observacoes_internas = observacoes_internas
16
+ @forma_envio = forma_envio
17
+ @form_frete = form_frete
18
+ @parcelas = parcelas
19
+ @cliente = cliente
20
+ @itens = itens
21
+ @ecommerce = ecommerce
22
+ @id_vendedor = id_vendedor
23
+ @atualizar_cliente = atualizar_cliente
24
+ @deposito = deposito
25
+ @id_natureza_operacao = id_natureza_operacao
26
+ end
27
+
28
+ def self.find_by_id(order_id)
29
+ response_json = Client.new(TinyErpApi.configuration.access_token).get_order_by_id(order_id)
30
+ new(**build_hash(response_json))
31
+ end
32
+
33
+ def create(params)
34
+ response = Client.new(TinyErpApi.configuration.access_token).create_order(build_json)
35
+ self.class.find_by_id(response["retorno"]["registros"]["registro"]["id"])
36
+ end
37
+
38
+ def build_json
39
+ {
40
+ pedido: {
41
+ data_pedido: data_pedido,
42
+ nome_transportador: transportador,
43
+ forma_pagamento: forma_pagamento,
44
+ valor_frete: valor_frete,
45
+ valor_desconto: valor_desconto,
46
+ numero_pedido_ecommerce: numero_pedido,
47
+ obs: observacoes,
48
+ obs_internas: observacoes_internas,
49
+ forma_envio: forma_envio,
50
+ forma_frete: form_frete,
51
+ parcelas: parcelas,
52
+ cliente: cliente,
53
+ itens: itens,
54
+ ecommerce: ecommerce,
55
+ id_vendedor: id_vendedor,
56
+ atualizar_cliente: atualizar_cliente,
57
+ deposito: deposito,
58
+ id_natureza_operacao: id_natureza_operacao
59
+ }
60
+ }
61
+ end
62
+
63
+ def self.build_hash json_response
64
+ {
65
+ id: json_response["id"],
66
+ data_pedido: json_response["data_pedido"],
67
+ transportador: json_response["nome_transportador"],
68
+ forma_pagamento: json_response["forma_pagamento"],
69
+ valor_frete: json_response["valor_frete"],
70
+ valor_desconto: json_response["valor_desconto"],
71
+ numero_pedido: json_response["numero_pedido_ecommerce"],
72
+ observacoes: json_response["obs"],
73
+ observacoes_internas: json_response["obs_internas"],
74
+ forma_envio: json_response["forma_envio"],
75
+ form_frete: json_response["forma_frete"],
76
+ parcelas: json_response["parcelas"],
77
+ cliente: json_response["cliente"],
78
+ itens: json_response["itens"],
79
+ ecommerce: json_response["ecommerce"],
80
+ id_vendedor: json_response["id_vendedor"],
81
+ deposito: json_response["deposito"],
82
+ id_natureza_operacao: json_response["id_natureza_operacao"]
83
+ }
84
+ end
85
+
86
+ end
87
+ end
@@ -0,0 +1,52 @@
1
+ module TinyErpApi
2
+ class Product
3
+
4
+ attr_reader :id, :data_criacao, :nome, :codigo, :preco, :preco_promocional, :unidade, :gtin, :tipoVariacao, :localizacao, :preco_custo, :preco_custo_medio, :situacao
5
+
6
+ def initialize(id: nil, data_criacao: nil, nome: nil, codigo: nil, preco: nil, preco_promocional: nil, unidade: nil, gtin: nil, tipoVariacao: nil, localizacao: nil, preco_custo: nil, preco_custo_medio: nil, situacao: nil)
7
+ @id = id
8
+ @data_criacao = data_criacao
9
+ @nome = nome
10
+ @codigo = codigo
11
+ @preco = preco
12
+ @preco_promocional = preco_promocional
13
+ @unidade = unidade
14
+ @gtin = gtin
15
+ @tipoVariacao = tipoVariacao
16
+ @localizacao = localizacao
17
+ @preco_custo = preco_custo
18
+ @preco_custo_medio = preco_custo_medio
19
+ @situacao = situacao
20
+ end
21
+
22
+ def self.find_by_sku(sku)
23
+ response_json = Client.new(TinyErpApi.configuration.access_token).get_product_by_sku(sku)
24
+ if response_json["produto"]
25
+ new(**build_hash(response_json["produto"]))
26
+ end
27
+ end
28
+
29
+ def self.get_product_by_id(product_id)
30
+ response_json = Client.new(TinyErpApi.configuration.access_token).get_product_by_id(product_id)
31
+ new(**build_hash(response_json))
32
+ end
33
+
34
+ def self.build_hash(response_json)
35
+ {
36
+ id: response_json["id"],
37
+ data_criacao: response_json["data_criacao"],
38
+ nome: response_json["nome"],
39
+ codigo: response_json["codigo"],
40
+ preco: response_json["preco"],
41
+ preco_promocional: response_json["preco_promocional"],
42
+ unidade: response_json["unidade"],
43
+ gtin: response_json["gtin"],
44
+ tipoVariacao: response_json["tipoVariacao"],
45
+ localizacao: response_json["localizacao"],
46
+ preco_custo: response_json["preco_custo"],
47
+ preco_custo_medio: response_json["preco_custo_medio"],
48
+ situacao: response_json["situacao"]
49
+ }
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,82 @@
1
+ module TinyErpApi
2
+ class Seller
3
+ attr_reader :id, :codigo, :nome, :fantasia, :tipo_pessoa, :cpf_cnpj, :email, :endereco, :numero, :complemento, :bairro, :cep, :cidade, :uf, :situacao
4
+
5
+ def initialize(id: nil, codigo: nil, nome: nil, fantasia: nil, tipo_pessoa: nil, cpf_cnpj: nil, email: nil, endereco: nil, numero: nil, complemento: nil, bairro: nil, cep: nil, cidade: nil, uf: nil, situacao: nil)
6
+ @id = id
7
+ @codigo = codigo
8
+ @nome = nome
9
+ @fantasia = fantasia
10
+ @tipo_pessoa = tipo_pessoa
11
+ @cpf_cnpj = cpf_cnpj
12
+ @email = email
13
+ @endereco = endereco
14
+ @numero = numero
15
+ @complemento = complemento
16
+ @bairro = bairro
17
+ @cep = cep
18
+ @cidade = cidade
19
+ @uf = uf
20
+ @situacao = situacao
21
+ end
22
+
23
+ def self.get_all
24
+ response_json = Client.new(TinyErpApi.configuration.access_token).get_sellers
25
+ sellers = response_json["vendedores"]
26
+ if response_json["numero_paginas"] > 1
27
+ (2..response_json["numero_paginas"]).each do |page|
28
+ response_json = Client.new(TinyErpApi.configuration.access_token).get_sellers(page)
29
+ sellers >> response_json["vendedores"]
30
+ end
31
+ end
32
+ build_hash_sellers(sellers)
33
+ end
34
+
35
+ def self.find_by_name(name)
36
+ response_json = Client.new(TinyErpApi.configuration.access_token).get_seller_by_name(name)
37
+ new(**build_hash_seller(response_json))
38
+ end
39
+
40
+ def self.build_hash_sellers sellers
41
+ sellers.map do |seller|
42
+ {
43
+ id: seller["vendedor"]["id"],
44
+ codigo: seller["vendedor"]["codigo"],
45
+ nome: seller["vendedor"]["nome"],
46
+ fantasia: seller["vendedor"]["fantasia"],
47
+ tipo_pessoa: seller["vendedor"]["tipo_pessoa"],
48
+ cpf_cnpj: seller["vendedor"]["cpf_cnpj"],
49
+ email: seller["vendedor"]["email"],
50
+ endereco: seller["vendedor"]["endereco"],
51
+ numero: seller["vendedor"]["numero"],
52
+ complemento: seller["vendedor"]["complemento"],
53
+ bairro: seller["vendedor"]["bairro"],
54
+ cep: seller["vendedor"]["cep"],
55
+ cidade: seller["vendedor"]["cidade"],
56
+ uf: seller["vendedor"]["uf"],
57
+ situacao: seller["vendedor"]["situacao"]
58
+ }
59
+ end
60
+ end
61
+
62
+ def self.build_hash_seller response_json
63
+ {
64
+ id: response_json["id"],
65
+ codigo: response_json["codigo"],
66
+ nome: response_json["nome"],
67
+ fantasia: response_json["fantasia"],
68
+ tipo_pessoa: response_json["tipo_pessoa"],
69
+ cpf_cnpj: response_json["cpf_cnpj"],
70
+ email: response_json["email"],
71
+ endereco: response_json["endereco"],
72
+ numero: response_json["numero"],
73
+ complemento: response_json["complemento"],
74
+ bairro: response_json["bairro"],
75
+ cep: response_json["cep"],
76
+ cidade: response_json["cidade"],
77
+ uf: response_json["uf"],
78
+ situacao: response_json["situacao"]
79
+ }
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TinyErpApi
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ac"
4
+ require_relative "tiny_erp_api/version"
5
+ require_relative "tiny_erp_api/client"
6
+ require_relative "tiny_erp_api/customer"
7
+ require_relative "tiny_erp_api/order"
8
+ require_relative "tiny_erp_api/product"
9
+ require_relative "tiny_erp_api/seller"
10
+
11
+ module TinyErpApi
12
+ class Error < StandardError; end
13
+
14
+ class Configuration
15
+ attr_accessor :access_token
16
+
17
+ def initialize
18
+ end
19
+ end
20
+
21
+ class << self
22
+ attr_accessor :configuration
23
+ end
24
+
25
+ def self.configure
26
+ self.configuration ||= Configuration.new
27
+ yield configuration
28
+ end
29
+
30
+ end
@@ -0,0 +1,4 @@
1
+ module TinyErpApi
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tiny_erp_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hamilton Tumenas Borges
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ac
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - hamiltontubo@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CHANGELOG.md
35
+ - CODE_OF_CONDUCT.md
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - generators/tiny_erp_api/install/install_generator.rb
40
+ - generators/tiny_erp_api/install/templates/initalizer.rb
41
+ - lib/tiny_erp_api.rb
42
+ - lib/tiny_erp_api/client.rb
43
+ - lib/tiny_erp_api/customer.rb
44
+ - lib/tiny_erp_api/order.rb
45
+ - lib/tiny_erp_api/product.rb
46
+ - lib/tiny_erp_api/seller.rb
47
+ - lib/tiny_erp_api/version.rb
48
+ - sig/tiny_erp_api.rbs
49
+ homepage: https://github.com/hamiltontborges
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ homepage_uri: https://github.com/hamiltontborges
54
+ source_code_uri: https://github.com/hamiltontborges/tiny_erp_api
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 3.3.0
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubygems_version: 3.5.3
71
+ signing_key:
72
+ specification_version: 4
73
+ summary: Gem to interact with Tiny ERP API.
74
+ test_files: []