tinyerp_ruby 0.3.0
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 +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.travis.yml +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/Rakefile +1 -0
- data/lib/tinyerp_ruby/connection.rb +11 -0
- data/lib/tinyerp_ruby/poster.rb +36 -0
- data/lib/tinyerp_ruby/service.rb +30 -0
- data/lib/tinyerp_ruby/version.rb +3 -0
- data/lib/tinyerp_ruby.rb +14 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/vcr/TinyerpRuby_Poster/_call/output_a_hash.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Poster/_call/output_keys_as_symbols.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_alterar_contato_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_alterar_contato_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_alterar_grupo_tag_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_alterar_grupo_tag_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_alterar_produto_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_alterar_produto_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_alterar_tag_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_alterar_tag_xml_as_a_valid_service.yml +1581 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_gerar_ordem_produca_pedido_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_incluir_contato_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_incluir_contato_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_incluir_contrato_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_incluir_contrato_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_incluir_grupo_tag_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_incluir_grupo_tag_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_incluir_nota_fiscal_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_incluir_nota_fiscal_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_incluir_nota_servico_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_incluir_nota_servico_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_incluir_pedido_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_incluir_pedido_xml_as_a_valid_service.yml +1581 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_incluir_produto_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_incluir_produto_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_incluir_tag_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_incluir_tag_xml_as_a_valid_service.yml +1581 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_lista_atualizacoes_estoque_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_lista_atualizacoes_estoque_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_lista_atualizacoes_produtos_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_lista_atualizacoes_produtos_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_contato_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_contato_xml_as_a_valid_service.yml +1581 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_contrato_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_contrato_xml_as_a_valid_service.yml +1581 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_estoque_produto_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_estoque_produto_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_estrutura_produto_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_estrutura_produto_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_nota_fiscal_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_nota_fiscal_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_nota_servico_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_nota_servico_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_pedido_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_pedido_xml_as_a_valid_service.yml +1581 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_produto_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_produto_xml_as_a_valid_service.yml +1581 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_tags_produto_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_tags_produto_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_obter_xml_nota_fiscal_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_pesquisar_contatos_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_pesquisar_contatos_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_pesquisar_contratos_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_pesquisar_contratos_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_pesquisar_grupos_tag_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_pesquisar_grupos_tag_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_pesquisar_notas_fiscais_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_pesquisar_notas_fiscais_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_pesquisar_notas_servico_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_pesquisar_notas_servico_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_pesquisar_pedidos_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_pesquisar_pedidos_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_pesquisar_produtos_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_pesquisar_produtos_xml_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_pesquisar_tag_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_pesquisar_tag_xml_as_a_valid_service.yml +1581 -0
- data/spec/support/vcr/TinyerpRuby_Service/accepts/_pesquisar_vendedores_service_as_a_valid_service.yml +1582 -0
- data/spec/support/vcr.rb +8 -0
- data/spec/tinyerp_ruby/connection_spec.rb +43 -0
- data/spec/tinyerp_ruby/poster_spec.rb +20 -0
- data/spec/tinyerp_ruby/service_spec.rb +47 -0
- data/tinyerp_ruby.gemspec +28 -0
- metadata +285 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 0ec70d0fb1f61b45caf432e187c1a6a09a02a248
|
|
4
|
+
data.tar.gz: 1cf63c259c6c9e6e74c67a7b03a6fda76bf31705
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: fa9c2a76c29646ff6a1aab5cc6be05b6622af5976db9749b34f22d74f061d61296c5ae59e20fdcb3afefd6b4e589ef77f1188bd578e8e7ca972284e994dcabe7
|
|
7
|
+
data.tar.gz: b61ccca8e3ecacfd00d8894872c3d641742387226288d920ec1ea24fb28d268eee2373f871a126bb9113bd4fd9db0d6bcbd55dca6b62402a483e786472c27720
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 Denis Tierno
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# TinyerpRuby
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/locomotivapro/tinyerp_ruby)
|
|
4
|
+
[](https://codeclimate.com/github/locomotivapro/tinyerp_ruby)
|
|
5
|
+
|
|
6
|
+
Gem for integration with [TinyERP](http://www.tiny.com.br) API.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
Add this line to your application's Gemfile:
|
|
11
|
+
|
|
12
|
+
gem 'tinyerp_ruby'
|
|
13
|
+
|
|
14
|
+
And then execute:
|
|
15
|
+
|
|
16
|
+
$ bundle
|
|
17
|
+
|
|
18
|
+
Or install it yourself as:
|
|
19
|
+
|
|
20
|
+
$ gem install tinyerp_ruby
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
In first place you need an account in TinyERP. This gem iis just a
|
|
25
|
+
wrapper to make calls to TinyERP api (v2) using a ruby hash and
|
|
26
|
+
parsing the response as a ruby hash object.
|
|
27
|
+
|
|
28
|
+
Start creating a connection with you api key, by default it will be started in production env but you can provide another env in connection initialization.
|
|
29
|
+
|
|
30
|
+
connection = TinyerpRuby::Connection.new 'yourawesomeapikey'
|
|
31
|
+
|
|
32
|
+
Then we create a service object.
|
|
33
|
+
|
|
34
|
+
poster = TinyerpRuby::Service.new connection
|
|
35
|
+
|
|
36
|
+
With service object created we just need to call the api methods and pass a hash according api description.
|
|
37
|
+
|
|
38
|
+
params = {....}
|
|
39
|
+
return_params = poster.pesquisar_vendedores_service(params)
|
|
40
|
+
|
|
41
|
+
The list with complete api method is found [here.](http://www.tiny.com.br/manuais/api2/)
|
|
42
|
+
|
|
43
|
+
## Testing
|
|
44
|
+
|
|
45
|
+
TinyerpRuby uses VCR to mock the api requests, but if you want to test
|
|
46
|
+
with another api key just do the following:
|
|
47
|
+
|
|
48
|
+
At the moment TinyERP doesn`t have a test environment, so you need to
|
|
49
|
+
create an account (free) and generate a new key for you. With your key,
|
|
50
|
+
create a file named api_key.rb inside spec/support with this code:
|
|
51
|
+
|
|
52
|
+
API_KEY = "yourawesomeeapikeyhere"
|
|
53
|
+
|
|
54
|
+
This way you are set up to run the tests
|
|
55
|
+
|
|
56
|
+
$ rspec spec
|
|
57
|
+
|
|
58
|
+
## TODO
|
|
59
|
+
|
|
60
|
+
This is an early release and can be much improved. Next steps planned are;
|
|
61
|
+
|
|
62
|
+
- Add builder object to complex methods as incluir_pedido and incluir_nota_fiscal
|
|
63
|
+
- Add better docs for params hash object
|
|
64
|
+
- Add support for better logs
|
|
65
|
+
- ...
|
|
66
|
+
|
|
67
|
+
## Contributing
|
|
68
|
+
|
|
69
|
+
1. Fork it
|
|
70
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
71
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
72
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
73
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module TinyerpRuby
|
|
2
|
+
class Connection
|
|
3
|
+
attr_reader :base_url, :environment, :api_key
|
|
4
|
+
|
|
5
|
+
def initialize(api_key, environment = :production)
|
|
6
|
+
@environment = eval(environment.to_s.capitalize)
|
|
7
|
+
@base_url = @environment::BASE_URL
|
|
8
|
+
@api_key = api_key
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'savon'
|
|
2
|
+
|
|
3
|
+
module TinyerpRuby
|
|
4
|
+
module Poster
|
|
5
|
+
|
|
6
|
+
class << self
|
|
7
|
+
|
|
8
|
+
def call(connection, service, params)
|
|
9
|
+
@connection = connection
|
|
10
|
+
webservice = Savon.client(wsdl: @connection.base_url, convert_request_keys_to: :none)
|
|
11
|
+
response = webservice.call(service, message: formatted_params(params))
|
|
12
|
+
parse service, response
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
def formatted_params(params)
|
|
17
|
+
formatted = { token: @connection.api_key }
|
|
18
|
+
formatted.delete(:formato)
|
|
19
|
+
formatted.merge!(params)
|
|
20
|
+
formatted.merge!({formato: 'json'})
|
|
21
|
+
formatted
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# For some reason Savon isnt parsing the response, so we do
|
|
25
|
+
def parse(service, response)
|
|
26
|
+
node = [service.to_s, "response"].join("_").to_sym
|
|
27
|
+
body = response.body[node][:return]
|
|
28
|
+
parser = Nori.new(convert_tags_to: lambda { |tag| tag.snakecase.to_sym })
|
|
29
|
+
parsed = parser.parse(body)
|
|
30
|
+
parsed[:retorno]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module TinyerpRuby
|
|
2
|
+
class Service
|
|
3
|
+
SERVICES = [:pesquisar_vendedores_service, :pesquisar_contatos_service, :obter_contato_service, :incluir_contato_service, :alterar_contato_service, :pesquisar_grupos_tag_service, :incluir_grupo_tag_service, :alterar_grupo_tag_service, :pesquisar_tag_service, :incluir_tag_service, :alterar_tag_service, :pesquisar_produtos_service, :obter_produto_service, :incluir_produto_service, :alterar_produto_service, :obter_estoque_produto_service, :obter_estrutura_produto_service, :obter_tags_produto_service, :lista_atualizacoes_produtos_service, :lista_atualizacoes_estoque_service, :pesquisar_pedidos_service, :obter_pedido_service, :incluir_pedido_service, :pesquisar_notas_fiscais_service, :obter_nota_fiscal_service, :incluir_nota_fiscal_service, :obter_xml_nota_fiscal, :pesquisar_notas_servico_service, :obter_nota_servico_service, :incluir_nota_servico_service, :pesquisar_contratos_service, :obter_contrato_service, :incluir_contrato_service, :gerar_ordem_produca_pedido_service, :pesquisar_contatos_xml, :obter_contato_xml, :incluir_contato_xml, :alterar_contato_xml, :pesquisar_grupos_tag_xml, :incluir_grupo_tag_xml, :alterar_grupo_tag_xml, :pesquisar_tag_xml, :incluir_tag_xml, :alterar_tag_xml, :pesquisar_produtos_xml, :obter_produto_xml, :incluir_produto_xml, :alterar_produto_xml, :obter_estoque_produto_xml, :obter_estrutura_produto_xml, :obter_tags_produto_xml, :lista_atualizacoes_produtos_xml, :lista_atualizacoes_estoque_xml, :pesquisar_pedidos_xml, :obter_pedido_xml, :incluir_pedido_xml, :pesquisar_notas_fiscais_xml, :obter_nota_fiscal_xml, :incluir_nota_fiscal_xml, :pesquisar_notas_servico_xml, :obter_nota_servico_xml, :incluir_nota_servico_xml, :pesquisar_contratos_xml, :obter_contrato_xml, :incluir_contrato_xml]
|
|
4
|
+
|
|
5
|
+
def initialize(connection)
|
|
6
|
+
raise StandartError unless connection.kind_of?(TinyerpRuby::Connection)
|
|
7
|
+
@connection = connection
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def method_missing(method, *args, &block)
|
|
11
|
+
method = method.to_sym
|
|
12
|
+
if SERVICES.include?(method)
|
|
13
|
+
poster(method, args)
|
|
14
|
+
else
|
|
15
|
+
super
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def poster(method, args)
|
|
22
|
+
params = args.first
|
|
23
|
+
raise ArgumentError unless params.kind_of?(Hash)
|
|
24
|
+
poster = Poster.call(@connection, method, params)
|
|
25
|
+
poster
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
data/lib/tinyerp_ruby.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require "tinyerp_ruby/version"
|
|
2
|
+
require "tinyerp_ruby/connection"
|
|
3
|
+
require "tinyerp_ruby/service"
|
|
4
|
+
require "tinyerp_ruby/poster"
|
|
5
|
+
|
|
6
|
+
module TinyerpRuby
|
|
7
|
+
class Production
|
|
8
|
+
BASE_URL = "http://www.tiny.com.br/api2.php?wsdl"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class Test
|
|
12
|
+
BASE_URL = "http://test.com"
|
|
13
|
+
end
|
|
14
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'bundler/setup'
|
|
2
|
+
Bundler.setup
|
|
3
|
+
|
|
4
|
+
require 'support/vcr'
|
|
5
|
+
require 'webmock/rspec'
|
|
6
|
+
require 'savon'
|
|
7
|
+
require 'tinyerp_ruby'
|
|
8
|
+
require 'support/api_key'
|
|
9
|
+
|
|
10
|
+
RSpec.configure do |config|
|
|
11
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
12
|
+
config.run_all_when_everything_filtered = true
|
|
13
|
+
config.mock_with :rspec
|
|
14
|
+
config.filter_run :focus
|
|
15
|
+
|
|
16
|
+
config.order = 'random'
|
|
17
|
+
end
|
|
18
|
+
|