sigep_web 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sigep_web (0.2.4)
4
+ sigep_web (0.2.6)
5
5
  nokogiri (~> 1.6)
6
- savon (~> 2.10.0)
6
+ savon (~> 2.10, >= 2.10.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
@@ -15,13 +15,14 @@ GEM
15
15
  diff-lcs (1.2.5)
16
16
  gyoku (1.3.1)
17
17
  builder (>= 2.1.2)
18
- httpi (2.4.1)
18
+ httpi (2.4.2)
19
19
  rack
20
+ socksify
20
21
  macaddr (1.7.1)
21
22
  systemu (~> 2.6.2)
22
- mini_portile2 (2.0.0)
23
- nokogiri (1.6.7.2)
24
- mini_portile2 (~> 2.0.0.rc2)
23
+ mini_portile2 (2.1.0)
24
+ nokogiri (1.6.8.1)
25
+ mini_portile2 (~> 2.1.0)
25
26
  nori (2.6.0)
26
27
  rack (1.6.4)
27
28
  rake (10.4.2)
@@ -47,6 +48,7 @@ GEM
47
48
  nori (~> 2.4)
48
49
  uuid (~> 2.3.7)
49
50
  wasabi (~> 3.4)
51
+ socksify (1.7.0)
50
52
  systemu (2.6.5)
51
53
  uuid (2.3.8)
52
54
  macaddr (~> 1.0)
@@ -64,4 +66,4 @@ DEPENDENCIES
64
66
  sigep_web!
65
67
 
66
68
  BUNDLED WITH
67
- 1.11.2
69
+ 1.13.5
data/README.md CHANGED
@@ -1,11 +1,115 @@
1
- # sigep_web
1
+ # Sigep Web
2
2
 
3
3
  [![Build Status](https://travis-ci.org/Sidoniuns/sigep_web.svg?branch=master)](https://travis-ci.org/Sidoniuns/sigep_web)
4
4
  [![Gem Version](https://badge.fury.io/rb/sigep_web.svg)](https://badge.fury.io/rb/sigep_web)
5
5
  [![Code Climate](https://codeclimate.com/github/Sidoniuns/sigep_web/badges/gpa.svg)](https://codeclimate.com/github/Sidoniuns/sigep_web)
6
6
 
7
- ## Installation
8
- gem install sigep_web
7
+ ## About
9
8
 
10
- ## Usage
11
- require 'sigep_web'
9
+ This gem provide a easy way to integrate an application to Correios Sigep Web API, all features is based on this API documentation [http://goo.gl/UglwTj](http://goo.gl/UglwTj)
10
+
11
+ ## Getting started
12
+
13
+ You can add it to your Gemfile with:
14
+
15
+ ``` ruby
16
+ gem 'sigep_web'
17
+ ```
18
+
19
+ or in your console:
20
+
21
+ ``` ruby
22
+ gem install sigep_web
23
+ ```
24
+
25
+ ### Configuration
26
+
27
+ If you are using Rails put this in your environments configuration files:
28
+
29
+ ``` ruby
30
+ SigepWeb.configure do |config|
31
+ config.user = 'YOUR_USER'
32
+ config.password = 'YOUR_PASSWORD'
33
+ config.administrative_code = 'YOUR_ADM_CODE'
34
+ config.card = 'YOUR_CARD_NUMBER'
35
+ config.contract = 'YOUR_CONTRACT_NUMBER'
36
+ end
37
+ ```
38
+ ### How It Works
39
+
40
+ #### Consulting service availability
41
+
42
+ This check whether a particular service is available from source zip code to target zip code.
43
+
44
+ ``` ruby
45
+ SigepWeb.service_availability(service_number: '40215', source_zip: '70002900', target_zip: '74730490')
46
+ ```
47
+
48
+ This method will return a hash like this if has a success response, the second attribute indicate if a particular service is available.
49
+
50
+ ``` ruby
51
+ { :success => true, :response => true }
52
+ ```
53
+
54
+ #### Search Client
55
+ This method return the available services of specific post card
56
+
57
+ ``` ruby
58
+ SigepWeb.search_client(id_contract: "0000000000", id_post_card: "0000000000")
59
+ ```
60
+
61
+ The method will return something like this
62
+
63
+ ``` ruby
64
+ {
65
+ :success => true,
66
+ :response => {
67
+ :cnpj => '0000000000',
68
+ :contratos => {
69
+ :cartoes_postage => {
70
+ :codigo_administrativo => '000000000',
71
+ :numero => '000000000',
72
+ :servicos => [
73
+ {
74
+ :codigo => '40096',
75
+ :descricao => 'SEDEX - CONTRATO',
76
+ :id => '104625'
77
+ },
78
+ ...
79
+ ]
80
+ }
81
+ }
82
+ }
83
+ }
84
+ ```
85
+
86
+ #### Zip Query
87
+ This method return the address based on zip code
88
+
89
+ ``` ruby
90
+ SigepWeb.zip_query(zip: "70002900")
91
+ ```
92
+
93
+ This method will return a hash like this
94
+
95
+ ``` ruby
96
+ {
97
+ :success => true,
98
+ :response => {
99
+ :bairro => 'Asa Norte',
100
+ :cep => '70002900',
101
+ :cidade => 'Brasília',
102
+ :complemento => nil,
103
+ :complemento2 => nil,
104
+ :end => 'SBN Quadra 1 Bloco A',
105
+ :id => '0',
106
+ :uf => 'DF'
107
+ }
108
+ }
109
+ ```
110
+
111
+ #### Request Labels For Posts
112
+ Return one label or a range of labels to use for posts
113
+ ``` ruby
114
+ SigepWeb.request_labels(receiver_type: "C", identifier: "00000000000000", id_service: "104625", qt_labels: 1)
115
+ ```
data/bin/console CHANGED
File without changes
data/bin/setup CHANGED
File without changes
@@ -28,77 +28,46 @@ module SigepWeb
28
28
  xml.correioslog do
29
29
  xml.tipo_arquivo 'Postagem'
30
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
-
31
+ plp_xml
32
+ receiver_xml
56
33
  xml.forma_pagamento @payment_form
57
34
 
58
35
  XML::PostalObject.new(xml, @postal_objects).build_xml
59
36
  end
60
37
  end
61
38
 
62
- builder.to_xml.gsub(/\n/, '').encode(Encoding::UTF_8)
39
+ builder.to_xml.delete(/\n/).encode(Encoding::UTF_8)
63
40
  end
64
41
 
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
42
+ private
94
43
 
95
- xml.forma_pagamento @payment_form
96
-
97
- XML::PostalObject.new(xml, @postal_objects).build_xml
98
- end
44
+ def plp_xml (xml)
45
+ xml.plp do
46
+ xml.id_plp
47
+ xml.valor_global
48
+ xml.mcu_unidade_postagem
49
+ xml.nome_unidade_postagem
50
+ xml.cartao_postagem @card
99
51
  end
52
+ end
100
53
 
101
- builder.to_xml.encode(Encoding::UTF_8)
54
+ def receiver_xml (xml)
55
+ xml.remetente do
56
+ xml.numero_contrato @contract_number
57
+ xml.numero_diretoria @directorship_number
58
+ xml.codigo_administrativo @administrative_code
59
+ xml.nome_remetente { xml.cdata @name }
60
+ xml.logradouro_remetente { xml.cdata @address }
61
+ xml.numero_remetente @number
62
+ xml.complemento_remetente { xml.cdata @complement }
63
+ xml.bairro_remetente { xml.cdata @neighborhood }
64
+ xml.cep_remetente { xml.cdata @zip_code }
65
+ xml.cidade_remetente { xml.cdata @city }
66
+ xml.uf_remetente @uf
67
+ xml.telefone_remetente { xml.cdata @phone }
68
+ xml.fax_remetente { xml.cdata @fax }
69
+ xml.email_remetente { xml.cdata @email }
70
+ end
102
71
  end
103
72
  end
104
73
  end
@@ -0,0 +1,31 @@
1
+ module SigepWeb
2
+ class CalculateDigitChecker < WebServiceReverseLogisticApi
3
+ def initialize(options = {})
4
+ @number = options[:number]
5
+ super()
6
+ end
7
+
8
+ def request
9
+ authenticate = SigepWeb.configuration.authenticate
10
+
11
+ begin
12
+ response = process(:calcular_digito_verificador, {
13
+ usuario: authenticate.user,
14
+ senha: authenticate.password,
15
+ codAdministrativo: authenticate.administrative_code,
16
+ numero: @number
17
+ }).to_hash[:calcular_digito_verificador_response][:return]
18
+
19
+ {
20
+ success: true,
21
+ response: response
22
+ }
23
+ rescue Savon::SOAPFault => msg
24
+ {
25
+ success: false,
26
+ error: msg
27
+ }
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,36 @@
1
+ module SigepWeb
2
+ class RequestRange < WebServiceReverseLogisticApi
3
+ def initialize(options = {})
4
+ @type = options[:type]
5
+ @service = options[:service]
6
+ @quantity = options[:quantity]
7
+ super()
8
+ end
9
+
10
+ def request
11
+ authenticate = SigepWeb.configuration.authenticate
12
+
13
+ begin
14
+ response = process(:solicitar_range, {
15
+ usuario: authenticate.user,
16
+ senha: authenticate.password,
17
+ codAdministrativo: authenticate.administrative_code,
18
+ contrato: authenticate.contract,
19
+ tipo: @type,
20
+ servico: @service,
21
+ quantidade: @quantity
22
+ }).to_hash[:solicitar_range_response][:return]
23
+
24
+ {
25
+ success: true,
26
+ response: response
27
+ }
28
+ rescue Savon::SOAPFault => msg
29
+ {
30
+ success: false,
31
+ error: msg
32
+ }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module SigepWeb
2
- VERSION = "0.2.5"
2
+ VERSION = '0.2.6'
3
3
  end
@@ -1,15 +1,23 @@
1
1
  module SigepWeb
2
2
  class WebServiceReverseLogisticApi
3
3
  def initialize
4
- @client = Savon.client({ wsdl: url })
4
+ @client = Savon.client({
5
+ wsdl: url,
6
+ ssl_verify_mode: :none
7
+ })
5
8
  end
6
9
 
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
10
+ def process(method, message)
11
+ @client.call(method, soap_action: "", message: message)
13
12
  end
13
+
14
+ private
15
+ def url
16
+ if ENV['GEM_ENV'] == 'test'
17
+ 'http://webservicescolhomologacao.correios.com.br/ScolWeb/WebServiceScol?wsdl'
18
+ else
19
+ 'http://webservicescol.correios.com.br/ScolWeb/WebServiceScol?wsdl'
20
+ end
21
+ end
14
22
  end
15
23
  end
@@ -13,7 +13,7 @@ module SigepWeb
13
13
 
14
14
  {
15
15
  success: true,
16
- response: ApiResponse.new(response)
16
+ response: response
17
17
  }
18
18
  rescue Savon::SOAPFault => msg
19
19
  {
@@ -23,20 +23,4 @@ module SigepWeb
23
23
  end
24
24
  end
25
25
  end
26
-
27
- class ApiResponse
28
- attr_reader :neighborhood, :zip, :city, :complement, :other_complement,
29
- :address, :id, :uf
30
-
31
- def initialize(options = {})
32
- @neighborhood = options[:bairro]
33
- @zip = options[:cep]
34
- @city = options[:cidade]
35
- @complement = options[:complemento]
36
- @other_complement = options[:complemento2]
37
- @address = options[:end]
38
- @id = options[:id]
39
- @uf = options[:uf]
40
- end
41
- end
42
26
  end
data/lib/sigep_web.rb CHANGED
@@ -20,6 +20,8 @@ require 'sigep_web/generate_labels_digit_verifier'
20
20
  require 'sigep_web/request_plp_services'
21
21
  require 'sigep_web/postage_card_status'
22
22
  require 'sigep_web/request_xml_plp'
23
+ require 'sigep_web/request_range'
24
+ require 'sigep_web/calculate_digit_checker'
23
25
  require 'savon'
24
26
  require 'nokogiri'
25
27
 
@@ -63,4 +65,12 @@ module SigepWeb
63
65
  def self.request_xml_plp(options = {})
64
66
  RequestXmlPlp.new(options).request
65
67
  end
68
+
69
+ def self.request_range(options = {})
70
+ RequestRange.new(options).request
71
+ end
72
+
73
+ def self.calculate_digit_checker(options = {})
74
+ CalculateDigitChecker.new(options).request
75
+ end
66
76
  end
data/sigep_web.gemspec CHANGED
@@ -4,15 +4,15 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'sigep_web/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "sigep_web"
7
+ spec.name = 'sigep_web'
8
8
  spec.version = SigepWeb::VERSION
9
- spec.authors = ["Marcelo Perini Veloso\n\n"]
10
- spec.email = ["marcelo.perini.veloso@gmail.com"]
9
+ spec.authors = ['Marcelo Perini Veloso\n\n']
10
+ spec.email = ['marcelo.perini.veloso@gmail.com']
11
11
 
12
12
  spec.summary = %q{A gem to integrate Sigep Web API}
13
13
  spec.description = %q{This gem provide a easy way to integrate an application to Correios Sigep Web API}
14
- spec.homepage = "https://github.com/Sidoniuns/sigep_web"
15
- spec.license = "MIT"
14
+ spec.homepage = 'https://github.com/Sidoniuns/sigep_web'
15
+ spec.license = 'MIT'
16
16
 
17
17
  spec.rubyforge_project = 'sigep_web'
18
18
 
@@ -25,14 +25,14 @@ Gem::Specification.new do |spec|
25
25
  # end
26
26
 
27
27
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
- spec.bindir = "exe"
28
+ spec.bindir = 'exe'
29
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
- spec.require_paths = ["lib"]
30
+ spec.require_paths = ['lib']
31
31
 
32
- spec.add_dependency "savon" , "~> 2.10.0"
33
- spec.add_dependency "nokogiri" , "~> 1.6"
32
+ spec.add_dependency 'savon', '~> 2.10', '>= 2.10.0'
33
+ spec.add_dependency 'nokogiri', '~> 1.6'
34
34
 
35
- spec.add_development_dependency "bundler" , "~> 1.11"
36
- spec.add_development_dependency "rake" , "~> 10.0"
37
- spec.add_development_dependency "rspec" , "~> 3.0"
35
+ spec.add_development_dependency 'bundler', '~> 1.11'
36
+ spec.add_development_dependency 'rake', '~> 10.0'
37
+ spec.add_development_dependency 'rspec', '~> 3.0'
38
38
  end
metadata CHANGED
@@ -1,22 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sigep_web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
- - |+
8
- Marcelo Perini Veloso
9
-
7
+ - Marcelo Perini Veloso\n\n
10
8
  autorequire:
11
9
  bindir: exe
12
10
  cert_chain: []
13
- date: 2016-02-12 00:00:00.000000000 Z
11
+ date: 2016-10-25 00:00:00.000000000 Z
14
12
  dependencies:
15
13
  - !ruby/object:Gem::Dependency
16
14
  name: savon
17
15
  requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
17
  - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.10'
20
+ - - ">="
20
21
  - !ruby/object:Gem::Version
21
22
  version: 2.10.0
22
23
  type: :runtime
@@ -24,6 +25,9 @@ dependencies:
24
25
  version_requirements: !ruby/object:Gem::Requirement
25
26
  requirements:
26
27
  - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.10'
30
+ - - ">="
27
31
  - !ruby/object:Gem::Version
28
32
  version: 2.10.0
29
33
  - !ruby/object:Gem::Dependency
@@ -90,8 +94,10 @@ executables: []
90
94
  extensions: []
91
95
  extra_rdoc_files: []
92
96
  files:
97
+ - ".codeclimate.yml"
93
98
  - ".gitignore"
94
99
  - ".rspec"
100
+ - ".rubocop.yml"
95
101
  - ".travis.yml"
96
102
  - CODE_OF_CONDUCT.md
97
103
  - Gemfile
@@ -113,11 +119,13 @@ files:
113
119
  - lib/sigep_web/XML/postal_object.rb
114
120
  - lib/sigep_web/XML/receiver.rb
115
121
  - lib/sigep_web/authenticate.rb
122
+ - lib/sigep_web/calculate_digit_checker.rb
116
123
  - lib/sigep_web/configuration.rb
117
124
  - lib/sigep_web/generate_labels_digit_verifier.rb
118
125
  - lib/sigep_web/postage_card_status.rb
119
126
  - lib/sigep_web/request_labels.rb
120
127
  - lib/sigep_web/request_plp_services.rb
128
+ - lib/sigep_web/request_range.rb
121
129
  - lib/sigep_web/request_xml_plp.rb
122
130
  - lib/sigep_web/search_client.rb
123
131
  - lib/sigep_web/service_availability.rb
@@ -146,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
154
  version: '0'
147
155
  requirements: []
148
156
  rubyforge_project: sigep_web
149
- rubygems_version: 2.1.9
157
+ rubygems_version: 2.5.1
150
158
  signing_key:
151
159
  specification_version: 4
152
160
  summary: A gem to integrate Sigep Web API