correios-cep 0.6.8 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e4c8378bcd592532a37c92841ae2656eb703da7f4d4692a7491a3800ca84f21
4
- data.tar.gz: ced0ad3e46a2ecafb7d42f57867a2e4a05a5a67c758b0ffd396271c38ba9e137
3
+ metadata.gz: 3878236cae342f7c6e62e66a408af063068bbcf5b9afe35e306cc5a571ce8197
4
+ data.tar.gz: e7f371280e7ef7461e9d3b63412d7befb9fd9de1134e259385da642c777932ca
5
5
  SHA512:
6
- metadata.gz: bc2924d1d79a954793358f46841ceb40fe70e5e709b5269c8d7eee57a2eed275936075aadf7e5a696d51ecdad523653f1ab5a254822e8e1ab8ac2973d2e5f646
7
- data.tar.gz: 68932d624083d07f83a6b6e98f57f0c57bdfae6dc88422e5d898b086642ec649960d1f0a01d1ac0ca1493cd83164caeb9af1a0a4472bd2c4e53041b0d50d56f8
6
+ metadata.gz: a6107533785f9b1b8de191ffdf78a5525bad9da18abc057ee44394102dd6abb1d715265339c6b429eff6693448ed6e5394fa9fbe3141b9c3d6b15bd6931b20af
7
+ data.tar.gz: d8aab12e160176bc8f1f5e7796a99aaf2280cafa20e7c44cffaaaf0695192ee855d5c995bffee7be2fe2d27efbc426fcd18b44a4050b7cf61c269c99d97890e5
@@ -1,12 +1,11 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.0.0
5
- - 2.1.10
6
- - 2.2.9
7
- - 2.3.6
8
- - 2.4.3
9
- - 2.5.0
4
+ - 2.2.10
5
+ - 2.3.7
6
+ - 2.4.4
7
+ - 2.5.1
8
+ - 2.6
10
9
  - ruby-head
11
10
  - jruby
12
11
  - jruby-9
@@ -15,9 +14,11 @@ rvm:
15
14
  - rbx
16
15
  - rbx-2
17
16
  - rbx-3
17
+ - rbx-head
18
18
 
19
19
  matrix:
20
20
  allow_failures:
21
+ - rvm: 2.6
21
22
  - rvm: jruby
22
23
  - rvm: jruby-9
23
24
  - rvm: jruby-19mode
@@ -26,6 +27,7 @@ matrix:
26
27
  - rvm: rbx
27
28
  - rvm: rbx-2
28
29
  - rvm: rbx-3
30
+ - rvm: rbx-head
29
31
  fast_finish: true
30
32
 
31
33
  script: bundle exec rspec
@@ -1,5 +1,6 @@
1
1
  | Version | Changes |
2
2
  | ------- | ------- |
3
+ | 0.7.0 | Replace Net::HTTP to HTTP gem. [Issue #15](https://github.com/prodis/correios-cep/issues/15); Remove `log-me` gem. |
3
4
  | 0.6.8 | Fix parsing bug when Correios API omits "complemento" XML node in response. |
4
5
  | 0.6.7 | Update Ox gem version to `2.9`. |
5
6
  | 0.6.6 | Update Ox gem version to `2.8.4`. |
@@ -0,0 +1,10 @@
1
+ # Contributing
2
+
3
+ - Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
4
+ - Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
5
+ - Fork the project.
6
+ - Start a feature/bugfix branch.
7
+ - Commit and push until you are happy with your contribution.
8
+ - Don't forget to rebase with branch master in main project before submit the pull request.
9
+ - Make sure to add tests for it.
10
+ - Please don't change the gemspec file, Rakefile, version, or history.
data/LICENSE CHANGED
@@ -1,21 +1,201 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2014-2017 Fernando Hamasaki de Amorim
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.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright (c) 2014-2018 Fernando Hamasaki de Amorim
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
data/README.md CHANGED
@@ -1,20 +1,19 @@
1
1
  # Correios CEP
2
2
 
3
- Current available solutions to find Brazilian addresses by zipcode use an HTML form from [Correios web site](http://correios.com.br) website to perform it, instead of to use a real API.
4
-
5
- The old solution works with an HTTP request to the form, followed by parsing HTML result page. The huge problem here is when the Correios web site development team decides to modify some HTML element in the result page, even a layout update, it will break the parser logic for result.
6
-
7
- Correios CEP gem solves this problem, retrieving data directly from Correios database.
8
-
9
- ![Correios Logo](http://prodis.net.br/images/ruby/2015/correios_logo.png)
10
-
11
3
  [![Gem Version](https://badge.fury.io/rb/correios-cep.svg)](http://badge.fury.io/rb/correios-cep)
12
4
  [![Build Status](https://travis-ci.org/prodis/correios-cep.svg?branch=master)](https://travis-ci.org/prodis/correios-cep)
13
5
  [![Coverage Status](https://coveralls.io/repos/prodis/correios-cep/badge.svg?branch=master&service=github)](https://coveralls.io/github/prodis/correios-cep?branch=master)
14
6
  [![Code Climate](https://codeclimate.com/github/prodis/correios-cep/badges/gpa.svg)](https://codeclimate.com/github/prodis/correios-cep)
15
- [![Dependency Status](https://gemnasium.com/prodis/correios-cep.svg)](https://gemnasium.com/prodis/correios-cep)
16
7
  [![GitHub license](https://img.shields.io/apm/l/vim-mode.svg)](LICENSE)
17
8
 
9
+ ![Correios Logo](http://prodis.net.br/images/ruby/2015/correios_logo.png)
10
+
11
+ Current available solutions to find Brazilian addresses by zipcode use an HTML form from [Correios web site](http://correios.com.br) website to perform it, instead of to use a real API.
12
+
13
+ The old solution works with an HTTP request to the form, followed by parsing HTML result page. The huge problem here is when the Correios web site development team decides to modify some HTML element in the result page, even a layout update, it will break the parser logic for result.
14
+
15
+ Correios CEP gem solves this problem, retrieving data directly from Correios database.
16
+
18
17
  ## Installing
19
18
 
20
19
  ### Gemfile
@@ -37,28 +36,30 @@ require 'correios-cep'
37
36
 
38
37
  # With "get" instance method
39
38
  finder = Correios::CEP::AddressFinder.new
40
- address = finder.get("54250610")
39
+ address = finder.get('54250610')
41
40
 
42
41
  # With "get" class method
43
- address = Correios::CEP::AddressFinder.get("54250610")
42
+ address = Correios::CEP::AddressFinder.get('54250610')
44
43
 
45
44
  address # =>
46
45
  {
47
- :address => "Rua Fernando Amorim",
48
- :neighborhood => "Cavaleiro",
49
- :city => "Jaboatão dos Guararapes",
50
- :state => "PE",
51
- :zipcode => "54250610",
52
- :complement => ""
46
+ :address => 'Rua Fernando Amorim',
47
+ :neighborhood => 'Cavaleiro',
48
+ :city => 'Jaboatão dos Guararapes',
49
+ :state => 'PE',
50
+ :zipcode => '54250610',
51
+ :complement => ''
53
52
  }
54
53
  ```
55
54
 
55
+
56
56
  ## Configurations
57
57
 
58
+ All the configurations are set using `Correios::CEP` module.
59
+
58
60
  ### Timeout
59
61
 
60
- For default, the timeout for a request to Correios Web Service is **5 seconds**. If Correios Web Service does not respond, a `Timeout::Error` exception will be raised.
61
- You can configure this timeout using `Correios::CEP` module.
62
+ For default, the timeout for a request to Correios Web Service is **5 seconds**. If Correios Web Service does not respond, a `HTTP::TimeoutError` exception will be raised.
62
63
 
63
64
  ```ruby
64
65
  Correios::CEP.configure do |config|
@@ -67,60 +68,21 @@ end
67
68
  ```
68
69
 
69
70
  ### HTTP Proxy
70
- If you need to use an HTTP proxy to HTTP requests, configure the HTTP proxy URL on `Correios::CEP` module.
71
+ If you need to use an HTTP proxy to HTTP requests, configure HTTP proxy URL.
71
72
 
72
73
  ```ruby
73
74
  Correios::CEP.configure do |config|
74
- config.proxy_url = "http://10.20.30.40:8888"
75
+ config.proxy_url = 'http://10.20.30.40:8888'
75
76
  end
76
77
  ```
77
78
 
78
79
  ### Log
79
80
 
80
- For default, each request to Correios Web service is logged to STDOUT, with **:info** log level, using the gem [LogMe](http://github.com/prodis/log-me).
81
-
82
- Log example:
83
-
84
- ```xml
85
- I, [2014-02-14T00:10:12.718413 #76361] INFO -- : [Correios::CEP] Request:
86
- POST http://200.252.60.209/SigepCliente/AtendeClienteService
87
- <?xml version="1.0" encoding="UTF-8"?>
88
- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/">
89
- <soapenv:Header />
90
- <soapenv:Body>
91
- <cli:consultaCEP>
92
- <cep>54250610</cep>
93
- </cli:consultaCEP>
94
- </soapenv:Body>
95
- </soapenv:Envelope>
96
-
97
- I, [2014-02-14T00:10:12.969937 #76361] INFO -- : [Correios::CEP] Response:
98
- HTTP/1.1 200 OK
99
- <?xml version='1.0' encoding='UTF-8'?>
100
- <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
101
- <S:Body>
102
- <ns2:consultaCEPResponse xmlns:ns2="http://cliente.bean.master.sigep.bsb.correios.com.br/">
103
- <return>
104
- <bairro>Cavaleiro</bairro>
105
- <cep>54250610</cep>
106
- <cidade>Jaboatão dos Guararapes</cidade>
107
- <complemento></complemento>
108
- <complemento2></complemento2>
109
- <end>Rua Fernando Amorim</end>
110
- <id>0</id>
111
- <uf>PE</uf>
112
- </return>
113
- </ns2:consultaCEPResponse>
114
- </S:Body>
115
- </S:Envelope>
116
- ```
117
-
118
- To disable the log and configure other log output, use **Correios::CEP** module:
81
+ From `0.7.0` version, there is no more default logger, and the log level will be the same of the given logger.
119
82
 
120
83
  ```ruby
121
84
  Correios::CEP.configure do |config|
122
- config.log_enabled = false # It disables the log
123
- config.logger = Rails.logger # It uses Rails logger
85
+ config.logger = Rails.logger
124
86
  end
125
87
  ```
126
88
 
@@ -133,32 +95,26 @@ Correios::CEP.configure do |config|
133
95
  end
134
96
  ```
135
97
 
136
- ## Changelog
137
-
138
- [See the changes in each version.](CHANGELOG.md)
139
-
140
-
141
98
  ## Credits
142
99
 
143
100
  ### Author
144
- - [Fernando Hamasaki de Amorim (prodis)](http://prodis.blog.br)
101
+ [Fernando Hamasaki de Amorim (prodis)](https://github.com/prodis)
145
102
 
146
- ![Prodis Logo](http://prodis.net.br/images/prodis_150.gif)
103
+ ![Prodis Logo](https://camo.githubusercontent.com/c01a3ebca1c000d7586a998bb07316c8cb784ce5/687474703a2f2f70726f6469732e6e65742e62722f696d616765732f70726f6469735f3135302e676966)
147
104
 
148
105
  ### Contributors
149
106
  - [Gabriel Givigier Guimarães (givigier)](https://github.com/givigier)
150
107
  - [Marlon Henry Schweigert (Schweigert)](https://github.com/Schweigert)
108
+ - [Mateus Luiz (mateusluizfb)](https://github.com/mateusluizfb)
151
109
  - [Maury M. Marques (maurymmarques)](https://github.com/maurymmarques)
152
110
  - [Rafael Garcia (rafbgarcia)](https://github.com/rafbgarcia)
153
111
 
154
112
 
155
- ## Contributing to correios-cep
113
+ ## Contributing
114
+
115
+ See the [contributing guide](https://github.com/prodis/correios-cep/blob/master/CONTRIBUTING.md).
116
+
117
+
118
+ ## License
156
119
 
157
- - Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
158
- - Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
159
- - Fork the project.
160
- - Start a feature/bugfix branch.
161
- - Commit and push until you are happy with your contribution.
162
- - Don't forget to rebase with branch master in main project before submit the pull request.
163
- - Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
164
- - Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
120
+ Correios CEP gem is released under the Apache 2.0 License. See the [LICENSE](https://github.com/prodis/correios-cep/blob/master/LICENSE) file.
@@ -6,7 +6,7 @@ require 'correios/cep/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'correios-cep'
8
8
  spec.version = Correios::CEP::VERSION
9
- spec.author = 'Prodis a.k.a. Fernando Hamasaki de Amorim'
9
+ spec.author = 'Fernando Hamasaki de Amorim'
10
10
  spec.email = 'prodis@gmail.com'
11
11
  spec.summary = 'Correios CEP gem finds updated Brazilian addresses by zipcode, directly from Correios database. No HTML parsers.'
12
12
  spec.description = spec.summary
@@ -14,15 +14,15 @@ Gem::Specification.new do |spec|
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ # spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.platform = Gem::Platform::RUBY
22
- spec.required_ruby_version = Gem::Requirement.new('>= 2.0.0')
22
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.2.0')
23
23
 
24
- spec.add_dependency 'log-me', '~> 0.0.10'
25
24
  spec.add_dependency 'ox', '~> 2.9'
25
+ spec.add_dependency 'http', '~> 4.0.0'
26
26
 
27
27
  spec.add_development_dependency 'coveralls', '~> 0.8.21'
28
28
  spec.add_development_dependency 'pry', '~> 0.11.3'
@@ -1,9 +1,6 @@
1
1
  # frozen_string_literal: true
2
- require 'log-me'
3
-
4
2
  module Correios
5
3
  module CEP
6
- extend LogMe
7
4
  extend Correios::CEP::Config
8
5
  end
9
6
  end
@@ -5,18 +5,19 @@ module Correios
5
5
  WEB_SERVICE_URL = 'https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente'
6
6
  DEFAULT_REQUEST_TIMEOUT = 5 # seconds
7
7
 
8
- attr_writer :web_service_url, :proxy_url, :request_timeout
8
+ attr_accessor :logger, :proxy_url
9
+ attr_writer :request_timeout, :web_service_url
9
10
 
10
- def web_service_url
11
- @web_service_url ||= WEB_SERVICE_URL
11
+ def request_timeout
12
+ (@request_timeout ||= DEFAULT_REQUEST_TIMEOUT).to_i
12
13
  end
13
14
 
14
- def proxy_url
15
- @proxy_url ||= ''
15
+ def web_service_url
16
+ @web_service_url ||= WEB_SERVICE_URL
16
17
  end
17
18
 
18
- def request_timeout
19
- (@request_timeout ||= DEFAULT_REQUEST_TIMEOUT).to_i
19
+ def configure
20
+ yield self if block_given?
20
21
  end
21
22
  end
22
23
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Correios
3
3
  module CEP
4
- VERSION = '0.6.8'
4
+ VERSION = '0.7.0'
5
5
  end
6
6
  end
@@ -1,11 +1,10 @@
1
1
  # frozen_string_literal: true
2
- require 'net/https'
2
+ require 'http'
3
3
  require 'uri'
4
4
 
5
5
  module Correios
6
6
  module CEP
7
7
  class WebService
8
- CONTENT_TYPE_HEADER = 'text/xml; charset=utf-8'
9
8
  BODY_TEMPLATE = '<?xml version="1.0" encoding="UTF-8"?>' \
10
9
  '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"' \
11
10
  ' xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/">' \
@@ -16,50 +15,58 @@ module Correios
16
15
  '</cli:consultaCEP>' \
17
16
  '</soapenv:Body>' \
18
17
  '</soapenv:Envelope>'
18
+ HTTP_HEADERS = {
19
+ 'Content-Type' => 'text/xml; charset=utf-8',
20
+ 'User-Agent' => "correios-cep/#{Correios::CEP::VERSION}"
21
+ }.freeze
19
22
 
20
- def initialize
21
- @uri = URI.parse(Correios::CEP.web_service_url)
22
- @proxy_uri = URI.parse(Correios::CEP.proxy_url)
23
+ def request(zipcode)
24
+ response = http.post(Correios::CEP.web_service_url,
25
+ body: request_body(zipcode),
26
+ ssl_context: ssl_context)
27
+ response.body.to_s
23
28
  end
24
29
 
25
- def request(zipcode)
26
- http = build_http
30
+ private
27
31
 
28
- request = build_request(zipcode)
29
- Correios::CEP.log_request(request, uri.to_s)
32
+ def http
33
+ http = HTTP.headers(HTTP_HEADERS)
34
+ .timeout(
35
+ connect: Correios::CEP.request_timeout,
36
+ read: Correios::CEP.request_timeout
37
+ )
38
+ http = http_proxy(http)
39
+ http = http_log(http)
30
40
 
31
- response = http.request(request)
32
- Correios::CEP.log_response(response)
41
+ http
42
+ end
33
43
 
34
- http.finish if http.started?
44
+ def http_proxy(http)
45
+ return http if proxy_uri.nil?
35
46
 
36
- response.body
47
+ http.via(proxy_uri.host, proxy_uri.port)
37
48
  end
38
49
 
39
- private
50
+ def http_log(http)
51
+ return http if Correios::CEP.logger.nil?
40
52
 
41
- attr_reader :uri, :proxy_uri
53
+ http.use(logging: { logger: Correios::CEP.logger })
54
+ end
55
+
56
+ def request_body(zipcode)
57
+ BODY_TEMPLATE % { zipcode: zipcode }
58
+ end
42
59
 
43
- def build_http
44
- Net::HTTP.start(
45
- uri.host,
46
- uri.port,
47
- proxy_uri.host,
48
- proxy_uri.port,
49
- nil,
50
- nil,
51
- use_ssl: true,
52
- verify_mode: OpenSSL::SSL::VERIFY_NONE,
53
- open_timeout: Correios::CEP.request_timeout,
54
- read_timeout: Correios::CEP.request_timeout
55
- )
60
+ def ssl_context
61
+ context = OpenSSL::SSL::SSLContext.new
62
+ context.verify_mode = OpenSSL::SSL::VERIFY_NONE
63
+ context
56
64
  end
57
65
 
58
- def build_request(zipcode)
59
- request = Net::HTTP::Post.new(uri.path)
60
- request['Content-Type'] = CONTENT_TYPE_HEADER
61
- request.body = BODY_TEMPLATE % { zipcode: zipcode }
62
- request
66
+ def proxy_uri
67
+ return nil if Correios::CEP.proxy_url.nil?
68
+
69
+ @proxy_uri ||= URI.parse(Correios::CEP.proxy_url)
63
70
  end
64
71
  end
65
72
  end
@@ -3,12 +3,6 @@ describe Correios::CEP::WebService do
3
3
  let(:cep) { '54250610' }
4
4
 
5
5
  describe '#request', vcr: { cassette_name: 'correios_consulta_cep_ok' } do
6
- around do |example|
7
- Correios::CEP.log_enabled = false
8
- example.run
9
- Correios::CEP.log_enabled = true
10
- end
11
-
12
6
  it 'returns HTTP response body from Correios web service' do
13
7
  result = subject.request(cep)
14
8
  expect(result).to include('Rua Fernando Amorim')
@@ -20,26 +20,6 @@ describe Correios::CEP do
20
20
  end
21
21
  end
22
22
 
23
- describe '#proxy_url' do
24
- it 'default is empty' do
25
- expect(Correios::CEP.proxy_url).to eq ''
26
- end
27
-
28
- context 'when set proxy URL' do
29
- let(:url) { 'http://10.20.30.40:8888' }
30
-
31
- around do |example|
32
- Correios::CEP.proxy_url = url
33
- example.run
34
- Correios::CEP.proxy_url = ''
35
- end
36
-
37
- it 'returns the given proxy URL' do
38
- expect(Correios::CEP.proxy_url).to eq url
39
- end
40
- end
41
- end
42
-
43
23
  describe "#request_timeout" do
44
24
  it "default is 5" do
45
25
  expect(Correios::CEP.request_timeout).to eq 5
@@ -58,4 +38,3 @@ describe Correios::CEP do
58
38
  end
59
39
  end
60
40
  end
61
-
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: correios-cep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.8
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
- - Prodis a.k.a. Fernando Hamasaki de Amorim
7
+ - Fernando Hamasaki de Amorim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-01 00:00:00.000000000 Z
11
+ date: 2018-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: log-me
14
+ name: ox
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.10
19
+ version: '2.9'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.10
26
+ version: '2.9'
27
27
  - !ruby/object:Gem::Dependency
28
- name: ox
28
+ name: http
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.9'
33
+ version: 4.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.9'
40
+ version: 4.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: coveralls
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -125,8 +125,7 @@ dependencies:
125
125
  description: Correios CEP gem finds updated Brazilian addresses by zipcode, directly
126
126
  from Correios database. No HTML parsers.
127
127
  email: prodis@gmail.com
128
- executables:
129
- - console
128
+ executables: []
130
129
  extensions: []
131
130
  extra_rdoc_files: []
132
131
  files:
@@ -134,6 +133,7 @@ files:
134
133
  - ".rspec"
135
134
  - ".travis.yml"
136
135
  - CHANGELOG.md
136
+ - CONTRIBUTING.md
137
137
  - Gemfile
138
138
  - LICENSE
139
139
  - README.md
@@ -165,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
165
  requirements:
166
166
  - - ">="
167
167
  - !ruby/object:Gem::Version
168
- version: 2.0.0
168
+ version: 2.2.0
169
169
  required_rubygems_version: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - ">="