fastshop_catalog 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.gitignore +20 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +52 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +69 -0
  8. data/Rakefile +5 -0
  9. data/fastshop_catalog.gemspec +25 -0
  10. data/lib/fastshop_catalog/base_entity.rb +30 -0
  11. data/lib/fastshop_catalog/base_service.rb +71 -0
  12. data/lib/fastshop_catalog/catalog_service.rb +17 -0
  13. data/lib/fastshop_catalog/check_availability_service.rb +23 -0
  14. data/lib/fastshop_catalog/crypto.rb +41 -0
  15. data/lib/fastshop_catalog/entity/address.rb +30 -0
  16. data/lib/fastshop_catalog/entity/business_unity.rb +9 -0
  17. data/lib/fastshop_catalog/entity/order.rb +12 -0
  18. data/lib/fastshop_catalog/entity/order_item.rb +7 -0
  19. data/lib/fastshop_catalog/entity/participant.rb +15 -0
  20. data/lib/fastshop_catalog/external_dne_service.rb +17 -0
  21. data/lib/fastshop_catalog/order_placement_service.rb +20 -0
  22. data/lib/fastshop_catalog/order_status_service.rb +18 -0
  23. data/lib/fastshop_catalog/participant_service.rb +20 -0
  24. data/lib/fastshop_catalog/product_service.rb +17 -0
  25. data/lib/fastshop_catalog/service_exception.rb +11 -0
  26. data/lib/fastshop_catalog/time.rb +15 -0
  27. data/lib/fastshop_catalog/version.rb +3 -0
  28. data/lib/fastshop_catalog.rb +20 -0
  29. data/password_util.rb +48 -0
  30. data/spec/.DS_Store +0 -0
  31. data/spec/fastshop_catalog/.DS_Store +0 -0
  32. data/spec/fastshop_catalog/base_service_spec.rb +44 -0
  33. data/spec/fastshop_catalog/catalog_service_spec.rb +43 -0
  34. data/spec/fastshop_catalog/check_availability_service_spec.rb +44 -0
  35. data/spec/fastshop_catalog/external_dne_service_spec.rb +60 -0
  36. data/spec/fastshop_catalog/integration/catalog_service_integration_spec.rb +15 -0
  37. data/spec/fastshop_catalog/integration/check_availability_service_integration_spec.rb +30 -0
  38. data/spec/fastshop_catalog/integration/external_dne_service_integration_spec.rb +12 -0
  39. data/spec/fastshop_catalog/integration/order_placement_service_integration_spec.rb +41 -0
  40. data/spec/fastshop_catalog/integration/order_status_service_integration_spec.rb +31 -0
  41. data/spec/fastshop_catalog/integration/participant_service_integration_spec.rb +34 -0
  42. data/spec/fastshop_catalog/integration/product_service_integration_spec.rb +23 -0
  43. data/spec/fastshop_catalog/order_placement_service_spec.rb +60 -0
  44. data/spec/fastshop_catalog/order_status_service_spec.rb +62 -0
  45. data/spec/fastshop_catalog/participant_factory.rb +40 -0
  46. data/spec/fastshop_catalog/participant_service_spec.rb +60 -0
  47. data/spec/fastshop_catalog/product_service_spec.rb +60 -0
  48. data/spec/fixtures/catalog_service_successful_response.xml +11 -0
  49. data/spec/fixtures/catalog_service_wrong_contract_response.xml +10 -0
  50. data/spec/fixtures/check_availability_not_available_response.xml +11 -0
  51. data/spec/fixtures/external_dne_service_successful_response.xml +11 -0
  52. data/spec/fixtures/external_dne_service_wrong_contract_response.xml +11 -0
  53. data/spec/fixtures/external_dne_service_wrong_zip_response.xml +11 -0
  54. data/spec/fixtures/order_placement_cart_not_identified.xml +11 -0
  55. data/spec/fixtures/order_placement_successful_delivery_payload.json +4 -0
  56. data/spec/fixtures/order_placement_successful_payload.json +1 -0
  57. data/spec/fixtures/order_status_service_order_not_found_response.xml +11 -0
  58. data/spec/fixtures/order_status_service_successful_response.xml +11 -0
  59. data/spec/fixtures/participant_service_successful_response.xml +11 -0
  60. data/spec/fixtures/participant_service_successful_token_response.xml +11 -0
  61. data/spec/fixtures/participant_successful_payload.json +1 -0
  62. data/spec/fixtures/product_service_successful_response.xml +11 -0
  63. data/spec/fixtures/product_service_wrong_contract_response.xml +11 -0
  64. data/spec/fixtures/product_service_wrong_sku_response.xml +11 -0
  65. data/spec/spec_helper.rb +10 -0
  66. data/wsdls/catalog.wsdl +49 -0
  67. data/wsdls/participante.wsdl +52 -0
  68. metadata +202 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6979a2dd0fb12fbe9763eb4c513ae9eb99ee4929
4
+ data.tar.gz: 0ae72216d29c1259cda93d76360b8ad87267729a
5
+ SHA512:
6
+ metadata.gz: a130fae20c101e7b86d617f54594de693487180acd9fdda906315acff3d9220b4becafcd6f9c40b08e72d7ee90957d03924375a06c1d5923eeed940afaa74904
7
+ data.tar.gz: 1d326bc2c4d90c913311d3da91a24c2116a6bc8b28a01ed4146a864c1c4f314d8495a1627948b000647ac0fb8c1ee02491f1bd77030b02ad7e3b927064fda464
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .rvmrc
4
+ .ruby-version
5
+ .ruby-gemset
6
+ .bundle
7
+ .config
8
+ .yardoc
9
+ Gemfile.lock
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ doc/
14
+ lib/bundler/man
15
+ pkg
16
+ rdoc
17
+ spec/reports
18
+ test/tmp
19
+ test/version_tmp
20
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fastshop_catalog.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fastshop_catalog (0.0.1)
5
+ savon
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ akami (1.2.0)
11
+ gyoku (>= 0.4.0)
12
+ nokogiri (>= 1.4.0)
13
+ builder (3.2.2)
14
+ diff-lcs (1.2.4)
15
+ gyoku (1.1.0)
16
+ builder (>= 2.1.2)
17
+ httpi (2.1.0)
18
+ rack
19
+ rubyntlm (~> 0.3.2)
20
+ nokogiri (1.5.10)
21
+ nori (2.3.0)
22
+ rack (1.5.2)
23
+ rake (10.1.0)
24
+ rspec (2.14.1)
25
+ rspec-core (~> 2.14.0)
26
+ rspec-expectations (~> 2.14.0)
27
+ rspec-mocks (~> 2.14.0)
28
+ rspec-core (2.14.5)
29
+ rspec-expectations (2.14.2)
30
+ diff-lcs (>= 1.1.3, < 2.0)
31
+ rspec-mocks (2.14.3)
32
+ rubyntlm (0.3.4)
33
+ savon (2.3.0)
34
+ akami (~> 1.2.0)
35
+ builder (>= 2.1.2)
36
+ gyoku (~> 1.1.0)
37
+ httpi (~> 2.1.0)
38
+ nokogiri (>= 1.4.0, < 1.6)
39
+ nori (~> 2.3.0)
40
+ wasabi (~> 3.2.0)
41
+ wasabi (3.2.0)
42
+ httpi (~> 2.0)
43
+ nokogiri (>= 1.4.0, < 1.6)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ bundler (~> 1.3)
50
+ fastshop_catalog!
51
+ rake
52
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Thiago Ganzarolli
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,69 @@
1
+ [![BuildStatus](https://semaphoreapp.com/api/v1/projects/1c84d1cef62189c3a446f7350568013fc8ab5551/76234/badge.png)](https://semaphoreapp.com/api/v1/projects/1c84d1cef62189c3a446f7350568013fc8ab5551/76234/badge.png)
2
+ [![Code Climate](https://codeclimate.com/repos/521e17247e00a40bce048945/badges/a9685ebf4138c4e2e2d4/gpa.png)](https://codeclimate.com/repos/521e17247e00a40bce048945/feed)
3
+
4
+ # FastshopCatalog
5
+
6
+ Integrates with Fastshop's catalog webservices.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'fastshop_catalog'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install fastshop_catalog
21
+
22
+ ## Testing
23
+
24
+ The project was tested with ruby 1.9.3 and 2.0.0-p247.
25
+
26
+ Just run:
27
+
28
+ rake
29
+
30
+ To skip integration tests, pass an environment variable as follows:
31
+
32
+ integration=false rake
33
+
34
+ ## Usage
35
+
36
+ Global parameters
37
+
38
+ FastshopCatalog::BaseService.log_level, defaults to ':info'. You can change it to :debug, for example:
39
+
40
+ FastshopCatalog::BaseService.log_level = :debug
41
+
42
+ FastshopCatalog::BaseService.base_url, defaults to FastshopCatalog::BaseService::DEFAULT_BASE_URL. To change it:
43
+
44
+ FastshopCatalog::BaseService.base_url = 'http://your_server_here'
45
+
46
+ FastshopCatalog::BaseService.crypto_key which is described on its own section, under password generation.
47
+
48
+ ## Password generation for encrypted services
49
+
50
+ Outside the gem, there is the PasswordUtil class, which depends on the proprietary library chilkat,
51
+ specifically the crypto modules. This is the only way to generate a .NET compatible PBKDF1 key. The default result
52
+ from PasswordUtil.derive_fastshop_default is already configured. If you need to change your password, follow these steps:
53
+
54
+ 1) Download this gem source code
55
+ 2) Install the chilkat gem (instructions here http://www.example-code.com/ruby/default.asp)
56
+ 3) Invoke this method on the console, given that you're already on the project source directory:
57
+
58
+ $irb
59
+ > PasswordUtil.derive_fastshop_default('your new password', 'your salt')
60
+ => YOUR_NEW_KEY
61
+
62
+ And then you can set the new default with:
63
+
64
+ FastshopCatalog::BaseService.crypto_key = 'YOUR_KEY'
65
+
66
+ Notice that you might have to purchase a chilkat license if the trial does not work anymore. If you have a license you
67
+ can invoke irb like this:
68
+
69
+ $ chilkat_license='your_license' irb
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fastshop_catalog/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fastshop_catalog"
8
+ spec.version = FastshopCatalog::VERSION
9
+ spec.authors = ["Thiago Ganzarolli"]
10
+ spec.email = ["thiago.ganzarolli@gmail.com"]
11
+ spec.description = %q{Integração com webservices da FastShop}
12
+ spec.summary = %q{FastShop integrações}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_dependency "savon"
25
+ end
@@ -0,0 +1,30 @@
1
+ module FastshopCatalog
2
+ class BaseEntity
3
+
4
+ def self.translate(map)
5
+ #instantiates the translation map and creates accessors
6
+ @translate_map = map
7
+ self.instance_eval do
8
+ map.each_key{|k| attr_accessor k}
9
+ end
10
+ end
11
+
12
+ def self.translate_symbol(symbol)
13
+ @translate_map[symbol]
14
+ end
15
+
16
+ def to_map
17
+ map = {}
18
+ #translates the variables to it's synonyms
19
+ self.class.public_instance_methods(optional=false).grep(/.*[^\=]$/).each do |m|
20
+ map[self.class.translate_symbol(m.to_sym)] = self.send(m) if self.send(m)
21
+ end
22
+ #orders the map by the synonym
23
+ map.keys.sort.inject({}){|o, k| o[k] = map[k]; o}
24
+ end
25
+
26
+ def to_json(*a)
27
+ to_map.to_json(*a)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,71 @@
1
+ module FastshopCatalog
2
+ class BaseService
3
+
4
+ AUX_LOG = Logger.new(STDOUT)
5
+ AUX_LOG.level = Logger::WARN
6
+
7
+ DEFAULT_BASE_URL = 'http://www.fastincentivos.com.br'
8
+
9
+ class << self
10
+ attr_accessor :log_level
11
+ attr_accessor :base_url
12
+ attr_accessor :crypto_key
13
+ end
14
+
15
+ def service_url
16
+ @service_url ||= "#{FastshopCatalog::BaseService.base_url || DEFAULT_BASE_URL}/#{@service}"
17
+ end
18
+
19
+ def action
20
+ @action ||= "#{@interface}/#{BaseService.camelize(@soap_method)}"
21
+ end
22
+
23
+ def self.camelize(val)
24
+ val.to_s.split('_').map {|w| w.capitalize}.join
25
+ end
26
+
27
+ def encrypt(payload)
28
+ require_relative 'crypto'
29
+ Crypto.new.encrypt(payload.to_s)
30
+ end
31
+
32
+ def initialize(params={})
33
+ @@log_level ||= :info
34
+ default_params = {:wsdl => "#{service_url}?wsdl", :soap_version => 2, :namespaces =>
35
+ {"xmlns:x" => "http://www.w3.org/2005/08/addressing"}, :soap_header =>
36
+ {"x:To" => service_url, "x:Action" => "http://tempuri.org/#{action}"}, :log_level =>
37
+ @log_level}
38
+ @client = Savon.client(recursive_merge(default_params, params))
39
+ HTTPI.log = false
40
+ end
41
+
42
+ protected
43
+
44
+ def service_invoker(parameters={})
45
+ response = @client.call(@soap_method, :message => adapt_output(parameters))
46
+ result = JSON.parse(response.body["#{@soap_method}_response".to_sym]["#{@soap_method}_result".to_sym])
47
+ result_status = result['Retorno']
48
+ if result_status['IdRetorno'] != 0
49
+ raise ServiceException.new(:code => result_status['IdRetorno'], :description => result_status['MsgRetorno'])
50
+ end
51
+ result[@return_key]
52
+ end
53
+
54
+ def service_invoker_with_encryption(encrypted_payload_key, parameters={})
55
+ encrypted_payload = encrypt(parameters[encrypted_payload_key])
56
+ FastshopCatalog::BaseService::AUX_LOG.debug('Encrypted payload: ' + encrypted_payload)
57
+ parameters[encrypted_payload_key] = encrypted_payload
58
+ service_invoker(parameters.merge(:salt => ''))
59
+ end
60
+
61
+ private
62
+
63
+ def adapt_output(params={}, namespace='tns')
64
+ Hash[params.map {|k, v| ["#{namespace}:#{k}", v] }]
65
+ end
66
+
67
+ def recursive_merge(h1, h2)
68
+ h1.merge(h2) { |k, v1, v2| v1.is_a?(Hash) && v2.is_a?(Hash) ? v1.merge(v2) : v2 }
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,17 @@
1
+ module FastshopCatalog
2
+ class CatalogService < FastshopCatalog::BaseService
3
+
4
+ def initialize
5
+ @service = 'FastServices.WsCatalogo/Catalogo.svc/service'
6
+ @interface = 'ICatalogo'
7
+ @soap_method = :busca_catalogo
8
+ @return_key = 'Lista'
9
+ super
10
+ end
11
+
12
+ def search(contract_code)
13
+ service_invoker('contrato' => contract_code)
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ module FastshopCatalog
2
+ class CheckAvailabilityService < FastshopCatalog::BaseService
3
+
4
+ def initialize
5
+ @service = 'FastServices.WsConsultaDisponibilidade/ConsultaDisponibilidade.svc/service'
6
+ @interface = 'IConsultaDisponibilidade'
7
+ @soap_method = :retorna_dados
8
+ @return_key = 'Disponibilidade'
9
+ super(:namespaces => {'xmlns:fas' => 'http://schemas.datacontract.org/2004/07/FastServices.WsConsultaDisponibilidade.Componentes'})
10
+ end
11
+
12
+ def check(order)
13
+ root_attributes = order.to_map
14
+ adapted_items = []
15
+ root_attributes['Itens'].each do |item|
16
+ adapted_items << {'fas:PedidoItensEntity' => adapt_output(item.to_map)}
17
+ end
18
+ root_attributes['Itens'] = adapted_items
19
+ service_invoker('dadosPedido' => adapt_output(root_attributes, 'fas'))
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,41 @@
1
+ module FastshopCatalog
2
+
3
+ require 'openssl'
4
+ require 'base64'
5
+
6
+ #if the iv changes, you can reconfigure it here
7
+ FAST_IV = [0xf, 0x6f, 0x13, 0x2e, 0x35, 0xc2, 0xcd, 0xf9, 0x5, 0x46, 0x9c, 0xea, 0xa8, 0x4b, 0x73, 0xcc]
8
+ #if this key changes, check the readme for instructions
9
+ DEFAULT_KEY = 'D027CF4E32A9A69363DB9D72234F97B4'
10
+
11
+ class Crypto
12
+
13
+ def initialize(key=FastshopCatalog::Crypto.default_key, iv=FastshopCatalog::Crypto.default_iv)
14
+ @cypher = OpenSSL::Cipher::Cipher.new("AES-128-CBC")
15
+ @cypher.encrypt
16
+ @cypher.key = key
17
+ @cypher.iv = iv
18
+ end
19
+
20
+ def encrypt(payload)
21
+ encrypted = @cypher.update(payload) << @cypher.final
22
+ Base64.strict_encode64(encrypted)
23
+ end
24
+
25
+ private
26
+
27
+ def self.hex_to_bin(s)
28
+ s.scan(/../).map { |x| x.hex.chr }.join
29
+ end
30
+
31
+ def self.default_iv
32
+ @@default_iv ||= FAST_IV.map{|x| x.chr}.join('')
33
+ end
34
+
35
+ def self.default_key
36
+ @@default_key ||= hex_to_bin(DEFAULT_KEY)
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,30 @@
1
+ module FastshopCatalog
2
+ module Entity
3
+ class Address < BaseEntity
4
+
5
+ HOME_TYPE_HOUSE = '1'
6
+ HOME_TYPE_APARTMENT = '2'
7
+ HOME_TYPE_CONDO = '3'
8
+ HOME_TYPE_COMPANY = '4'
9
+
10
+ HOME_TYPE_DESCRIPTION_MAP = {'1' => 'CASA', '2' => 'APARTAMENTO',
11
+ '3' => 'CONDOMINIO', '4' => 'EMPRESA'}
12
+
13
+ translate :description => 'Descricao',
14
+ :address_type => 'TipoEndereco', :document => 'CPF', :registry => 'RG',
15
+ :birth_date => 'DataNascimento', :address => 'Endereco',
16
+ :number => 'Numero', :complement => 'Complemento',
17
+ :neighborhood => 'Bairro', :city => 'Cidade',
18
+ :state => 'Estado', :zip_code => 'Cep',
19
+ :home_type_id => 'TipoMoradiaId',
20
+ :home_type_description => 'TipoMoradiaDescricao'
21
+
22
+ def home_type=(home_type)
23
+ raise ArgumentError.new('Invalid home type') unless (1..4).member? home_type.to_i
24
+ self.home_type_id = home_type
25
+ self.home_type_description = HOME_TYPE_DESCRIPTION_MAP[home_type]
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ module FastshopCatalog
2
+ module Entity
3
+ class BusinessUnity < BaseEntity
4
+ translate :company_document => 'Cnpj',
5
+ :company_name => 'RazaoSocial',
6
+ :trading_name => 'Fantasia'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ module FastshopCatalog
2
+ module Entity
3
+ class Order < BaseEntity
4
+ translate :contract_code => 'Contrato',
5
+ :partner_order_number => 'NumeroPedidoParceiro', :document => 'Cpf',
6
+ :zip_code => 'Cep', :number => 'Numero', :total_amount => 'ValorTotal',
7
+ :delivery_type => 'TipoEntrega', :delivery_date => 'DataEntrega',
8
+ :period_id => 'PeriodoId', :period_name => 'PeriodoNome',
9
+ :items => 'Itens'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ module FastshopCatalog
2
+ module Entity
3
+ class OrderItem < BaseEntity
4
+ translate :sku => 'Sku', :price => 'ValorUnitario', :quantity => 'Quantidade'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ module FastshopCatalog
2
+ module Entity
3
+ class Participant < BaseEntity
4
+ translate :contract_code => 'Contrato',
5
+ :name => 'Nome', :document => 'Cpf', :registry => 'RG',
6
+ :birth_date => 'DataNascimento', :gender => 'Sexo',
7
+ :category => 'Categoria',
8
+ :home_phone_prefix => 'DddResidencial', :home_phone => 'TelefoneResidencial',
9
+ :work_phone_prefix => 'DddComercial', :work_phone => 'TelefoneComercial',
10
+ :mobile_phone_prefix => 'DddCelular', :mobile_phone => 'Celular',
11
+ :email => 'Email', :status => 'Status', :operation_type => 'TipoOperacao',
12
+ :address => 'Endereco', :business_unity => 'UnidadeNegocio'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module FastshopCatalog
2
+ class ExternalDneService < FastshopCatalog::BaseService
3
+
4
+ def initialize
5
+ @service = 'FastServices.WsConsultaDneExterno/ConsultaDneExterno.svc/service'
6
+ @interface = 'IConsultaDneExterno'
7
+ @soap_method = :consultar
8
+ @return_key = 'Dne'
9
+ super
10
+ end
11
+
12
+ def query(contract_code, zip_code)
13
+ service_invoker('cep' => zip_code, 'contrato' => contract_code)
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ module FastshopCatalog
2
+ class OrderPlacementService < FastshopCatalog::BaseService
3
+
4
+ def initialize
5
+ @service = 'FastServices.WsColocacaoPedido/ColocacaoPedido.svc/service'
6
+ @interface = 'IColocacaoPedido'
7
+ @soap_method = :incluir_pedido
8
+ @return_key = 'NumeroPedidoFast'
9
+ super
10
+ end
11
+
12
+ def place_order(order)
13
+ payload = order.to_json.to_s
14
+ AUX_LOG.debug('Order as json: ' + payload)
15
+ service_invoker_with_encryption('entrada', 'contrato' => order.contract_code,
16
+ 'entrada' => payload)
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ module FastshopCatalog
2
+ class OrderStatusService < FastshopCatalog::BaseService
3
+
4
+ def initialize
5
+ @service = 'FastServices.WsConsultaStatusPedido/ConsultaStatusPedido.svc/service'
6
+ @interface = 'IConsultaStatusPedido'
7
+ @soap_method = :retorna_dados
8
+ @return_key = 'Lista'
9
+ super
10
+ end
11
+
12
+ def check(contract_code, order_number, partner_order_number)
13
+ service_invoker('numeroPedidoFast' => order_number, 'numeroPedidoParceiro' => partner_order_number,
14
+ 'contrato' => contract_code)
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ module FastshopCatalog
2
+ class ParticipantService < FastshopCatalog::BaseService
3
+
4
+ def initialize
5
+ @service = 'FastServices.WsParticipante/Participante.svc/service'
6
+ @interface = 'IParticipante'
7
+ @soap_method = :cadastrar_participante
8
+ @return_key = 'Token'
9
+ super
10
+ end
11
+
12
+ def insert(participant)
13
+ payload = participant.to_json.to_s
14
+ AUX_LOG.debug('Participant as json: ' + payload)
15
+ service_invoker_with_encryption('entrada', 'contrato' => participant.contract_code,
16
+ 'entrada' => payload)
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ module FastshopCatalog
2
+ class ProductService < FastshopCatalog::BaseService
3
+
4
+ def initialize
5
+ @service = 'FastServices.WsConsultaProduto/ConsultaProduto.svc/service'
6
+ @interface = 'IConsultaProduto'
7
+ @soap_method = :busca_produto
8
+ @return_key = 'ProdutoDados'
9
+ super
10
+ end
11
+
12
+ def search(contract_code, sku)
13
+ service_invoker('contrato' => contract_code, 'sku' => sku)
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module FastshopCatalog
2
+ class ServiceException < Exception
3
+ attr_accessor :code, :description
4
+
5
+ def initialize(params={})
6
+ @code = params[:code]
7
+ @description = params[:description]
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module FastshopCatalog
2
+
3
+ class Time < Time
4
+ def to_json(*a)
5
+ date_serializer(self)
6
+ end
7
+
8
+ protected
9
+ # .NET compatible formatter
10
+ def date_serializer(datetime)
11
+ "\"\\/Date(#{(datetime.to_f*1000).to_i}#{datetime.utc_offset})\\/\""
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module FastshopCatalog
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ require "savon"
2
+ require "json"
3
+ require_relative "fastshop_catalog/version"
4
+ require_relative "fastshop_catalog/base_entity"
5
+ require_relative "fastshop_catalog/time"
6
+ require_relative "fastshop_catalog/entity/order"
7
+ require_relative "fastshop_catalog/entity/order_item"
8
+ require_relative "fastshop_catalog/entity/participant"
9
+ require_relative "fastshop_catalog/entity/address"
10
+ require_relative "fastshop_catalog/entity/business_unity"
11
+ require_relative "fastshop_catalog/base_service"
12
+ require_relative "fastshop_catalog/catalog_service"
13
+ require_relative "fastshop_catalog/product_service"
14
+ require_relative "fastshop_catalog/external_dne_service"
15
+ require_relative "fastshop_catalog/order_placement_service"
16
+ require_relative "fastshop_catalog/check_availability_service"
17
+ require_relative "fastshop_catalog/order_status_service"
18
+ require_relative "fastshop_catalog/participant_service"
19
+ require_relative "fastshop_catalog/service_exception"
20
+ HTTPI.log_level = :info