sepomex_acrogenesis 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.gitignore +50 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +74 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/Rakefile +7 -0
- data/lib/sepomex_acrogenesis/client/api_client.rb +19 -0
- data/lib/sepomex_acrogenesis/client/json_api.rb +48 -0
- data/lib/sepomex_acrogenesis/error.rb +12 -0
- data/lib/sepomex_acrogenesis/general.rb +19 -0
- data/lib/sepomex_acrogenesis/structs/zip_code.rb +12 -0
- data/lib/sepomex_acrogenesis/version.rb +3 -0
- data/sepomex_acrogenesis.gemspec +29 -0
- data/spec/sepomex_acrogenesis/general_spec.rb +73 -0
- data/spec/spec_helper.rb +7 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee9b2420cad640013394cc799067df13faca55292dd2868a8fa6721e112ddc48
|
4
|
+
data.tar.gz: 740b5c9d8b7809991a516324a3ebf3b328f5d9ed24d5ef41926d32abb9874757
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47cdfc15b973e3f011867175041cfc009013b59c8cdc99c256ab5475558c622c1f0d7577ce316c71954bb357040b9d4bd8584c8d785fd15489deca18110465cb
|
7
|
+
data.tar.gz: 1ee19c7a7dd7d9b641bcefb402677d24be42dd6054ca933514172a2ee8ce188769c08480c9581516e5ffd3dd485a17e0ea772600f5595ffb89861b9a8d9768b2
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
@@ -0,0 +1,50 @@
|
|
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
|
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,74 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sepomex_acrogenesis (0.4.0)
|
5
|
+
activesupport (~> 5.2)
|
6
|
+
httparty (~> 0.16.0)
|
7
|
+
json (~> 2.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (5.2.4.1)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (>= 0.7, < 2)
|
15
|
+
minitest (~> 5.1)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
addressable (2.7.0)
|
18
|
+
public_suffix (>= 2.0.2, < 5.0)
|
19
|
+
concurrent-ruby (1.1.5)
|
20
|
+
crack (0.4.3)
|
21
|
+
safe_yaml (~> 1.0.0)
|
22
|
+
diff-lcs (1.3)
|
23
|
+
docile (1.3.2)
|
24
|
+
hashdiff (1.0.0)
|
25
|
+
httparty (0.16.4)
|
26
|
+
mime-types (~> 3.0)
|
27
|
+
multi_xml (>= 0.5.2)
|
28
|
+
i18n (1.7.0)
|
29
|
+
concurrent-ruby (~> 1.0)
|
30
|
+
json (2.2.0)
|
31
|
+
mime-types (3.3.1)
|
32
|
+
mime-types-data (~> 3.2015)
|
33
|
+
mime-types-data (3.2019.1009)
|
34
|
+
minitest (5.13.0)
|
35
|
+
multi_xml (0.6.0)
|
36
|
+
public_suffix (4.0.1)
|
37
|
+
rspec (3.8.0)
|
38
|
+
rspec-core (~> 3.8.0)
|
39
|
+
rspec-expectations (~> 3.8.0)
|
40
|
+
rspec-mocks (~> 3.8.0)
|
41
|
+
rspec-core (3.8.2)
|
42
|
+
rspec-support (~> 3.8.0)
|
43
|
+
rspec-expectations (3.8.4)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.8.0)
|
46
|
+
rspec-mocks (3.8.1)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.8.0)
|
49
|
+
rspec-support (3.8.2)
|
50
|
+
safe_yaml (1.0.5)
|
51
|
+
simplecov (0.17.0)
|
52
|
+
docile (~> 1.1)
|
53
|
+
json (>= 1.8, < 3)
|
54
|
+
simplecov-html (~> 0.10.0)
|
55
|
+
simplecov-html (0.10.2)
|
56
|
+
thread_safe (0.3.6)
|
57
|
+
tzinfo (1.2.6)
|
58
|
+
thread_safe (~> 0.1)
|
59
|
+
webmock (3.7.2)
|
60
|
+
addressable (>= 2.3.6)
|
61
|
+
crack (>= 0.3.2)
|
62
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
63
|
+
|
64
|
+
PLATFORMS
|
65
|
+
ruby
|
66
|
+
|
67
|
+
DEPENDENCIES
|
68
|
+
rspec (~> 3.8)
|
69
|
+
sepomex_acrogenesis!
|
70
|
+
simplecov (~> 0.17)
|
71
|
+
webmock (~> 3.7)
|
72
|
+
|
73
|
+
BUNDLED WITH
|
74
|
+
1.17.3
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 Yellowme
|
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/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module SEPOMEX_Acrogenesis
|
4
|
+
class ApiClient
|
5
|
+
include SEPOMEX_Acrogenesis::JsonApi
|
6
|
+
|
7
|
+
def self.config
|
8
|
+
yield self
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.api_base
|
12
|
+
@api_base
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.api_base=(api_base)
|
16
|
+
@api_base = api_base
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module SEPOMEX_Acrogenesis
|
4
|
+
module JsonApi
|
5
|
+
module ClassMethods
|
6
|
+
def default_headers
|
7
|
+
{
|
8
|
+
'Content-type' => 'application/json'
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def api_get(url:, headers: {})
|
13
|
+
custom_headers = headers.merge(default_headers)
|
14
|
+
response = HTTParty.get(SEPOMEX_Acrogenesis.api_base + url, headers: custom_headers)
|
15
|
+
|
16
|
+
JSON.parse(response.body, symbolize_names: true)
|
17
|
+
end
|
18
|
+
|
19
|
+
def api_post(url:, body: {}, headers: {})
|
20
|
+
custom_headers = headers.merge(default_headers)
|
21
|
+
|
22
|
+
response =
|
23
|
+
HTTParty.post(
|
24
|
+
SEPOMEX_Acrogenesis.api_base + url,
|
25
|
+
body: body.to_json, headers: custom_headers
|
26
|
+
)
|
27
|
+
|
28
|
+
JSON.parse(response.body, symbolize_names: true)
|
29
|
+
end
|
30
|
+
|
31
|
+
def api_post_multipart(url:, body: {}, headers: {})
|
32
|
+
custom_headers = headers.merge(default_headers)
|
33
|
+
|
34
|
+
response =
|
35
|
+
HTTParty.post(
|
36
|
+
SEPOMEX_Acrogenesis.api_base + url,
|
37
|
+
multipart: true, body: body, headers: custom_headers
|
38
|
+
)
|
39
|
+
|
40
|
+
response.body
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.included(base)
|
45
|
+
base.extend(ClassMethods)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
|
4
|
+
module SEPOMEX_Acrogenesis
|
5
|
+
class General < ApiClient
|
6
|
+
def self.info_zip_code(zip_code:)
|
7
|
+
url = "v2/codigo_postal/#{zip_code}"
|
8
|
+
response = api_get(url: url)
|
9
|
+
raise SEPOMEX_Acrogenesis::RequestError.new if response[:municipio].blank?
|
10
|
+
data = {
|
11
|
+
zip_code: response[:codigo_postal].present? ? response[:codigo_postal] : nil,
|
12
|
+
settlement: response[:colonias][0].present? ? response[:colonias][0] : nil,
|
13
|
+
municipality: response[:municipio].present? ? response[:municipio] : nil,
|
14
|
+
state: response[:estado].present? ? response[:estado] : nil
|
15
|
+
}
|
16
|
+
SEPOMEX_Acrogenesis::ZipCode.new(*data.values_at(*SEPOMEX_Acrogenesis::ZipCode.members))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
$:.push File.expand_path("lib", __dir__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require "sepomex_acrogenesis/version"
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "sepomex_acrogenesis"
|
9
|
+
spec.version = SEPOMEX_Acrogenesis::VERSION
|
10
|
+
spec.date = '2019-10-10'
|
11
|
+
spec.description = "Ruby Bindings for SEPOMEX Acrogenesis API"
|
12
|
+
spec.summary = "Ruby that provides a library to SEPOMEX Acrogenesis API"
|
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://rubygems.org/gems/sepomex-acrogenesis-ruby'
|
19
|
+
spec.license = 'MIT'
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency 'httparty', "~> 0.16.0"
|
23
|
+
spec.add_dependency "json", "~> 2.0"
|
24
|
+
spec.add_dependency 'activesupport', "~> 5.2"
|
25
|
+
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.8"
|
27
|
+
spec.add_development_dependency "webmock", "~> 3.7"
|
28
|
+
spec.add_development_dependency "simplecov", "~> 0.17"
|
29
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SEPOMEX_Acrogenesis::General do
|
4
|
+
describe '.info_cp' do
|
5
|
+
it 'successfully creates a customer' do
|
6
|
+
stub_request(:get, 'https://api-codigos-postales.herokuapp.com/v2/codigo_postal/97305').to_return(
|
7
|
+
body:
|
8
|
+
JSON.dump(
|
9
|
+
codigo_postal: "97305",
|
10
|
+
municipio: "Mérida",
|
11
|
+
estado: "Yucatán",
|
12
|
+
colonias: [
|
13
|
+
"Granjas Cholul",
|
14
|
+
"Jalapa",
|
15
|
+
"Parque Central",
|
16
|
+
"Cholul",
|
17
|
+
"Gran San Pedro Cholul",
|
18
|
+
"Villas Cholul",
|
19
|
+
"Alura",
|
20
|
+
"Tixcuytún",
|
21
|
+
"Santa Gertrudis Copo",
|
22
|
+
"Algarrobos Desarrollo Residencial",
|
23
|
+
"Residencial Campestre Viladiu",
|
24
|
+
"San Luis Cholul",
|
25
|
+
"Sian Kaan",
|
26
|
+
"Residencial Anturio",
|
27
|
+
"Cocoyoles",
|
28
|
+
"Dzibilchaltún",
|
29
|
+
"Bogdan",
|
30
|
+
"Altavista",
|
31
|
+
"Paraíso las Margaritas",
|
32
|
+
"Las Margaritas de Cholul",
|
33
|
+
"Villas de Bosque Cholul",
|
34
|
+
"San Gabriel Tulipanes",
|
35
|
+
"Cabo Norte",
|
36
|
+
"Villas del Bosque Cholul"
|
37
|
+
]
|
38
|
+
),
|
39
|
+
status: 200
|
40
|
+
)
|
41
|
+
|
42
|
+
zip_code = SEPOMEX_Acrogenesis::General.info_zip_code(zip_code: '97305')
|
43
|
+
|
44
|
+
expect(zip_code).to be_a(SEPOMEX_Acrogenesis::ZipCode)
|
45
|
+
expect(zip_code.zip_code).to eq('97305')
|
46
|
+
expect(zip_code.settlement).to eq('Granjas Cholul')
|
47
|
+
expect(zip_code.municipality).to eq('Mérida')
|
48
|
+
expect(zip_code.state).to eq('Yucatán')
|
49
|
+
expect(zip_code.city).to be_nil
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'raises error whith invalid cp' do
|
53
|
+
stub_request(:get, 'https://api-codigos-postales.herokuapp.com/v2/codigo_postal/97305').to_return(
|
54
|
+
body:
|
55
|
+
JSON.dump(
|
56
|
+
{
|
57
|
+
codigo_postal: "9",
|
58
|
+
municipio: "",
|
59
|
+
estado: "",
|
60
|
+
colonias: [ ]
|
61
|
+
}
|
62
|
+
),
|
63
|
+
status: 200
|
64
|
+
)
|
65
|
+
|
66
|
+
begin
|
67
|
+
zip_code = SEPOMEX_Acrogenesis::General.info_zip_code(zip_code: '97305')
|
68
|
+
rescue => exception
|
69
|
+
expect(exception).to be_a(SEPOMEX_Acrogenesis::RequestError)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sepomex_acrogenesis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yellowme
|
@@ -100,7 +100,23 @@ executables: []
|
|
100
100
|
extensions: []
|
101
101
|
extra_rdoc_files: []
|
102
102
|
files:
|
103
|
+
- ".DS_Store"
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- Gemfile.lock
|
107
|
+
- LICENSE
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
103
110
|
- lib/sepomex_acrogenesis.rb
|
111
|
+
- lib/sepomex_acrogenesis/client/api_client.rb
|
112
|
+
- lib/sepomex_acrogenesis/client/json_api.rb
|
113
|
+
- lib/sepomex_acrogenesis/error.rb
|
114
|
+
- lib/sepomex_acrogenesis/general.rb
|
115
|
+
- lib/sepomex_acrogenesis/structs/zip_code.rb
|
116
|
+
- lib/sepomex_acrogenesis/version.rb
|
117
|
+
- sepomex_acrogenesis.gemspec
|
118
|
+
- spec/sepomex_acrogenesis/general_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
104
120
|
homepage: https://rubygems.org/gems/sepomex-acrogenesis-ruby
|
105
121
|
licenses:
|
106
122
|
- MIT
|
@@ -125,4 +141,6 @@ rubygems_version: 2.7.6
|
|
125
141
|
signing_key:
|
126
142
|
specification_version: 4
|
127
143
|
summary: Ruby that provides a library to SEPOMEX Acrogenesis API
|
128
|
-
test_files:
|
144
|
+
test_files:
|
145
|
+
- spec/sepomex_acrogenesis/general_spec.rb
|
146
|
+
- spec/spec_helper.rb
|