sigep_web 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
+ SHA1:
3
+ metadata.gz: 9fc28601ecbf768efbebd5130539958d36847beb
4
+ data.tar.gz: 3a682d3a51186f5ea8088dca08322ca15f07a36e
5
+ SHA512:
6
+ metadata.gz: 2f6df7ed2b7b2a88dfa386216f0ffcc86da293339e5d3467ddfd61b0e7e187cf937af1164a54890849008e22516ee6e01c19376a5dcf12ea1720b71a65a186be
7
+ data.tar.gz: 04937b4274095b080eb7d9805c50c941fbb522617d98e16b9b858885080ae8303c20e03b474dbacf3d43a674cb0657085de54ccc5e0a4533ecadb6499b044987
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.4
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at marcelo.perini.veloso@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sigep_web.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sigep_web (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ akami (1.3.1)
10
+ gyoku (>= 0.4.0)
11
+ nokogiri
12
+ builder (3.2.2)
13
+ diff-lcs (1.2.5)
14
+ gyoku (1.3.1)
15
+ builder (>= 2.1.2)
16
+ httpi (2.4.1)
17
+ rack
18
+ macaddr (1.7.1)
19
+ systemu (~> 2.6.2)
20
+ mini_portile2 (2.0.0)
21
+ nokogiri (1.6.7.1)
22
+ mini_portile2 (~> 2.0.0.rc2)
23
+ nori (2.6.0)
24
+ rack (1.6.4)
25
+ rake (10.4.2)
26
+ rspec (3.4.0)
27
+ rspec-core (~> 3.4.0)
28
+ rspec-expectations (~> 3.4.0)
29
+ rspec-mocks (~> 3.4.0)
30
+ rspec-core (3.4.1)
31
+ rspec-support (~> 3.4.0)
32
+ rspec-expectations (3.4.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.4.0)
35
+ rspec-mocks (3.4.1)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.4.0)
38
+ rspec-support (3.4.1)
39
+ savon (2.10.1)
40
+ akami (~> 1.2)
41
+ builder (>= 2.1.2)
42
+ gyoku (~> 1.2)
43
+ httpi (~> 2.3)
44
+ nokogiri (>= 1.4.0)
45
+ nori (~> 2.4)
46
+ uuid (~> 2.3.7)
47
+ wasabi (~> 3.4)
48
+ systemu (2.6.5)
49
+ uuid (2.3.8)
50
+ macaddr (~> 1.0)
51
+ wasabi (3.5.0)
52
+ httpi (~> 2.0)
53
+ nokogiri (>= 1.4.2)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ bundler (~> 1.11)
60
+ nokogiri (~> 1.6)
61
+ rake (~> 10.0)
62
+ rspec (~> 3.0)
63
+ savon (~> 2.10.0)
64
+ sigep_web!
65
+
66
+ BUNDLED WITH
67
+ 1.11.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Marcelo Perini Veloso
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,23 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Marcelo Perini Veloso
4
+
5
+
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # sigep_web
2
+
3
+ [![Build Status](https://travis-ci.org/Sidoniuns/sigep_web.svg?branch=master)](https://travis-ci.org/Sidoniuns/sigep_web)
4
+
5
+ ## Installation
6
+ gem install sigep_web
7
+
8
+ ## Usage
9
+ require 'sigep_web'
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ #RSpec::Core::RakeTask.new(:spec)
5
+ RSpec::Core::RakeTask.new
6
+
7
+ task :default => :spec
8
+ task :test => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sigep_web"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/sigep_web.rb ADDED
@@ -0,0 +1,61 @@
1
+ require 'sigep_web/version'
2
+ require 'sigep_web/configuration'
3
+ require 'sigep_web/web_service_interface_api'
4
+ require 'sigep_web/web_service_reverse_logistic_api'
5
+ require 'sigep_web/authenticate'
6
+ require 'sigep_web/XML/postal_object'
7
+ require 'sigep_web/XML/receiver'
8
+ require 'sigep_web/XML/additional_service'
9
+ require 'sigep_web/XML/dimension_object'
10
+ require 'sigep_web/Models/sender'
11
+ require 'sigep_web/Models/postal_object'
12
+ require 'sigep_web/Models/receiver'
13
+ require 'sigep_web/Models/additional_service'
14
+ require 'sigep_web/Models/dimension_object'
15
+ require 'sigep_web/service_availability'
16
+ require 'sigep_web/search_client'
17
+ require 'sigep_web/zip_query'
18
+ require 'sigep_web/request_labels'
19
+ require 'sigep_web/generate_labels_digit_verifier'
20
+ require 'sigep_web/request_plp_services'
21
+ require 'sigep_web/postage_card_status'
22
+ require 'savon'
23
+ require 'nokogiri'
24
+
25
+ module SigepWeb
26
+ def self.configure
27
+ yield(configuration)
28
+ end
29
+
30
+ def self.configuration
31
+ @configuration ||= Configuration.new
32
+ end
33
+
34
+ def self.service_availability(options = {})
35
+ ServiceAvailability.new(options)
36
+ end
37
+
38
+ def self.search_client(options = {})
39
+ SearchClient.new(options)
40
+ end
41
+
42
+ def self.zip_query(options = {})
43
+ ZipQuery.new(options)
44
+ end
45
+
46
+ def self.request_labels(options = {})
47
+ RequestLabels.new(options)
48
+ end
49
+
50
+ def self.generate_labels_digit_verifier(options = {})
51
+ GenerateLabelsDigitVerifier.new(options)
52
+ end
53
+
54
+ def self.request_plp_services(options = {})
55
+ RequestPlpServices.new(options)
56
+ end
57
+
58
+ def self.postage_card_status(options = {})
59
+ PostageCardStatus.new(options)
60
+ end
61
+ end
@@ -0,0 +1,12 @@
1
+ module SigepWeb
2
+ module Models
3
+ class AdditionalService
4
+ attr_accessor :codes, :declareted_value
5
+
6
+ def initialize(options = {})
7
+ @codes = options[:codes]
8
+ @declareted_value = options[:declareted_value]
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,15 @@
1
+ module SigepWeb
2
+ module Models
3
+ class DimensionObject
4
+ attr_accessor :object_type, :height, :width, :length, :diameter
5
+
6
+ def initialize(options = {})
7
+ @object_type = options[:object_type]
8
+ @height = options[:height]
9
+ @width = options[:width]
10
+ @length = options[:length]
11
+ @diameter = options[:diameter]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,21 @@
1
+ module SigepWeb
2
+ module Models
3
+ class PostalObject
4
+ attr_accessor :label_number, :postage_code_service, :cubage,
5
+ :weight, :receiver, :dimension_object, :processing_status,
6
+ :additional_service_codes, :additional_services_declared_value
7
+
8
+ def initialize(options = {})
9
+ @label_number = options[:label_number]
10
+ @postage_code_service = options[:postage_code_service]
11
+ @cubage = options[:cubage]
12
+ @weight = options[:weight]
13
+ @receiver = options[:receiver]
14
+ @dimension_object = options[:dimension_object]
15
+ @processing_status = options[:processing_status]
16
+ @additional_service_codes = options[:additional_service_codes]
17
+ @additional_services_declared_value = options[:additional_services_declared_value]
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ module SigepWeb
2
+ module Models
3
+ class Receiver
4
+ attr_accessor :name, :phone, :cellphone, :email, :address,
5
+ :complement, :neighborhood, :city, :uf, :cep, :number,
6
+ :user_postal_code, :cost_center_client, :invoice_number,
7
+ :invoice_serie, :invoice_value, :invoice_nature,
8
+ :description_object, :amount
9
+
10
+ def initialize(options = {})
11
+ @name = options[:name]
12
+ @phone = options[:phone]
13
+ @cellphone = options[:cellphone]
14
+ @email = options[:email]
15
+ @address = options[:address]
16
+ @complement = options[:complement]
17
+ @number = options[:number]
18
+ @neighborhood = options[:neighborhood]
19
+ @city = options[:city]
20
+ @uf = options[:uf]
21
+ @cep = options[:cep]
22
+ @user_postal_code = options[:user_postal_code]
23
+ @cost_center_client = options[:cost_center_client]
24
+ @invoice_number = options[:invoice_number]
25
+ @invoice_serie = options[:invoice_serie]
26
+ @invoice_value = options[:invoice_value]
27
+ @invoice_nature = options[:invoice_nature]
28
+ @description_object = options[:description_object]
29
+ @amount = options[:amount]
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,105 @@
1
+ module SigepWeb
2
+ module Models
3
+ class Sender
4
+ def initialize(options = {})
5
+ authenticate = SigepWeb.configuration.authenticate
6
+
7
+ @card = authenticate.card
8
+ @contract_number = authenticate.contract
9
+ @directorship_number = options[:directorship_number]
10
+ @administrative_code = authenticate.administrative_code
11
+ @name = options[:name]
12
+ @address = options[:address]
13
+ @number = options[:number]
14
+ @complement = options[:complement]
15
+ @neighborhood = options[:neighborhood]
16
+ @zip_code = options[:zip_code]
17
+ @city = options[:city]
18
+ @uf = options[:uf]
19
+ @phone = options[:phone]
20
+ @fax = options[:fax]
21
+ @email = options[:email]
22
+ @payment_form = options[:payment_form]
23
+ @postal_objects = options[:postal_objects]
24
+ end
25
+
26
+ def to_xml
27
+ builder = Nokogiri::XML::Builder.new(encoding: 'ISO-8859-1') do |xml|
28
+ xml.correioslog do
29
+ xml.tipo_arquivo 'Postagem'
30
+ xml.versao_arquivo '2.3'
31
+ xml.plp do
32
+ xml.id_plp
33
+ xml.valor_global
34
+ xml.mcu_unidade_postagem
35
+ xml.nome_unidade_postagem
36
+ xml.cartao_postagem @card
37
+ end
38
+
39
+ xml.remetente do
40
+ xml.numero_contrato @contract_number
41
+ xml.numero_diretoria @directorship_number
42
+ xml.codigo_administrativo @administrative_code
43
+ xml.nome_remetente { xml.cdata @name }
44
+ xml.logradouro_remetente { xml.cdata @address }
45
+ xml.numero_remetente @number
46
+ xml.complemento_remetente { xml.cdata @complement }
47
+ xml.bairro_remetente { xml.cdata @neighborhood }
48
+ xml.cep_remetente { xml.cdata @zip_code }
49
+ xml.cidade_remetente { xml.cdata @city }
50
+ xml.uf_remetente @uf
51
+ xml.telefone_remetente { xml.cdata @phone }
52
+ xml.fax_remetente { xml.cdata @fax }
53
+ xml.email_remetente { xml.cdata @email }
54
+ end
55
+
56
+ xml.forma_pagamento @payment_form
57
+
58
+ XML::PostalObject.new(xml, @postal_objects).build_xml
59
+ end
60
+ end
61
+
62
+ builder.to_xml.gsub(/\n/, '').encode(Encoding::UTF_8)
63
+ end
64
+
65
+ def example_xml
66
+ builder = Nokogiri::XML::Builder.new(encoding: 'ISO-8859-1') do |xml|
67
+ xml.correioslog do
68
+ xml.tipo_arquivo 'Postagem'
69
+ xml.versao_arquivo '2.3'
70
+ xml.plp do
71
+ xml.id_plp
72
+ xml.valor_global
73
+ xml.mcu_unidade_postagem
74
+ xml.nome_unidade_postagem
75
+ xml.cartao_postagem @card
76
+ end
77
+
78
+ xml.remetente do
79
+ xml.numero_contrato @contract_number
80
+ xml.numero_diretoria @directorship_number
81
+ xml.codigo_administrativo @administrative_code
82
+ xml.nome_remetente { xml.cdata @name }
83
+ xml.logradouro_remetente { xml.cdata @address }
84
+ xml.numero_remetente @number
85
+ xml.complemento_remetente { xml.cdata @complement }
86
+ xml.bairro_remetente { xml.cdata @neighborhood }
87
+ xml.cep_remetente { xml.cdata @zip_code }
88
+ xml.cidade_remetente { xml.cdata @city }
89
+ xml.uf_remetente @uf
90
+ xml.telefone_remetente { xml.cdata @phone }
91
+ xml.fax_remetente { xml.cdata @fax }
92
+ xml.email_remetente { xml.cdata @email }
93
+ end
94
+
95
+ xml.forma_pagamento @payment_form
96
+
97
+ XML::PostalObject.new(xml, @postal_objects).build_xml
98
+ end
99
+ end
100
+
101
+ builder.to_xml.encode(Encoding::UTF_8)
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,24 @@
1
+ module SigepWeb
2
+ module XML
3
+ class AdditionalService
4
+ def initialize(builder, additional_service)
5
+ @builder = builder
6
+ @additional_service = additional_service
7
+ end
8
+
9
+ def build_xml
10
+ @builder.servico_adicional do
11
+ if @additional_service
12
+ @additional_service.codes.each do |code|
13
+ @builder.codigo_servico_adicional code
14
+ end
15
+
16
+ @builder.codigo_servico_adicional "025"
17
+
18
+ @builder.valor_declarado @additional_service.declareted_value
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ module SigepWeb
2
+ module XML
3
+ class DimensionObject
4
+ def initialize(builder, dimension_object)
5
+ @builder = builder
6
+ @dimension_object = dimension_object
7
+ end
8
+
9
+ def build_xml
10
+ @builder.dimensao_objeto do
11
+ @builder.tipo_objeto @dimension_object.object_type
12
+ @builder.dimensao_altura @dimension_object.height
13
+ @builder.dimensao_largura @dimension_object.width
14
+ @builder.dimensao_comprimento @dimension_object.length
15
+ @builder.dimensao_diametro @dimension_object.diameter
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,50 @@
1
+ module SigepWeb
2
+ module XML
3
+ class PostalObject
4
+ def initialize(builder, postal_objects = [])
5
+ @builder = builder
6
+ @postal_objects = postal_objects
7
+ end
8
+
9
+ def build_xml
10
+ @postal_objects.each do |postal_object|
11
+ @builder.objeto_postal do
12
+ build_object(postal_object)
13
+ end
14
+ end
15
+ end
16
+
17
+ private
18
+ def build_object(postal_object)
19
+ @builder.numero_etiqueta postal_object.label_number
20
+ @builder.codigo_objeto_cliente
21
+ @builder.codigo_servico_postagem postal_object.postage_code_service
22
+ @builder.cubagem postal_object.cubage
23
+ @builder.peso postal_object.weight
24
+ @builder.rt1
25
+ @builder.rt2
26
+
27
+ XML::Receiver.new(@builder, postal_object.receiver).build_xml
28
+
29
+ @builder.servico_adicional do
30
+ @builder.codigo_servico_adicional "025"
31
+
32
+ if postal_object.additional_service_codes
33
+ postal_object.additional_service_codes.each do |code|
34
+ @builder.codigo_servico_adicional code
35
+ end
36
+ end
37
+
38
+ @builder.valor_declarado postal_object.additional_services_declared_value
39
+ end
40
+
41
+ XML::DimensionObject.new(@builder, postal_object.dimension_object).build_xml
42
+
43
+ @builder.data_postagem_sara
44
+ @builder.status_processamento postal_object.processing_status
45
+ @builder.numero_comprovante_postagem
46
+ @builder.valor_cobrado
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,37 @@
1
+ module SigepWeb
2
+ module XML
3
+ class Receiver
4
+ def initialize(builder, receiver)
5
+ @builder = builder
6
+ @receiver = receiver
7
+ end
8
+
9
+ def build_xml
10
+ @builder.destinatario do
11
+ @builder.nome_destinatario { @builder.cdata @receiver.name }
12
+ @builder.telefone_destinatario { @builder.cdata @receiver.phone }
13
+ @builder.celular_destinatario { @builder.cdata @receiver.cellphone }
14
+ @builder.email_destinatario { @builder.cdata @receiver.email }
15
+ @builder.logradouro_destinatario { @builder.cdata @receiver.address }
16
+ @builder.complemento_destinatario { @builder.cdata @receiver.complement }
17
+ @builder.numero_end_destinatario @receiver.number
18
+ end
19
+
20
+ @builder.nacional do
21
+ @builder.bairro_destinatario { @builder.cdata @receiver.neighborhood }
22
+ @builder.cidade_destinatario { @builder.cdata @receiver.city }
23
+ @builder.uf_destinatario @receiver.uf
24
+ @builder.cep_destinatario { @builder.cdata @receiver.cep }
25
+ @builder.codigo_usuario_postal @receiver.user_postal_code
26
+ @builder.centro_custo_cliente @receiver.cost_center_client
27
+ @builder.numero_nota_fiscal @receiver.invoice_number
28
+ @builder.serie_nota_fiscal @receiver.invoice_serie
29
+ @builder.valor_nota_fiscal @receiver.invoice_value
30
+ @builder.natureza_nota_fiscal @receiver.invoice_nature
31
+ @builder.descricao_objeto { @builder.cdata @receiver.description_object }
32
+ @builder.valor_a_cobrar @receiver.amount
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,14 @@
1
+ module SigepWeb
2
+ class Authenticate
3
+ attr_accessor :user, :password, :administrative_code,
4
+ :contract, :card
5
+
6
+ def initialize(options = {})
7
+ self.user = options[:user]
8
+ self.password = options[:password]
9
+ self.administrative_code = options[:administrative_code]
10
+ self.contract = options[:contract]
11
+ self.card = options[:card]
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ module SigepWeb
2
+ class Configuration
3
+ attr_accessor :user, :password, :administrative_code,
4
+ :contract, :card
5
+
6
+ def authenticate
7
+ @authenticate ||=
8
+ Authenticate.new(user: user, password: password,
9
+ administrative_code: administrative_code,
10
+ contract: contract, card: card)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ module SigepWeb
2
+ class GenerateLabelsDigitVerifier < WebServiceInterfaceApi
3
+ def initialize(options = {})
4
+ @labels = options[:labels]
5
+ super()
6
+ end
7
+
8
+ def request
9
+ authenticate = SigepWeb.configuration.authenticate
10
+ begin
11
+ process(:gera_digito_verificador_etiquetas, {
12
+ etiquetas: @labels,
13
+ usuario: authenticate.user,
14
+ senha: authenticate.password
15
+ }).to_hash[:gera_digito_verificador_etiquetas_response][:return]
16
+ rescue Savon::SOAPFault => msg
17
+ msg
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module SigepWeb
2
+ class PostageCardStatus < WebServiceInterfaceApi
3
+ def initialize(options = {})
4
+ @postage_number_card = options[:postage_number_card]
5
+ super()
6
+ end
7
+
8
+ def request
9
+ authenticate = SigepWeb.configuration.authenticate
10
+ begin
11
+ process(:get_status_cartao_postagem, {
12
+ numeroCartaoPostagem: @postage_number_card,
13
+ usuario: authenticate.user,
14
+ senha: authenticate.password
15
+ }).to_hash[:get_status_cartao_postagem_response][:return]
16
+ rescue Savon::SOAPFault => msg
17
+ msg
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,46 @@
1
+ module SigepWeb
2
+ class RequestLabels < WebServiceInterfaceApi
3
+ def initialize(options = {})
4
+ @receiver_type = options[:receiver_type]
5
+ @identifier = options[:identifier]
6
+ @id_service = options[:id_service]
7
+ @qt_labels = options[:qt_labels]
8
+ super()
9
+ end
10
+
11
+ def request
12
+ authenticate = SigepWeb.configuration.authenticate
13
+ begin
14
+ response = process(:solicita_etiquetas, {
15
+ tipoDestinatario: @receiver_type,
16
+ identificador: @identifier,
17
+ idServico: @id_service,
18
+ qtdEtiquetas: @qt_labels,
19
+ usuario: authenticate.user,
20
+ senha: authenticate.password
21
+ }).to_hash[:solicita_etiquetas_response][:return]
22
+
23
+ build_label_array(response)
24
+ rescue Savon::SOAPFault => msg
25
+ msg
26
+ end
27
+ end
28
+
29
+ private
30
+ def build_label_array(label_range)
31
+ label_array = []
32
+ label_range = label_range.split(',')
33
+ label = label_range[0].to_s
34
+ label_base = label.gsub(/[\d]/, '').split(' ')
35
+ number = label.gsub(/[^\d]/, '').to_i
36
+
37
+ while number <= label_range[1].gsub(/[^\d]/, '').to_i do
38
+ label_array.push(label_base[0] + '0' + number.to_s + ' ' + label_base[1])
39
+
40
+ number += 1
41
+ end
42
+
43
+ label_array
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,27 @@
1
+ module SigepWeb
2
+ class RequestPlpServices < WebServiceInterfaceApi
3
+ def initialize(options = {})
4
+ @plp = options[:plp]
5
+ @id_plp_client = options[:id_plp_client]
6
+ #@post_card = options[:post_card]
7
+ @labels = options[:labels]
8
+ super()
9
+ end
10
+
11
+ def request
12
+ authenticate = SigepWeb.configuration.authenticate
13
+ begin
14
+ process(:fecha_plp_varios_servicos, {
15
+ xml: @plp.to_xml,
16
+ idPlpCliente: @id_plp_client,
17
+ cartaoPostagem: authenticate.card,
18
+ listaEtiquetas: @labels,
19
+ usuario: authenticate.user,
20
+ senha: authenticate.password
21
+ }).to_hash[:fecha_plp_varios_servicos_response][:return].to_s
22
+ rescue Savon::SOAPFault => msg
23
+ msg
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ module SigepWeb
2
+ class SearchClient < WebServiceInterfaceApi
3
+ def initialize(options = {})
4
+ @id_contract = options[:id_contract]
5
+ @id_post_card = options[:id_post_card]
6
+ super()
7
+ end
8
+
9
+ def request
10
+ authenticate = SigepWeb.configuration.authenticate
11
+ begin
12
+ response = process(:busca_cliente, {
13
+ idContrato: @id_contract,
14
+ idCartaoPostagem: @id_post_card,
15
+ usuario: authenticate.user,
16
+ senha: authenticate.password
17
+ })
18
+
19
+ response.to_hash[:busca_cliente_response][:return]
20
+ rescue Savon::SOAPFault => msg
21
+ msg
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ module SigepWeb
2
+ class ServiceAvailability < WebServiceInterfaceApi
3
+ def initialize(options = {})
4
+ @service_number = options[:service_number]
5
+ @source_zip = options[:source_zip]
6
+ @target_zip = options[:target_zip]
7
+ super()
8
+ end
9
+
10
+ def request
11
+ authenticate = SigepWeb.configuration.authenticate
12
+ process(:verifica_disponibilidade_servico, {
13
+ codAdministrativo: authenticate.administrative_code,
14
+ numeroServico: @service_number,
15
+ cepOrigem: @source_zip,
16
+ cepDestino: @target_zip,
17
+ usuario: authenticate.user,
18
+ senha: authenticate.password
19
+ }).to_hash[:verifica_disponibilidade_servico_response][:return]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module SigepWeb
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ module SigepWeb
2
+ class WebServiceInterfaceApi
3
+ def initialize(options = {})
4
+ if options[:encoding]
5
+ @client = Savon.client({ wsdl: url, ssl_verify_mode: :none, encoding: options[:encoding] })
6
+ else
7
+ @client = Savon.client({ wsdl: url, ssl_verify_mode: :none })
8
+ end
9
+ end
10
+
11
+ def process(method, message)
12
+ @client.call(method, soap_action: "", message: message)
13
+ end
14
+
15
+ private
16
+ def url
17
+ if ENV['GEM_ENV'] == 'test'
18
+ 'https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl'
19
+ else
20
+ 'https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl'
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ module SigepWeb
2
+ class WebServiceReverseLogisticApi
3
+ def initialize
4
+ @client = Savon.client({ wsdl: url })
5
+ end
6
+
7
+ def url
8
+ @url ||= if ENV['GEM_ENV'] == 'test'
9
+ 'http://webservicescolhomologacao.correios.com.br/ScolWeb/WebServiceScol?wsdl'
10
+ else
11
+ 'http://webservicescol.correios.com.br/ScolWeb/WebServiceScol?wsdl'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,36 @@
1
+ module SigepWeb
2
+ class ZipQuery < WebServiceInterfaceApi
3
+ def initialize(options = {})
4
+ @zip = options[:zip]
5
+ super()
6
+ end
7
+
8
+ def request
9
+ begin
10
+ response = process(:consulta_cep, {
11
+ cep: @zip
12
+ }).to_hash[:consulta_cep_response][:return]
13
+
14
+ ApiResponse.new(response)
15
+ rescue Savon::SOAPFault => msg
16
+ msg
17
+ end
18
+ end
19
+ end
20
+
21
+ class ApiResponse
22
+ attr_reader :neighborhood, :zip, :city, :complement, :other_complement,
23
+ :address, :id, :uf
24
+
25
+ def initialize(options = {})
26
+ @neighborhood = options[:bairro]
27
+ @zip = options[:cep]
28
+ @city = options[:cidade]
29
+ @complement = options[:complemento]
30
+ @other_complement = options[:complemento2]
31
+ @address = options[:end]
32
+ @id = options[:id]
33
+ @uf = options[:uf]
34
+ end
35
+ end
36
+ end
data/sigep_web.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sigep_web/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sigep_web"
8
+ spec.version = SigepWeb::VERSION
9
+ spec.authors = ["Marcelo Perini Veloso\n\n"]
10
+ spec.email = ["marcelo.perini.veloso@gmail.com"]
11
+
12
+ spec.summary = %q{A gem to integrate Sigep Web API}
13
+ spec.description = %q{This gem provide a easy way to integrate an application to Correios Sigep Web API}
14
+ spec.homepage = "http://rubygems.org/gems/sigep_web"
15
+ spec.license = "MIT"
16
+
17
+ spec.rubyforge_project = 'sigep_web'
18
+
19
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
20
+ # delete this section to allow pushing this gem to any host.
21
+ # if spec.respond_to?(:metadata)
22
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
23
+ # else
24
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
25
+ # end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler" , "~> 1.11"
33
+ spec.add_development_dependency "rake" , "~> 10.0"
34
+ spec.add_development_dependency "rspec" , "~> 3.0"
35
+ spec.add_development_dependency "savon" , "~> 2.10.0"
36
+ spec.add_development_dependency "nokogiri" , "~> 1.6"
37
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sigep_web
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - |+
8
+ Marcelo Perini Veloso
9
+
10
+ autorequire:
11
+ bindir: exe
12
+ cert_chain: []
13
+ date: 2016-01-15 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.11'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1.11'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '10.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '10.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rspec
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '3.0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: savon
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: 2.10.0
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: 2.10.0
71
+ - !ruby/object:Gem::Dependency
72
+ name: nokogiri
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '1.6'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: '1.6'
85
+ description: This gem provide a easy way to integrate an application to Correios Sigep
86
+ Web API
87
+ email:
88
+ - marcelo.perini.veloso@gmail.com
89
+ executables: []
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - ".gitignore"
94
+ - ".rspec"
95
+ - ".travis.yml"
96
+ - CODE_OF_CONDUCT.md
97
+ - Gemfile
98
+ - Gemfile.lock
99
+ - LICENSE
100
+ - LICENSE.txt
101
+ - README.md
102
+ - Rakefile
103
+ - bin/console
104
+ - bin/setup
105
+ - lib/sigep_web.rb
106
+ - lib/sigep_web/Models/additional_service.rb
107
+ - lib/sigep_web/Models/dimension_object.rb
108
+ - lib/sigep_web/Models/postal_object.rb
109
+ - lib/sigep_web/Models/receiver.rb
110
+ - lib/sigep_web/Models/sender.rb
111
+ - lib/sigep_web/XML/additional_service.rb
112
+ - lib/sigep_web/XML/dimension_object.rb
113
+ - lib/sigep_web/XML/postal_object.rb
114
+ - lib/sigep_web/XML/receiver.rb
115
+ - lib/sigep_web/authenticate.rb
116
+ - lib/sigep_web/configuration.rb
117
+ - lib/sigep_web/generate_labels_digit_verifier.rb
118
+ - lib/sigep_web/postage_card_status.rb
119
+ - lib/sigep_web/request_labels.rb
120
+ - lib/sigep_web/request_plp_services.rb
121
+ - lib/sigep_web/search_client.rb
122
+ - lib/sigep_web/service_availability.rb
123
+ - lib/sigep_web/version.rb
124
+ - lib/sigep_web/web_service_interface_api.rb
125
+ - lib/sigep_web/web_service_reverse_logistic_api.rb
126
+ - lib/sigep_web/zip_query.rb
127
+ - sigep_web.gemspec
128
+ homepage: http://rubygems.org/gems/sigep_web
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project: sigep_web
148
+ rubygems_version: 2.1.9
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: A gem to integrate Sigep Web API
152
+ test_files: []