janio_api 0.2.1 → 0.3.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: 6563c2fcc213efcc5814f62dc6f7d710a8d4d686519c2bfc2a31879f55df06fd
4
- data.tar.gz: e079a825f69e71d7a8bacc2724e01df367836707c3cec657ac23a5e4d6778e81
3
+ metadata.gz: aa093e0f5ad7e07588aaf0c058fea09ef6ee4fbfa7e44044557e0fa313dc15cd
4
+ data.tar.gz: da73f1b6206dc12d175a71fbf6c73b43562eb4ec0c99b36dd5579c8bebf35863
5
5
  SHA512:
6
- metadata.gz: 074abb6b51f02c06a2682b0b0907a76030550871fd0e3461eda9c71cbd46ae1ebbe5fe819edf934bbd85f228e308e9a0374a33c8b35a11f02b44f230f11b8623
7
- data.tar.gz: d2e9ad3547f786c0a6353fa6b7353a8d8dd0898d2dcce38df9e69043fa4dbe6e058dc0a3e257873a29d5d7b1f474e14eacc52a51f140d27f5fa0b2fca5997951
6
+ metadata.gz: 934f2a7a98afd7dec8d84212fb4233484c7f31521812e4b2ca2e91060dff3f87a35f49c35e60b73f103de6257accaaafab0f079978f3809534f19fad2a4b3f3f
7
+ data.tar.gz: 569852e237c4db83f14c3092604ecfd27f1edd01aef5ac72ec93ed3021c810c816167c19bb2bf3bb25aeb7f4bd867afa7a86e463bcc85ced8696343f94f1fbe1
@@ -0,0 +1,42 @@
1
+ name: Rspec
2
+
3
+ on: [push]
4
+
5
+ env:
6
+ POSTGRES_USER: postgres
7
+ POSTGRES_PASSWORD: "postgres"
8
+ POSTGRES_DB: "postco_test"
9
+
10
+ jobs:
11
+ rspec:
12
+ name: Rspec
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ ruby: ["2.5", "2.6", "2.7"]
17
+ steps:
18
+ - name: Checkout to repo
19
+ uses: actions/checkout@master
20
+
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+
26
+ - name: Cache ruby gems
27
+ uses: actions/cache@v1
28
+ with:
29
+ path: vendor/bundle
30
+ key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
31
+ restore-keys: |
32
+ ${{ runner.os }}-gems-
33
+
34
+ - name: Build gem
35
+ run: |
36
+ gem install bundler
37
+ bundle config path vendor/bundle
38
+ bundle install --jobs 4 --retry 3
39
+
40
+ - name: Run rspec tests
41
+ run: |
42
+ bundle exec rspec spec
data/Gemfile.lock CHANGED
@@ -1,8 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- janio_api (0.2.0)
4
+ janio_api (0.2.1)
5
5
  activeresource
6
+ countries
7
+ phonelib
6
8
 
7
9
  GEM
8
10
  remote: https://rubygems.org/
@@ -27,12 +29,42 @@ GEM
27
29
  byebug (11.1.1)
28
30
  coderay (1.1.2)
29
31
  concurrent-ruby (1.1.6)
32
+ countries (3.0.0)
33
+ i18n_data (~> 0.8.0)
34
+ sixarm_ruby_unaccent (~> 1.1)
35
+ unicode_utils (~> 1.4)
30
36
  diff-lcs (1.3)
31
37
  dotenv (2.7.5)
38
+ ffi (1.12.2)
39
+ formatador (0.2.5)
40
+ guard (2.16.2)
41
+ formatador (>= 0.2.4)
42
+ listen (>= 2.7, < 4.0)
43
+ lumberjack (>= 1.0.12, < 2.0)
44
+ nenv (~> 0.1)
45
+ notiffany (~> 0.0)
46
+ pry (>= 0.9.12)
47
+ shellany (~> 0.0)
48
+ thor (>= 0.18.1)
49
+ guard-compat (1.2.1)
50
+ guard-rspec (4.7.3)
51
+ guard (~> 2.1)
52
+ guard-compat (~> 1.1)
53
+ rspec (>= 2.99.0, < 4.0)
32
54
  i18n (1.8.2)
33
55
  concurrent-ruby (~> 1.0)
56
+ i18n_data (0.8.0)
57
+ listen (3.2.1)
58
+ rb-fsevent (~> 0.10, >= 0.10.3)
59
+ rb-inotify (~> 0.9, >= 0.9.10)
60
+ lumberjack (1.2.4)
34
61
  method_source (1.0.0)
35
62
  minitest (5.14.0)
63
+ nenv (0.3.0)
64
+ notiffany (0.1.3)
65
+ nenv (~> 0.1)
66
+ shellany (~> 0.0)
67
+ phonelib (0.6.43)
36
68
  pry (0.13.1)
37
69
  coderay (~> 1.1)
38
70
  method_source (~> 1.0)
@@ -40,6 +72,9 @@ GEM
40
72
  byebug (~> 11.0)
41
73
  pry (~> 0.13.0)
42
74
  rake (12.3.3)
75
+ rb-fsevent (0.10.3)
76
+ rb-inotify (0.10.1)
77
+ ffi (~> 1.0)
43
78
  rspec (3.9.0)
44
79
  rspec-core (~> 3.9.0)
45
80
  rspec-expectations (~> 3.9.0)
@@ -53,9 +88,13 @@ GEM
53
88
  diff-lcs (>= 1.2.0, < 2.0)
54
89
  rspec-support (~> 3.9.0)
55
90
  rspec-support (3.9.2)
91
+ shellany (0.0.1)
92
+ sixarm_ruby_unaccent (1.2.0)
93
+ thor (1.0.1)
56
94
  thread_safe (0.3.6)
57
95
  tzinfo (1.2.7)
58
96
  thread_safe (~> 0.1)
97
+ unicode_utils (1.4.0)
59
98
  zeitwerk (2.3.0)
60
99
 
61
100
  PLATFORMS
@@ -63,6 +102,7 @@ PLATFORMS
63
102
 
64
103
  DEPENDENCIES
65
104
  dotenv
105
+ guard-rspec
66
106
  janio_api!
67
107
  pry
68
108
  pry-byebug
data/Guardfile ADDED
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.call("routing/#{m[1]}_routing"),
51
+ rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ rspec.spec.call("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+ end
data/bin/console CHANGED
@@ -1,14 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
+ require "dotenv/load"
5
+ require "dev/zeitwerk_loader"
6
+ require "dev/config"
4
7
  require "janio_api"
5
8
 
6
9
  # You can add fixtures and/or initialization code here to make experimenting
7
10
  # with your gem easier. You can also use a different console, if you like.
8
- require "dev/config"
11
+ set_config
9
12
 
10
13
  # (If you use this, don't forget to add pry to your Gemfile!)
11
14
  require "pry"
15
+ require "pry-byebug"
12
16
  Pry.start
13
17
 
14
18
  # require "irb"
data/bin/setup CHANGED
@@ -8,10 +8,8 @@ bundle install
8
8
  # Do any other automated setup that you need to do here
9
9
 
10
10
  filename=".env"
11
- if [ ! -f $filename ]
12
- then
11
+ if [ ! -f $filename ]; then
13
12
  touch $filename
14
- echo "API_HOST=https://janio-api-int.herokuapp.com" >> $filename
15
- echo "API_TOKEN=" >> $filename
16
- echo "JANIO_API_GEM_ENV=development" >> $filename
17
- fi
13
+ echo "API_HOST=https://janio-api-int.herokuapp.com" >>$filename
14
+ echo "API_TOKEN=" >>$filename
15
+ fi
data/janio_api.gemspec CHANGED
@@ -27,9 +27,12 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ["lib"]
28
28
 
29
29
  spec.add_dependency "activeresource"
30
+ spec.add_dependency "countries"
31
+ spec.add_dependency "phonelib"
30
32
 
31
33
  spec.add_development_dependency "rspec", "~> 3.2"
32
34
  spec.add_development_dependency "dotenv"
33
35
  spec.add_development_dependency "pry-byebug"
34
36
  spec.add_development_dependency "pry"
37
+ spec.add_development_dependency "guard-rspec"
35
38
  end
data/lib/dev/config.rb CHANGED
@@ -1,7 +1,8 @@
1
+ require "dotenv/load"
2
+
1
3
  def set_config
2
4
  JanioAPI.configure do |config|
3
5
  config.api_host = ENV["API_HOST"]
4
6
  config.api_token = ENV["API_TOKEN"]
5
7
  end
6
8
  end
7
- set_config
@@ -1,11 +1,15 @@
1
1
  require "zeitwerk"
2
+ require_relative "config"
2
3
 
3
4
  loader = Zeitwerk::Loader.for_gem
4
5
  loader.inflector.inflect(
5
6
  "janio_api" => "JanioAPI"
6
7
  )
8
+ loader.push_dir("./lib")
7
9
  loader.collapse("./lib/janio_api/resources")
8
10
  loader.ignore("#{__dir__}/config.rb")
11
+ loader.ignore("./lib/janio_api/exceptions.rb")
12
+ loader.ignore("./lib/janio_api/services_list.rb")
9
13
  loader.enable_reloading
10
14
  # loader.log!
11
15
  loader.setup
@@ -17,36 +17,5 @@ module JanioAPI
17
17
  rescue OpenSSL::SSL::SSLError => e
18
18
  raise SSLError.new(e.message)
19
19
  end
20
-
21
- private
22
-
23
- def handle_response(response)
24
- case response.code.to_i
25
- when 200...400
26
- response
27
- when 400
28
- raise(BadRequest.new(response))
29
- when 401
30
- raise(UnauthorizedAccess.new(response))
31
- when 403
32
- raise(ForbiddenAccess.new(response))
33
- when 404
34
- raise(ResourceNotFound.new(response))
35
- when 405
36
- raise(MethodNotAllowed.new(response))
37
- when 409
38
- raise(ResourceConflict.new(response))
39
- when 410
40
- raise(ResourceGone.new(response))
41
- when 422
42
- raise(ResourceInvalid.new(response))
43
- when 401...500
44
- raise(ClientError.new(response))
45
- when 500...600
46
- raise(ServerError.new(response))
47
- else
48
- raise(ConnectionError.new(response, "Unknown response code: #{response.code}"))
49
- end
50
- end
51
20
  end
52
21
  end
@@ -15,69 +15,70 @@ module JanioAPI
15
15
 
16
16
  self.collection_parser = Collection
17
17
 
18
- SUPPORTED_PICKUP_COUNTRIES = ["Singapore", "China", "Hong Kong", "Indonesia", "Malaysia", "Philippines", "Thailand"].freeze
19
- SUPPORTED_CONSIGNEE_COUNTRIES = ["Indonesia", "Singapore", "Thailand", "Malaysia", "Philippines", "China", "Hong Kong", "Taiwan", "Brunei", "South Korea", "Japan", "Vietnam"].freeze
18
+ SUPPORTED_PICKUP_COUNTRIES = SERVICES.map { |s| s[:pickup_country] }.uniq.freeze
19
+ SUPPORTED_CONSIGNEE_COUNTRIES = SERVICES.map { |s| s[:consignee_country] }.uniq.freeze
20
20
 
21
21
  POSTAL_EXCLUDED_COUNTRIES = ["Hong Kong", "Vietnam", "Brunei"].freeze
22
22
  VALID_PAYMENT_TYPES = ["cod", "prepaid"].freeze
23
23
 
24
- SERVICE_ID_MAP = [
25
- {id: 1, from: "Singapore", to: "Indonesia"},
26
- {id: 6, from: "China", to: "Indonesia"},
27
- {id: 5, from: "China", to: "Singapore"},
28
- {id: 7, from: "China", to: "Thailand"},
29
- {id: 11, from: "Hong Kong", to: "Indonesia"},
30
- {id: 37, from: "Hong Kong", to: "Malaysia"},
31
- {id: 33, from: "Hong Kong", to: "Philippines"},
32
- {id: 13, from: "Hong Kong", to: "Singapore"},
33
- {id: 12, from: "Hong Kong", to: "Thailand"},
34
- {id: 41, from: "Indonesia", to: "China"},
35
- {id: 41, from: "Indonesia", to: "Hong Kong"},
36
- {id: 41, from: "Indonesia", to: "Taiwan"},
37
- {id: 41, from: "Indonesia", to: "Brunei"},
38
- {id: 41, from: "Indonesia", to: "Philippines"},
39
- {id: 41, from: "Indonesia", to: "Malaysia"},
40
- {id: 3, from: "Indonesia", to: "Indonesia"},
41
- {id: 47, from: "Indonesia", to: "Philippines"},
42
- {id: 54, from: "Indonesia", to: "Philippines"},
43
- {id: 20, from: "Indonesia", to: "Singapore"},
44
- {id: 48, from: "Indonesia", to: "Singapore"},
45
- {id: 22, from: "Indonesia", to: "South Korea"},
46
- {id: 22, from: "Indonesia", to: "Japan"},
47
- {id: 22, from: "Indonesia", to: "Vietnam"},
48
- {id: 4, from: "Malaysia", to: "Indonesia"},
49
- {id: 40, from: "Malaysia", to: "Malaysia"},
50
- {id: 36, from: "Philippines", to: "Philippines"},
51
- {id: 2, from: "Singapore", to: "China"},
52
- {id: 2, from: "Singapore", to: "Taiwan"},
53
- {id: 2, from: "Singapore", to: "South Korea"},
54
- {id: 2, from: "Singapore", to: "Brunei"},
55
- {id: 2, from: "Singapore", to: "Vietnam"},
56
- {id: 2, from: "Singapore", to: "Hong Kong"},
57
- {id: 2, from: "Singapore", to: "Japan"},
58
- {id: 26, from: "Singapore", to: "Malaysia"},
59
- {id: 10, from: "Singapore", to: "Singapore"},
60
- {id: 17, from: "Singapore", to: "Thailand"},
61
- {id: 34, from: "Thailand", to: "Indonesia"},
62
- {id: 35, from: "Thailand", to: "Singapore"}
63
- ].freeze
64
-
24
+ DEFAULT_ATTRS = {
25
+ service_id: 1,
26
+ tracking_no: nil,
27
+ shipper_order_id: nil,
28
+ order_length: 12,
29
+ order_width: 12,
30
+ order_height: 12,
31
+ order_weight: 1,
32
+ payment_type: nil,
33
+ cod_amount_to_collect: 0,
34
+ consignee_name: nil,
35
+ consignee_number: nil,
36
+ consignee_country: nil,
37
+ consignee_address: nil,
38
+ consignee_postal: nil,
39
+ consignee_state: nil,
40
+ consignee_city: nil,
41
+ consignee_province: nil,
42
+ consignee_email: nil,
43
+ pickup_contact_name: nil,
44
+ pickup_contact_number: nil,
45
+ pickup_country: nil,
46
+ pickup_address: nil,
47
+ pickup_postal: nil,
48
+ pickup_state: nil,
49
+ pickup_city: nil,
50
+ pickup_province: nil,
51
+ pickup_date: nil,
52
+ pickup_notes: nil,
53
+ items: nil
54
+ }
65
55
  self.prefix = "/api/order/orders/"
66
56
  self.element_name = ""
67
57
 
68
58
  has_many :items, class_name: "JanioAPI::Item"
69
59
 
70
- validates :service_id, :order_length, :order_width, :order_height, :order_weight, :cod_amount_to_collect, :consignee_name, :consignee_number, :consignee_country,
71
- :consignee_address, :consignee_state, :consignee_email, :pickup_contact_name, :pickup_contact_number, :pickup_country, :pickup_address,
72
- :pickup_state, :pickup_date, presence: true
73
-
74
- validates :pickup_country, inclusion: {in: SUPPORTED_PICKUP_COUNTRIES, message: "%{value} is not a supported pickup country, supported countries are #{SUPPORTED_PICKUP_COUNTRIES.join(", ")}"}
75
- validates :consignee_country, inclusion: {in: SUPPORTED_CONSIGNEE_COUNTRIES, message: "%{value} is not a supported consignee country, supported countries are #{SUPPORTED_CONSIGNEE_COUNTRIES.join(", ")}"}
76
- validates :pickup_postal, :consignee_postal, presence: true, unless: -> { POSTAL_EXCLUDED_COUNTRIES.include?(consignee_country) }
60
+ validates :service_id, :order_length, :order_width, :order_height, :order_weight,
61
+ :consignee_name, :consignee_country, :consignee_address, :consignee_state, :consignee_email,
62
+ :pickup_contact_name, :pickup_country, :pickup_address, :pickup_state, :pickup_date, presence: true
63
+
64
+ validates :pickup_country, inclusion: {
65
+ in: SUPPORTED_PICKUP_COUNTRIES,
66
+ message: "%{value} is not a supported pickup country, supported countries are #{SUPPORTED_PICKUP_COUNTRIES.join(", ")}"
67
+ }
68
+ validates :consignee_country, inclusion: {
69
+ in: SUPPORTED_CONSIGNEE_COUNTRIES,
70
+ message: "%{value} is not a supported consignee country, supported countries are #{SUPPORTED_CONSIGNEE_COUNTRIES.join(", ")}"
71
+ }
72
+ validates :consignee_postal, presence: true, unless: -> { POSTAL_EXCLUDED_COUNTRIES.include?(consignee_country) }
77
73
  validates :pickup_postal, presence: true, unless: -> { POSTAL_EXCLUDED_COUNTRIES.include?(pickup_country) }
78
- validates :payment_type, inclusion: {in: VALID_PAYMENT_TYPES, message: "%{value} is not a valid payment type, valid payment types are #{VALID_PAYMENT_TYPES.join(", ")}"}
74
+ validates :payment_type, inclusion: {
75
+ in: VALID_PAYMENT_TYPES,
76
+ message: "%{value} is not a valid payment type, valid payment types are #{VALID_PAYMENT_TYPES.join(", ")}"
77
+ }
79
78
  validates :cod_amount_to_collect, presence: true, if: -> { payment_type == "cod" }
80
79
  validates :items, length: {minimum: 1, message: "are required. Please add at least one."}
80
+ validate :pickup_contact_number_country_matched?
81
+ validate :consignee_number_country_matched?
81
82
  validate :items_validation
82
83
  validate :route_supported?
83
84
 
@@ -95,8 +96,8 @@ module JanioAPI
95
96
  options = arguments.slice!(0) || {}
96
97
  options[:from] = "/api/order/order" unless options[:from]
97
98
  options[:params] = {} unless options[:params]
98
- options[:params][:secret_key] = JanioAPI.config.api_token
99
99
  options[:params][:with_items] = true unless options[:params][:with_items]
100
+ options[:params][:secret_key] = JanioAPI.config.api_token
100
101
 
101
102
  case scope
102
103
  when :all
@@ -128,48 +129,22 @@ module JanioAPI
128
129
  end
129
130
 
130
131
  def initialize(attributes = {}, persisted = false)
131
- default_attrs = {
132
- service_id: 1,
133
- tracking_no: nil,
134
- shipper_order_id: nil,
135
- order_length: 12,
136
- order_width: 12,
137
- order_height: 12,
138
- order_weight: 1,
139
- payment_type: nil,
140
- cod_amount_to_collect: 0,
141
- consignee_name: nil,
142
- consignee_number: nil,
143
- consignee_country: nil,
144
- consignee_address: nil,
145
- consignee_postal: nil,
146
- consignee_state: nil,
147
- consignee_city: nil,
148
- consignee_province: nil,
149
- consignee_email: nil,
150
- pickup_contact_name: nil,
151
- pickup_contact_number: nil,
152
- pickup_country: nil,
153
- pickup_address: nil,
154
- pickup_postal: nil,
155
- pickup_state: nil,
156
- pickup_city: nil,
157
- pickup_province: nil,
158
- pickup_date: nil,
159
- pickup_notes: nil,
160
- items: nil
161
- }
162
- attributes = default_attrs.merge(attributes)
132
+ attributes = DEFAULT_ATTRS.merge(attributes)
163
133
  super
164
134
  set_service_id
165
135
  end
166
136
 
167
- def get_service_id
168
- SERVICE_ID_MAP.find { |route| route[:from] == pickup_country && route[:to] == consignee_country }&.dig(:id)
137
+ def get_service_id(service_category = "pickup")
138
+ # only check with services offering pickup by default
139
+ SERVICES.find do |s|
140
+ s[:pickup_country] == pickup_country &&
141
+ s[:consignee_country] == consignee_country &&
142
+ s[:service_category] == service_category
143
+ end&.dig(:id)
169
144
  end
170
145
 
171
- def set_service_id
172
- @attributes[:service_id] = get_service_id
146
+ def set_service_id(service_category = "pickup")
147
+ @attributes[:service_id] = get_service_id(service_category)
173
148
  end
174
149
 
175
150
  # Tracks the current order
@@ -193,6 +168,26 @@ module JanioAPI
193
168
 
194
169
  private
195
170
 
171
+ def pickup_contact_number_country_matched?
172
+ country_code = ISO3166::Country.find_country_by_name(pickup_country)&.alpha2
173
+ if Phonelib.invalid_for_country? pickup_contact_number, country_code
174
+ errors.add(
175
+ :pickup_contact_number,
176
+ "is invalid, please make sure the phone's country code matches the pickup address's country"
177
+ )
178
+ end
179
+ end
180
+
181
+ def consignee_number_country_matched?
182
+ country_code = ISO3166::Country.find_country_by_name(consignee_country)&.alpha2
183
+ if Phonelib.invalid_for_country? consignee_number, country_code
184
+ errors.add(
185
+ :consignee_number,
186
+ "is invalid, please make sure the phone's country code matches the consignee address's country"
187
+ )
188
+ end
189
+ end
190
+
196
191
  def route_supported?
197
192
  unless set_service_id
198
193
  errors.add(:route, "not supported, if new route not available in service_id_map, please contact gem author.")