sepomex_hckdrk 0.4.0 → 0.4.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: 0bd07fb01e8c6fa056f484f8938f2fd6c9f2b3a6437863ed935b09d89f9900fa
4
- data.tar.gz: c0a1f81d6a931a1a81cb3bec6de8ee62a25e5f70a66d2eaa634f3b67da8961f9
3
+ metadata.gz: 8612099c295c9bdf943474b688aca3519afff6c536c6b88c9a1cead63360fdce
4
+ data.tar.gz: bee904524bbe0d8f4a78cccf468224b90a02d75912c34521a99f1853f1b0618e
5
5
  SHA512:
6
- metadata.gz: 6066c9acd5ca57dea24c5dc1332205334ac3284e6069e81874097822cbc332b9297b449fdc452ab5e8ea5869f6b6e03586c88768686804a56d5e7baa02d62786
7
- data.tar.gz: 232bee3b0d09e037838399b837a2a03f8705281d80cfce7e1ef058ecb2696363b0e5bd9413a2a94ebc9b70f272f63cbbdecaa18fc7d71f8b56db6a1ed1580d3a
6
+ metadata.gz: 7def5510d944b07e8c87e690bf58a2ac23d71b1318e4d2f34623b21f46a774e7ebc544317eaf3ed6dfbfac145afe5b742cfc7783e806c338d8b9eaf0199d1b3e
7
+ data.tar.gz: 5a09cfe3faed1b8bda61bf52f5e976d8b4f68b894fd9795e421b6ea08e5f6c1f97d2e5eafa90c80060e81a6b595f6c32062e82e90bf96869a58d0f5f3e618856
data/.gitignore ADDED
@@ -0,0 +1,53 @@
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
+
52
+ # Mac
53
+ .DS_Store
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_hckdrk (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_hckdrk!
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
@@ -0,0 +1,2 @@
1
+ # sepomex-hckdrk-ruby
2
+ Ruby Bindings for SEPOMEX HCKDRK API
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,19 @@
1
+ require 'singleton'
2
+
3
+ module SEPOMEX_HCKDRK
4
+ class ApiClient
5
+ include SEPOMEX_HCKDRK::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_HCKDRK
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_HCKDRK.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_HCKDRK.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_HCKDRK.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,12 @@
1
+ module SEPOMEX_HCKDRK
2
+ class Error < StandardError
3
+ attr_reader :response
4
+
5
+ def initialize(response = {})
6
+ @response = response
7
+ super
8
+ end
9
+ end
10
+
11
+ class RequestError < Error; end
12
+ end
@@ -0,0 +1,24 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+
4
+ module SEPOMEX_HCKDRK
5
+ class General < ApiClient
6
+ def self.info_zip_code(zip_code:)
7
+ url = "query/info_cp/#{zip_code}"
8
+ response = api_get(url: url)
9
+ raise SEPOMEX_HCKDRK::RequestError.new(response[:error_message]) if !response.kind_of?(Array) && response[:error] == true
10
+ payload = response[0]
11
+ raise SEPOMEX_HCKDRK::RequestError.new(payload[:error_message]) if payload[:error] == true
12
+ data = {
13
+ zip_code: payload[:response][:cp].present? ? payload[:response][:cp] : nil,
14
+ settlement: payload[:response][:asentamiento].present? ? payload[:response][:asentamiento] : nil,
15
+ settlement_type: payload[:response][:tipo_asentamiento].present? ? payload[:response][:tipo_asentamiento] : nil,
16
+ municipality: payload[:response][:municipio].present? ? payload[:response][:municipio] : nil,
17
+ state: payload[:response][:estado].present? ? payload[:response][:estado] : nil,
18
+ city: payload[:response][:ciudad].present? ? payload[:response][:ciudad] : nil,
19
+ country: payload[:response][:pais].present? ? payload[:response][:pais] : nil
20
+ }
21
+ SEPOMEX_HCKDRK::ZipCode.new(*data.values_at(*SEPOMEX_HCKDRK::ZipCode.members))
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ module SEPOMEX_HCKDRK
2
+ ZipCode =
3
+ Struct.new(
4
+ :zip_code,
5
+ :settlement,
6
+ :settlement_type,
7
+ :municipality,
8
+ :state,
9
+ :city,
10
+ :country
11
+ )
12
+ end
@@ -0,0 +1,3 @@
1
+ module SEPOMEX_HCKDRK
2
+ VERSION = '0.4.1'
3
+ end
@@ -0,0 +1,28 @@
1
+ $:.push File.expand_path("lib", __dir__)
2
+
3
+ # Maintain your gem's version:
4
+ require "sepomex_hckdrk/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "sepomex_hckdrk"
9
+ spec.version = SEPOMEX_HCKDRK::VERSION
10
+ spec.date = '2019-10-10'
11
+ spec.description = "Ruby Bindings for SEPOMEX HCKDRK API"
12
+ spec.summary = "Ruby that provides a library to SEPOMEX HCKDRK 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-hckdrk-ruby'
19
+ spec.license = 'MIT'
20
+
21
+ spec.add_dependency 'httparty', "~> 0.16.0"
22
+ spec.add_dependency "json", "~> 2.0"
23
+ spec.add_dependency 'activesupport', "~> 5.2"
24
+
25
+ spec.add_development_dependency "rspec", "~> 3.8"
26
+ spec.add_development_dependency "webmock", "~> 3.7"
27
+ spec.add_development_dependency "simplecov", "~> 0.17"
28
+ end
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe SEPOMEX_HCKDRK::General do
4
+ describe '.info_cp' do
5
+ it 'successfully creates a customer' do
6
+ stub_request(:get, 'https://api-sepomex.hckdrk.mx/query/info_cp/97305').to_return(
7
+ body:
8
+ JSON.dump(
9
+ [
10
+ {
11
+ error: false,
12
+ code_error: 0,
13
+ error_message: "null",
14
+ response: {
15
+ cp: "97305",
16
+ asentamiento: "Granjas Cholul",
17
+ tipo_asentamiento: "Colonia",
18
+ municipio: "Mérida",
19
+ estado: "Yucatán",
20
+ ciudad: "",
21
+ pais: "México"
22
+ }
23
+ },
24
+ {
25
+ error: false,
26
+ code_error: 0,
27
+ error_message: "null",
28
+ response: {
29
+ cp: "97305",
30
+ asentamiento: "Cabo Norte",
31
+ tipo_asentamiento: "Fraccionamiento",
32
+ municipio: "Mérida",
33
+ estado: "Yucatán",
34
+ ciudad: "",
35
+ pais: "México"
36
+ }
37
+ }
38
+ ]
39
+ ),
40
+ status: 200
41
+ )
42
+
43
+ zip_code = SEPOMEX_HCKDRK::General.info_zip_code(zip_code: '97305')
44
+
45
+ expect(zip_code).to be_a(SEPOMEX_HCKDRK::ZipCode)
46
+ expect(zip_code.zip_code).to eq('97305')
47
+ expect(zip_code.settlement).to eq('Granjas Cholul')
48
+ expect(zip_code.settlement_type).to eq('Colonia')
49
+ expect(zip_code.municipality).to eq('Mérida')
50
+ expect(zip_code.state).to eq('Yucatán')
51
+ expect(zip_code.city).to be_nil
52
+ expect(zip_code.country).to eq('México')
53
+ end
54
+
55
+ it 'raises error whith invalid cp' do
56
+ stub_request(:get, 'https://api-sepomex.hckdrk.mx/query/info_cp/97305123').to_return(
57
+ body:
58
+ JSON.dump(
59
+ {
60
+ error: true,
61
+ code_error: 102,
62
+ error_message: "La longitud del cp es inválida",
63
+ response: "null"
64
+ }
65
+ ),
66
+ status: 200
67
+ )
68
+
69
+ begin
70
+ zip_code = SEPOMEX_HCKDRK::General.info_zip_code(zip_code: '97305123')
71
+ rescue => exception
72
+ expect(exception).to be_a(SEPOMEX_HCKDRK::RequestError)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,7 @@
1
+ require 'webmock/rspec'
2
+ require 'rspec'
3
+ require 'simplecov'
4
+
5
+ require 'sepomex_hckdrk'
6
+
7
+ SimpleCov.start { add_filter '/spec/' }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sepomex_hckdrk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yellowme
@@ -100,7 +100,22 @@ executables: []
100
100
  extensions: []
101
101
  extra_rdoc_files: []
102
102
  files:
103
+ - ".gitignore"
104
+ - Gemfile
105
+ - Gemfile.lock
106
+ - LICENSE
107
+ - README.md
108
+ - Rakefile
103
109
  - lib/sepomex_hckdrk.rb
110
+ - lib/sepomex_hckdrk/client/api_client.rb
111
+ - lib/sepomex_hckdrk/client/json_api.rb
112
+ - lib/sepomex_hckdrk/error.rb
113
+ - lib/sepomex_hckdrk/general.rb
114
+ - lib/sepomex_hckdrk/structs/zip_code.rb
115
+ - lib/sepomex_hckdrk/version.rb
116
+ - sepomex_hckdrk.gemspec
117
+ - spec/sepomex_hckdrk/general_spec.rb
118
+ - spec/spec_helper.rb
104
119
  homepage: https://rubygems.org/gems/sepomex-hckdrk-ruby
105
120
  licenses:
106
121
  - MIT
@@ -125,4 +140,6 @@ rubygems_version: 2.7.6
125
140
  signing_key:
126
141
  specification_version: 4
127
142
  summary: Ruby that provides a library to SEPOMEX HCKDRK API
128
- test_files: []
143
+ test_files:
144
+ - spec/sepomex_hckdrk/general_spec.rb
145
+ - spec/spec_helper.rb