abacos 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +72 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +29 -0
  8. data/Rakefile +4 -0
  9. data/abacos.gemspec +30 -0
  10. data/lib/abacos.rb +27 -0
  11. data/lib/abacos/base.rb +68 -0
  12. data/lib/abacos/carrier.rb +9 -0
  13. data/lib/abacos/customer.rb +10 -0
  14. data/lib/abacos/inventory.rb +4 -0
  15. data/lib/abacos/invoice.rb +7 -0
  16. data/lib/abacos/order.rb +24 -0
  17. data/lib/abacos/order_data.rb +4 -0
  18. data/lib/abacos/order_status.rb +6 -0
  19. data/lib/abacos/payment_condition.rb +9 -0
  20. data/lib/abacos/payment_method.rb +9 -0
  21. data/lib/abacos/price.rb +10 -0
  22. data/lib/abacos/product.rb +18 -0
  23. data/lib/abacos/response.rb +32 -0
  24. data/lib/abacos/shipping.rb +11 -0
  25. data/lib/abacos/stock.rb +10 -0
  26. data/lib/abacos/version.rb +3 -0
  27. data/spec/abacos/carrier_spec.rb +11 -0
  28. data/spec/abacos/customer_spec.rb +13 -0
  29. data/spec/abacos/inventory_spec.rb +11 -0
  30. data/spec/abacos/invoice_spec.rb +19 -0
  31. data/spec/abacos/order_spec.rb +39 -0
  32. data/spec/abacos/order_status_spec.rb +11 -0
  33. data/spec/abacos/payment_condition_spec.rb +11 -0
  34. data/spec/abacos/payment_method_spec.rb +11 -0
  35. data/spec/abacos/price_spec.rb +27 -0
  36. data/spec/abacos/product_spec.rb +53 -0
  37. data/spec/abacos/shipping_spec.rb +11 -0
  38. data/spec/abacos/stock_spec.rb +25 -0
  39. data/spec/cassettes/customer_success.yml +501 -0
  40. data/spec/cassettes/order_confirm_payment.yml +86 -0
  41. data/spec/cassettes/order_statuses_confirm.yml +1543 -0
  42. data/spec/cassettes/order_success.yml +1542 -0
  43. data/spec/cassettes/orders_exist.yml +100 -0
  44. data/spec/cassettes/orders_statuses.yml +70 -0
  45. data/spec/cassettes/prices_available.yml +4031 -0
  46. data/spec/cassettes/prices_confirm.yml +75 -0
  47. data/spec/cassettes/products_available.yml +4031 -0
  48. data/spec/cassettes/products_available_empty.yml +76 -0
  49. data/spec/cassettes/products_available_one.yml +76 -0
  50. data/spec/cassettes/products_confirm.yml +74 -0
  51. data/spec/cassettes/stocks_available.yml +4031 -0
  52. data/spec/cassettes/stocks_confirm.yml +75 -0
  53. data/spec/config.yml.example +14 -0
  54. data/spec/spec_helper.rb +17 -0
  55. metadata +237 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7be81378607aafff5232adb78d94b64bc7572dda
4
+ data.tar.gz: 907cea7ac4ad572c2e2ec2660553617f934a528d
5
+ SHA512:
6
+ metadata.gz: 8d6338aa262bb2fa9ba259eafd861771a68c636ea4597c137c7e72f3289c5012dd12d285b82f316390fb2b88d22cd85f6978ad8875ce8b6c80a40eb2d751f85d
7
+ data.tar.gz: c7d300b8bd4c0dbbc54d02a1cd0b9b511825a7a0cf9d09cf5e6b07624c5c02051e84d81abcabc922ab341d16cb660fe588252633f7ea4fca65fb706723bd3084
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
17
+ spec/config.yml
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in abacos.gemspec
4
+ gemspec
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ abacos (0.0.4)
5
+ savon
6
+ tiny_tds
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.3.5)
12
+ akami (1.3.1)
13
+ gyoku (>= 0.4.0)
14
+ nokogiri
15
+ builder (3.2.2)
16
+ coderay (1.1.0)
17
+ crack (0.4.1)
18
+ safe_yaml (~> 0.9.0)
19
+ diff-lcs (1.2.5)
20
+ gyoku (1.3.1)
21
+ builder (>= 2.1.2)
22
+ httpi (2.4.1)
23
+ rack
24
+ method_source (0.8.2)
25
+ mini_portile (0.6.2)
26
+ nokogiri (1.6.6.2)
27
+ mini_portile (~> 0.6.0)
28
+ nori (2.6.0)
29
+ pry (0.9.12.6)
30
+ coderay (~> 1.0)
31
+ method_source (~> 0.8)
32
+ slop (~> 3.4)
33
+ rack (1.6.4)
34
+ rake (10.1.1)
35
+ rspec (2.14.1)
36
+ rspec-core (~> 2.14.0)
37
+ rspec-expectations (~> 2.14.0)
38
+ rspec-mocks (~> 2.14.0)
39
+ rspec-core (2.14.8)
40
+ rspec-expectations (2.14.5)
41
+ diff-lcs (>= 1.1.3, < 2.0)
42
+ rspec-mocks (2.14.6)
43
+ safe_yaml (0.9.7)
44
+ savon (2.11.1)
45
+ akami (~> 1.2)
46
+ builder (>= 2.1.2)
47
+ gyoku (~> 1.2)
48
+ httpi (~> 2.3)
49
+ nokogiri (>= 1.4.0)
50
+ nori (~> 2.4)
51
+ wasabi (~> 3.4)
52
+ slop (3.4.7)
53
+ tiny_tds (0.6.2)
54
+ vcr (2.8.0)
55
+ wasabi (3.5.0)
56
+ httpi (~> 2.0)
57
+ nokogiri (>= 1.4.2)
58
+ webmock (1.15.0)
59
+ addressable (>= 2.2.7)
60
+ crack (>= 0.3.2)
61
+
62
+ PLATFORMS
63
+ ruby
64
+
65
+ DEPENDENCIES
66
+ abacos!
67
+ bundler (~> 1.5)
68
+ pry
69
+ rake
70
+ rspec
71
+ vcr
72
+ webmock
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Diego Carrion
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.
@@ -0,0 +1,29 @@
1
+ # Abacos
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'abacos'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install abacos
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/abacos/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,4 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'abacos/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "abacos"
8
+ spec.version = Abacos::VERSION
9
+ spec.authors = ["Diego Carrion"]
10
+ spec.email = ["dc.rec1@gmail.com"]
11
+ spec.summary = "Ruby API to Abacos"
12
+ spec.description = ""
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "savon"
22
+ spec.add_dependency "tiny_tds"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "vcr"
28
+ spec.add_development_dependency "pry"
29
+ spec.add_development_dependency "webmock"
30
+ end
@@ -0,0 +1,27 @@
1
+ require "savon"
2
+ require "tiny_tds"
3
+ require "abacos/base"
4
+ require "abacos/carrier"
5
+ require "abacos/customer"
6
+ require "abacos/inventory"
7
+ require "abacos/invoice"
8
+ require "abacos/order"
9
+ require "abacos/order_data"
10
+ require "abacos/order_status"
11
+ require "abacos/payment_condition"
12
+ require "abacos/payment_method"
13
+ require "abacos/price"
14
+ require "abacos/product"
15
+ require "abacos/response"
16
+ require "abacos/stock"
17
+ require "abacos/shipping"
18
+
19
+ module Abacos
20
+ def self.config!(config)
21
+ @config = config
22
+ end
23
+
24
+ def self.config
25
+ @config
26
+ end
27
+ end
@@ -0,0 +1,68 @@
1
+ module Abacos
2
+ class Base
3
+ attr_reader :response
4
+
5
+ def self.available(params)
6
+ call(:"#{collection_name}_disponiveis", params).map { |params| new params }
7
+ end
8
+
9
+ def confirm!
10
+ self.class.call(:"confirmar_recebimento_#{self.class.resource_name}", :"protocolo_#{self.class.resource_name}" => send("protocolo_#{self.class.resource_name}"))
11
+ end
12
+
13
+ class << self
14
+ %w(ws resource_name collection_name).each do |attribute|
15
+ define_method "#{attribute}=" do |param|
16
+ instance_variable_set "@#{attribute}", param
17
+ end
18
+
19
+ define_method "#{attribute}" do
20
+ instance_variable_get "@#{attribute}"
21
+ end
22
+ end
23
+
24
+ def collection_name
25
+ @collection_name ||= "#{resource_name}s"
26
+ end
27
+ end
28
+
29
+ def self.call(method, params)
30
+ Response.new method, api.call(method, message: params)
31
+ end
32
+
33
+ def self.create(method, params)
34
+ new response: call(method, params)
35
+ end
36
+
37
+ def self.execute(query)
38
+ db.execute(query).map { |params| new params }
39
+ end
40
+
41
+ def initialize(params)
42
+ params.each do |key, value|
43
+ instance_variable_set "@#{key}", value
44
+ define_singleton_method(key) { instance_variable_get "@#{key}" }
45
+ end
46
+ end
47
+
48
+ def persisted?
49
+ response.success?
50
+ end
51
+
52
+ private
53
+
54
+ def self.api
55
+ @api ||= Savon.client wsdl: "#{endpoint}/AbacosWS#{ws}.asmx?wsdl", log: Abacos.config['log'], read_timeout: 600, open_timeout: 600 do
56
+ convert_request_keys_to :camelcase
57
+ end
58
+ end
59
+
60
+ def self.db
61
+ TinyTds::Client.new(Hash[Abacos.config['db'].map{ |k, v| [k.to_sym, v] }])
62
+ end
63
+
64
+ def self.endpoint
65
+ Abacos.config['ws']['endpoint']
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,9 @@
1
+ module Abacos
2
+ class Carrier < Base
3
+ attr_reader :id, :name
4
+
5
+ def self.all
6
+ execute("select id = tran_cod, name = rtrim(entb_nom_fan) from abacos..tgen_transp, abacos..tgen_entbas where tgen_transp.entb_cod = tgen_entbas.entb_cod order by entb_nom_fan")
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Abacos
2
+ class Customer < Base
3
+ attr_reader :response
4
+ self.ws = "Clientes"
5
+
6
+ def self.create!(*params, chave_identificacao:)
7
+ create :cadastrar_cliente, { chave_identificacao: chave_identificacao }.merge(lista_de_clientes: params.map { |param| { dados_clientes: param }})
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ module Abacos
2
+ class Inventory < Base
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module Abacos
2
+ class Invoice < Base
3
+ self.ws = "NotasFiscais"
4
+ self.resource_name = "nota_fiscal"
5
+ self.collection_name = "notas_fiscais"
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ module Abacos
2
+ class Order < Base
3
+ attr_reader :response
4
+ self.ws = "Pedidos"
5
+
6
+ def self.create!(*params, chave_identificacao:)
7
+ create :inserir_pedido, { chave_identificacao: chave_identificacao }.merge(lista_de_pedidos: params.map { |param| { dados_pedidos: param }})
8
+ end
9
+
10
+ def self.confirm_payment!(*params, chave_identificacao:)
11
+ call :confirmar_pagamentos_pedidos, { chave_identificacao: chave_identificacao }.merge(lista_de_pagamentos: params.map { |param| { dados_pgto_pedido: param }})
12
+ end
13
+
14
+ def self.statuses(chave_identificacao:)
15
+ call(:status_pedido_disponiveis, { chave_identificacao: chave_identificacao }).map { |params| OrderStatus.new params }
16
+ end
17
+
18
+ def self.exist?(*ids, chave_identificacao:)
19
+ {}.tap do |hash|
20
+ call(:pedido_existe, { chave_identificacao: chave_identificacao, lista_de_numeros_de_pedidos: { 'string' => ids }}).each { |data| hash[data[:numero_do_pedido]] = OrderData.new data }
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ module Abacos
2
+ class OrderData < Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Abacos
2
+ class OrderStatus < Base
3
+ self.ws = "Pedidos"
4
+ self.resource_name = "status_pedido"
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ module Abacos
2
+ class PaymentCondition < Base
3
+ attr_reader :id, :name
4
+
5
+ def self.all
6
+ execute("select id = conp_cod, name = rtrim(conp_nom) from abacos..tcom_conpag order by conp_nom")
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Abacos
2
+ class PaymentMethod < Base
3
+ attr_reader :id, :name
4
+
5
+ def self.all
6
+ execute("select id = forp_cod, name = rtrim(forp_nom) from abacos..tcom_forpag order by forp_nom")
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Abacos
2
+ class Price < Base
3
+ self.ws = "Produtos"
4
+ self.resource_name = "preco"
5
+
6
+ def self.find_by_sku_and_table(sku, table)
7
+ execute("select list_value = prol_val_pre, sell_value = prol_val_prepro from abacos..tcom_proser pro with (nolock) join abacos..tcom_prolis lis with (nolock) on pro.pros_cod = lis.pros_cod and lis.lisp_cod = #{table} where pro.pros_ext_cod = '#{sku}'").first
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ module Abacos
2
+ class Product < Base
3
+ self.ws = "Produtos"
4
+ self.resource_name = "produto"
5
+
6
+ def self.find_by_ean(ean)
7
+ execute("select codigo_produto = pros_ext_cod, weight = pros_pes from abacos..tcom_proser with (nolock) where pros_bar = #{ean}").first
8
+ end
9
+
10
+ def self.find_by_sku(sku)
11
+ execute("select ean = pros_bar, weight = pros_pes from abacos..tcom_proser with (nolock) where pros_ext_cod = '#{sku}'").first
12
+ end
13
+
14
+ def self.all_active_by_cnpj(cnpj)
15
+ execute("select bas.ENTB_CGC,ENTB_NOM_RAZ,selo=marp_nom,pros_cod=pro.PROS_COD,pros_bar=pro.PROS_BAR,pro.PROS_EXT_COD,pros_nom=PROS_NOM,preco_capa=lis.PROL_VAL_PRE,pod=liv.LIVP_CHR_SN_POD from ABACOS..TGEN_ENTBAS bas with (nolock) inner join ABACOS..TCOM_CLIFOR cli with (nolock) on bas.ENTB_COD=cli.entb_cod inner join ABACOS..TCOM_FORMAR fo with (nolock) on fo.FORM_COD=(select top 1 FORM_COD from ABACOS..TCOM_FORMAR xx with (nolock) where xx.FORM_CHR_SN_PAD='S' and xx.CLIF_COD=cli.CLIF_COD) inner join ABACOS..TCOM_PROSER pro with (nolock) on pro.MARP_COD=fo.marp_cod inner join ABACOS..TCOM_PROLIS lis with (nolock) on pro.PROS_COD=lis.PROS_COD and lis.LISP_COD=1 inner join ABACOS..TCOM_MARPRO mar with (nolock) on pro.MARP_COD=mar.MARP_cod inner join ABACOS..TCOM_LIVPRO liv with (nolock) on pro.PROS_COD=liv.pros_cod where bas.ENTB_CGC='#{cnpj}' AND liv.LIVP_CHR_SN_POD = 'S'")
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,32 @@
1
+ require 'forwardable'
2
+
3
+ module Abacos
4
+ class Response
5
+ include Enumerable
6
+ extend Forwardable
7
+ def_delegators :@savon, :to_s
8
+
9
+ def initialize(method, savon)
10
+ @method = method
11
+ @savon = savon
12
+ end
13
+
14
+ def each(&block)
15
+ (doc.has_key?(:rows) ? extract_values(doc[:rows]) : []).each &block
16
+ end
17
+
18
+ def success?
19
+ (doc.has_key?(:tipo) ? doc : doc[:resultado_operacao])[:tipo] == "tdreSucesso"
20
+ end
21
+
22
+ private
23
+
24
+ def extract_values(rows)
25
+ [rows.values.first].flatten
26
+ end
27
+
28
+ def doc
29
+ @savon.body["#{@method}_response".to_sym]["#{@method}_result".to_sym]
30
+ end
31
+ end
32
+ end