sepomex_client 0.1.0 → 0.1.1

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: f9db38b97ba3c20e91c0e474c37dfd9c28a1c17fb2c0050e088a1110f16544b9
4
- data.tar.gz: 7c40f0691e08848b319828cd6cd1cde57c7c4c493aacbc1f71fb7260754c1486
3
+ metadata.gz: 5c26ab8e8d11f89a49dcfd544ee139a6b42b004551a1b80df3ce3d29b3878316
4
+ data.tar.gz: b1537a4d86406414eea80e91354f5c707b211ca8b196c84f5719161655fbb7ea
5
5
  SHA512:
6
- metadata.gz: d222836fce1efcbce435f1e2274f8ce60a786cafc17d057bd88fe5a862ea155e5b8e8a0bbf9aa32e94dfdd0bfd0682c9fab92e26ba4ab4a0aaaf903a7418064e
7
- data.tar.gz: 655821d688f072fa86cd412e54063eefa499cd13544ee78f9405d25f40bf3897cedbfafeb67994c0466f2a93839da750c0e7c1738c19cb36f6f8a53998f1fb2f
6
+ metadata.gz: c7f3bda39e1290880d6286830bc86911211850fcab702f8fa0ce7f06343ea88f1d8687808427a7cfdbf69e51b4d756acae906cda62beea288e6dd3b12b2ef4e5
7
+ data.tar.gz: d59b646ec9c461b6b0cbe1f8387c2443591b0f1bdd5a2aed6f175408c0c1c07f0820090c0bcefda03a503c1398f03fd19fff9df6679077ba27579e772bc9cc5b
data/.gitignore ADDED
@@ -0,0 +1,51 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
4
+ # Declare your gem's dependencies in commons.gemspec.
5
+ # Bundler will treat runtime dependencies like base dependencies, and
6
+ # development dependencies will be added by default to the :development group.
7
+ gemspec
8
+
9
+ # Declare any dependencies that are still in development here instead of in
10
+ # your gemspec. These might include edge Rails or gems from your path or
11
+ # Git. Remember to move these dependencies to your gemspec before releasing
12
+ # your gem to rubygems.org.
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sepomex_client (0.1.0)
5
+ sepomex_acrogenesis (~> 0.5.2)
6
+ sepomex_hckdrk (~> 0.4.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.2.4.1)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ addressable (2.7.0)
17
+ public_suffix (>= 2.0.2, < 5.0)
18
+ concurrent-ruby (1.1.5)
19
+ crack (0.4.3)
20
+ safe_yaml (~> 1.0.0)
21
+ diff-lcs (1.3)
22
+ docile (1.3.2)
23
+ hashdiff (1.0.0)
24
+ httparty (0.16.4)
25
+ mime-types (~> 3.0)
26
+ multi_xml (>= 0.5.2)
27
+ i18n (1.7.0)
28
+ concurrent-ruby (~> 1.0)
29
+ json (2.3.0)
30
+ mime-types (3.3.1)
31
+ mime-types-data (~> 3.2015)
32
+ mime-types-data (3.2019.1009)
33
+ minitest (5.13.0)
34
+ multi_xml (0.6.0)
35
+ public_suffix (4.0.3)
36
+ rspec (3.9.0)
37
+ rspec-core (~> 3.9.0)
38
+ rspec-expectations (~> 3.9.0)
39
+ rspec-mocks (~> 3.9.0)
40
+ rspec-core (3.9.1)
41
+ rspec-support (~> 3.9.1)
42
+ rspec-expectations (3.9.0)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.9.0)
45
+ rspec-mocks (3.9.1)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.9.0)
48
+ rspec-support (3.9.2)
49
+ safe_yaml (1.0.5)
50
+ sepomex_acrogenesis (0.5.2)
51
+ activesupport (~> 5.2)
52
+ httparty (~> 0.16.0)
53
+ json (~> 2.0)
54
+ sepomex_hckdrk (0.4.1)
55
+ activesupport (~> 5.2)
56
+ httparty (~> 0.16.0)
57
+ json (~> 2.0)
58
+ simplecov (0.17.1)
59
+ docile (~> 1.1)
60
+ json (>= 1.8, < 3)
61
+ simplecov-html (~> 0.10.0)
62
+ simplecov-html (0.10.2)
63
+ thread_safe (0.3.6)
64
+ tzinfo (1.2.6)
65
+ thread_safe (~> 0.1)
66
+ webmock (3.7.6)
67
+ addressable (>= 2.3.6)
68
+ crack (>= 0.3.2)
69
+ hashdiff (>= 0.4.0, < 2.0.0)
70
+
71
+ PLATFORMS
72
+ ruby
73
+
74
+ DEPENDENCIES
75
+ rspec (~> 3.8)
76
+ sepomex_client!
77
+ simplecov (~> 0.17)
78
+ webmock (~> 3.7)
79
+
80
+ BUNDLED WITH
81
+ 2.0.2
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2019 Juan Ku
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # sepomex-ruby
2
+ SEPOMEX is a ruby integration to SEPOMEX clients for zip code information gathering
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ # Default directory to look in is `/spec`
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,18 @@
1
+ module SEPOMEX
2
+ module Clients
3
+ class Acrogenesis
4
+ def initialize(zip_code)
5
+ @zip_code = zip_code
6
+ end
7
+
8
+ #
9
+ # Método que se encarga de solicitar información de un código postal
10
+ #
11
+ # @raise [SepomexError]
12
+ #
13
+ def query
14
+ SEPOMEX_Acrogenesis::General.info_zip_code(zip_code: @zip_code)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module SEPOMEX
2
+ module Clients
3
+ class Hckdrk
4
+ def initialize(zip_code)
5
+ @zip_code = zip_code
6
+ end
7
+
8
+ #
9
+ # Método que se encarga de solicitar información de un código postal
10
+ #
11
+ # @raise [SepomexError]
12
+ #
13
+ def query
14
+ SEPOMEX_HCKDRK::General.info_zip_code(zip_code: @zip_code)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ module SEPOMEX
2
+ class DataNotFoundError < StandardError
3
+ end
4
+ end
@@ -0,0 +1,43 @@
1
+ module SEPOMEX
2
+ class Strategy
3
+ ACROGENESIS = 'acrogenesis'.freeze
4
+ HCKDRK = 'hckdrk'.freeze
5
+
6
+ def self.call(*args, &block)
7
+ new(*args, &block).call
8
+ end
9
+
10
+ def initialize(zip_code)
11
+ @zip_code = zip_code
12
+ @clients = [HCKDRK, ACROGENESIS]
13
+ end
14
+
15
+ def call
16
+ raise ArgumentError if @zip_code.blank?
17
+
18
+ zip_code_result = {}
19
+ @clients.each do |client|
20
+ strategy = processor(client)
21
+ zip_code_result = strategy.query
22
+ break if zip_code_result.settlement.present?
23
+ rescue StandardError => e
24
+ end
25
+ raise DataNotFoundError if zip_code_result.blank? || zip_code_result.settlement.blank?
26
+
27
+ zip_code_result
28
+ end
29
+
30
+ private
31
+
32
+ def processor(client)
33
+ case client
34
+ when HCKDRK
35
+ SEPOMEX::Clients::Hckdrk.new(@zip_code)
36
+ when ACROGENESIS
37
+ SEPOMEX::Clients::Acrogenesis.new(@zip_code)
38
+ else
39
+ raise ArgumentError
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module SEPOMEX
2
+ VERSION = '0.1.1'
3
+ end
data/sepomex.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ $:.push File.expand_path("lib", __dir__)
2
+
3
+ # Maintain your gem's version:
4
+ require "sepomex/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "sepomex_client"
9
+ spec.version = SEPOMEX::VERSION
10
+ spec.date = '2019-12-10'
11
+ spec.description = "SEPOMEX is a ruby integration to SEPOMEX clients for zip code information gathering"
12
+ spec.summary = "SEPOMEX is a library that integrates to multiple SEPOMEX clients for MX zip code information gathering"
13
+ spec.files = `git ls-files`.split($/)
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ spec.authors = ["Yellowme"]
17
+ spec.email = 'hola@yellowme.mx'
18
+ spec.homepage = 'https://github.com/yellowme/sepomex-ruby'
19
+ spec.license = 'MIT'
20
+
21
+ spec.add_dependency "sepomex_acrogenesis", "~> 0.5.2"
22
+ spec.add_dependency 'sepomex_hckdrk', "~> 0.4.1"
23
+
24
+ spec.add_development_dependency "rspec", "~> 3.8"
25
+ spec.add_development_dependency "webmock", "~> 3.7"
26
+ spec.add_development_dependency "simplecov", "~> 0.17"
27
+ end
@@ -0,0 +1,129 @@
1
+ require 'webmock/rspec'
2
+
3
+ RSpec.describe SEPOMEX::Strategy do
4
+ zip_code = '97305'
5
+
6
+ let(:sepomex_zip_code_response) do
7
+ [
8
+ {
9
+ error: false,
10
+ code_error: 0,
11
+ error_message: 'null',
12
+ response: {
13
+ cp: zip_code,
14
+ asentamiento: 'Granjas Cholul',
15
+ tipo_asentamiento: 'Colonia',
16
+ municipio: 'Mérida',
17
+ estado: 'Yucatán',
18
+ ciudad: '',
19
+ pais: 'México',
20
+ },
21
+ },
22
+ {
23
+ error: false,
24
+ code_error: 0,
25
+ error_message: 'null',
26
+ response: {
27
+ cp: zip_code,
28
+ asentamiento: 'Cabo Norte',
29
+ tipo_asentamiento: 'Fraccionamiento',
30
+ municipio: 'Mérida',
31
+ estado: 'Yucatán',
32
+ ciudad: '',
33
+ pais: 'México',
34
+ },
35
+ },
36
+ ]
37
+ end
38
+
39
+ let(:sepomex_invalid_zip_code_response) do
40
+ {
41
+ error: true,
42
+ code_error: 102,
43
+ error_message: 'La longitud del cp es inválida',
44
+ response: 'null',
45
+ }
46
+ end
47
+
48
+ let(:sepomex_acrogenesis_valid_zip_code_response) do
49
+ {
50
+ codigo_postal: '97305',
51
+ municipio: 'Mérida',
52
+ estado: 'Yucatán',
53
+ colonias: ['Cholul'],
54
+ }
55
+ end
56
+
57
+ let(:sepomex_acrogenesis_invalid_zip_code_response) do
58
+ {
59
+ codigo_postal: '94',
60
+ municipio: '',
61
+ estado: '',
62
+ colonias: [],
63
+ }
64
+ end
65
+
66
+ describe 'it works' do
67
+ context 'when hckdrk works' do
68
+ before do
69
+ stub_request(:get, "https://api-sepomex.hckdrk.mx/query/info_cp/#{zip_code}").to_return(
70
+ body: JSON.dump(sepomex_zip_code_response), status: 200
71
+ )
72
+ end
73
+
74
+ subject { described_class.call(zip_code) }
75
+
76
+ it do
77
+ expect { subject }.not_to raise_error
78
+ expect(subject.state).to eq 'Yucatán'
79
+ end
80
+ end
81
+
82
+ context 'when hckdrk fails but acrogenesis works' do
83
+ before do
84
+ stub_request(:get, "https://api-sepomex.hckdrk.mx/query/info_cp/#{zip_code}").to_return(
85
+ body: JSON.dump(sepomex_invalid_zip_code_response), status: 200
86
+ )
87
+
88
+ stub_request(:get, "https://api-codigos-postales.herokuapp.com/v2/codigo_postal/#{zip_code}").to_return(
89
+ body: JSON.dump(sepomex_acrogenesis_valid_zip_code_response), status: 200
90
+ )
91
+ end
92
+
93
+ subject { described_class.call(zip_code) }
94
+
95
+ it do
96
+ expect { subject }.not_to raise_error
97
+ expect(subject.state).to eq 'Yucatán'
98
+ end
99
+ end
100
+ end
101
+
102
+ describe 'fails correctly' do
103
+ context 'when both APIs fail' do
104
+ before do
105
+ stub_request(:get, "https://api-sepomex.hckdrk.mx/query/info_cp/#{zip_code}").to_return(
106
+ body: JSON.dump(sepomex_invalid_zip_code_response), status: 200
107
+ )
108
+
109
+ stub_request(:get, "https://api-codigos-postales.herokuapp.com/v2/codigo_postal/#{zip_code}").to_return(
110
+ body: JSON.dump(sepomex_acrogenesis_invalid_zip_code_response), status: 200
111
+ )
112
+ end
113
+
114
+ it do
115
+ expect do
116
+ described_class.call(zip_code)
117
+ end.to raise_error SEPOMEX::DataNotFoundError
118
+ end
119
+ end
120
+
121
+ context 'when no zip_code sent' do
122
+ it do
123
+ expect do
124
+ described_class.call
125
+ end.to raise_error ArgumentError
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+ require 'simplecov'
3
+
4
+ require 'sepomex'
5
+
6
+ SimpleCov.start
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sepomex_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yellowme
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.2'
19
+ version: 0.5.2
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.2'
26
+ version: 0.5.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sepomex_hckdrk
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.1'
33
+ version: 0.4.1
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: '0.1'
40
+ version: 0.4.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -87,7 +87,22 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - MIT-LICENSE
95
+ - README.md
96
+ - Rakefile
90
97
  - lib/sepomex.rb
98
+ - lib/sepomex/clients/acrogenesis.rb
99
+ - lib/sepomex/clients/hckdrk.rb
100
+ - lib/sepomex/data_not_found_error.rb
101
+ - lib/sepomex/strategy.rb
102
+ - lib/sepomex/version.rb
103
+ - sepomex.gemspec
104
+ - spec/sepomex/strategy_spec.rb
105
+ - spec/spec_helper.rb
91
106
  homepage: https://github.com/yellowme/sepomex-ruby
92
107
  licenses:
93
108
  - MIT
@@ -113,4 +128,6 @@ signing_key:
113
128
  specification_version: 4
114
129
  summary: SEPOMEX is a library that integrates to multiple SEPOMEX clients for MX zip
115
130
  code information gathering
116
- test_files: []
131
+ test_files:
132
+ - spec/sepomex/strategy_spec.rb
133
+ - spec/spec_helper.rb