janio_api 0.3.2 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ead05593ce47d76a8f18f547f61d7c84783554909b4eb4f1d80b5c9d21f29dc
4
- data.tar.gz: 4db668fd55a9019167d52534243578802eda8ee2766a1a589abe139162bdfe15
3
+ metadata.gz: 2eb551722b7d734da79c0c34f59c6f14c8866e2656562b0fd25bdba9bcdc3fb3
4
+ data.tar.gz: 487e7b65437e433546c116aba987176b41ad937d4c6937bcf5270c7995ab2907
5
5
  SHA512:
6
- metadata.gz: a67d8337c5d5e0ddcc4b45ba0a299eacae6010cab7fb4c4e7654b04f5116b62a111c0c9e77f6bbbdf16b22b1f7c12c5b1e9284ae93da8c609a541dd280cc094c
7
- data.tar.gz: ced2968fb2fbf5b4dc438c8543d3e8cc342a349d5db65c61b6c3d4db7cbc9131896b1931c6c03c4f727b3f805f9ae1ed3542b58e80183a8e641b2777fc011fdb
6
+ metadata.gz: a8dc69b4891a6d07f6a7d78a47a518e69819bbfe6b78b86784bc557fb4433e547160da13bf355efd1e36cb9a17c8b808f8a95e09039777cb11082922e1c83329
7
+ data.tar.gz: '075582cc9cf498238a20f37a5e5107fc89644651526ab42b8c53450f5bd6e27db04e573342ba8ba3b9eb12467371b42b3c067e32c4fe4e6111862cb52f711067'
data/.gitignore CHANGED
@@ -6,8 +6,10 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /Gemfile.lock
10
+ /.vscode
9
11
 
10
12
  # rspec failure tracking
11
13
  .rspec_status
12
14
  .env
13
- .pryrc
15
+ .pryrc
data/README.md CHANGED
@@ -31,7 +31,7 @@ Or install it yourself as:
31
31
 
32
32
  config.api_token = ENV["API_TOKEN"]
33
33
  # or
34
- # api_tokens will take over api_token if set in config
34
+ # api_tokens will take higher precedence than api_token
35
35
  config.api_tokens = {
36
36
  MY: ENV["MALAYSIA_JANIO_API_TOKEN"],
37
37
  SG: ENV["SINGAPORE_JANIO_API_TOKEN"],
@@ -26,9 +26,9 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ["lib"]
28
28
 
29
- spec.add_dependency "activeresource"
30
- spec.add_dependency "countries"
31
- spec.add_dependency "phonelib"
29
+ spec.add_dependency "activeresource", "~> 5.0"
30
+ spec.add_dependency "countries", "~> 3.0"
31
+ spec.add_dependency "phonelib", "~> 0.6"
32
32
 
33
33
  spec.add_development_dependency "rspec", "~> 3.2"
34
34
  spec.add_development_dependency "dotenv"
@@ -3,10 +3,12 @@ require "dotenv/load"
3
3
  def set_config
4
4
  JanioAPI.configure do |config|
5
5
  config.api_host = ENV["API_HOST"]
6
- # config.api_token = ENV["API_TOKEN"]
7
- config.api_tokens = {
8
- MY: ENV["MY_API_TOKEN"],
9
- SG: ENV["SG_API_TOKEN"]
10
- }
6
+ config.api_token = ENV["API_TOKEN"]
7
+ # or
8
+ # api_tokens take higher precedence than api_token
9
+ # config.api_tokens = {
10
+ # MY: ENV["MY_API_TOKEN"],
11
+ # SG: ENV["SG_API_TOKEN"]
12
+ # }
11
13
  end
12
14
  end
@@ -10,6 +10,7 @@ loader.collapse("./lib/janio_api/resources")
10
10
  loader.ignore("#{__dir__}/config.rb")
11
11
  loader.ignore("./lib/janio_api/exceptions.rb")
12
12
  loader.ignore("./lib/janio_api/services_list.rb")
13
+ loader.ignore("./lib/janio_api/postal_code_regex_list.rb")
13
14
  loader.enable_reloading
14
15
  # loader.log!
15
16
  loader.setup
@@ -6,6 +6,7 @@ module JanioAPI
6
6
  require "countries"
7
7
 
8
8
  require "janio_api/services_list"
9
+ require "janio_api/postal_code_regex_list"
9
10
 
10
11
  require "janio_api/configuration"
11
12
 
@@ -0,0 +1,190 @@
1
+ module JanioAPI
2
+ POSTAL_CODE_REGEX = {
3
+ AC: "^(ASCN 1ZZ)$",
4
+ AD: "^(?:AD)*(\\d{3})$",
5
+ AF: "^(\\d{4})$",
6
+ AG: "^(\\d{5})$",
7
+ AI: "^(AI-2640)$",
8
+ AL: "^(\\d{4})$",
9
+ AM: "^(\\d{4})$",
10
+ AQ: "^(7151)$",
11
+ AR: "^([A-Z]\\d{4}[A-Z]{3})|([A-Z]?\\d{4})$",
12
+ AS: "^(\\d{5})$",
13
+ AT: "^(\\d{4})$",
14
+ AU: "^(\\d{4})$",
15
+ AW: "^(0000 AW)$",
16
+ AX: "^(\\d{5})$",
17
+ AZ: "^(AZ) (\\d{4})$",
18
+ BA: "^(\\d{5})$",
19
+ BB: "^(?:BB)*(\\d{5})$",
20
+ BD: "^(\\d{4})$",
21
+ BE: "^(\\d{4})$",
22
+ BG: "^(\\d{4})$",
23
+ BH: "^(\\d{3}\\d?)$",
24
+ BL: "^(\\d{5})$",
25
+ BM: "^([A-Z]{2} \\d{2})$",
26
+ BN: "^([A-Z]{2}\\d{4})$",
27
+ BQ: "^(0000 BQ)$",
28
+ BR: "^[0-9]{5}-[0-9]{3}$",
29
+ BT: "^(\\d{5})$",
30
+ BY: "^(\\d{6})$",
31
+ CA: "^(?!.*[DFIOQU])[A-VXY][0-9][A-Z] +?[0-9][A-Z][0-9]$",
32
+ CC: "^(6799 W3)$",
33
+ CH: "^(\\d{4})$",
34
+ CL: "^(\\d{7})$",
35
+ CN: "^(\\d{6})$",
36
+ CO: "^(\\d{6})$",
37
+ CR: "^(\\d{5})$",
38
+ CU: "^(?:CP)*(\\d{5})$",
39
+ CV: "^(\\d{4})$",
40
+ CW: "^(0000 CW)$",
41
+ CX: "^(6978)$",
42
+ CY: "^(\\d{4})$",
43
+ CZ: "^[0-9]{3} [0-9]{2}$",
44
+ DE: "^(\\d{5})$",
45
+ DK: "^(\\d{4})$",
46
+ DO: "^(\\d{5})$",
47
+ DZ: "^(\\d{5})$",
48
+ EC: "^(\\d{6})$",
49
+ EE: "^(\\d{5})$",
50
+ EG: "^(\\d{5})$",
51
+ EH: "^(\\d{5})$",
52
+ ES: "^(\\d{5})$",
53
+ ET: "^(\\d{4})$",
54
+ FI: "^(?:FI)*(\\d{5})$",
55
+ FK: "^(FIQQ 1ZZ)$",
56
+ FM: "^(\\d{5})$",
57
+ FO: "^(?:FO)*(\\d{3})$",
58
+ FR: "^(\\d{5})$",
59
+ GB: "^(((([A-PR-UWYZ][0-9][0-9A-HJKS-UW]?)|([A-PR-UWYZ][A-HK-Y][0-9][0-9ABEHMNPRV-Y]?))\\s{0,2}[0-9]([ABD-HJLNP-UW-Z]{2}))|(GIR\\s{0,2}0AA))$",
60
+ GE: "^(\\d{4})$",
61
+ GF: "^((973)\\d{2})$",
62
+ GG: "((GY)([0-9][0-9A-HJKPS-UW]?|[A-HK-Y][0-9][0-9ABEHMNPRV-Y]?) [0-9][ABD-HJLNP-UW-Z]{2})",
63
+ GI: "^(GX11 1AA)$",
64
+ GL: "^(\\d{4})$",
65
+ GN: "^(\\d{3})$",
66
+ GP: "^((971)[0-9][0-0])$",
67
+ GR: "^(\\d{3}) \\d{2}$",
68
+ GS: "^(SIQQ 1ZZ)$",
69
+ GT: "^(\\d{5})$",
70
+ GU: "^((969)[1-3][0-2])$",
71
+ GW: "^(\\d{4})$",
72
+ HK: "^(999077)$",
73
+ HM: "^(7151)$",
74
+ HN: "^(\\d{5})$",
75
+ HR: "^(?:HR)*(\\d{5})$",
76
+ HT: "^(?:HT)*(\\d{4})$",
77
+ HU: "^(\\d{4})$",
78
+ ID: "^(\\d{5})$",
79
+ IE: "^[A-NP-Z\\d]{3}\\s[A-NP-Z\\d]{4}",
80
+ IL: "^(\\d{5})$",
81
+ IM: "((IM)([0-9][0-9A-HJKPS-UW]?|[A-HK-Y][0-9][0-9ABEHMNPRV-Y]?) [0-9][ABD-HJLNP-UW-Z]{2})",
82
+ IN: "^(\\d{6})$",
83
+ IO: "^(BB9D 1ZZ)$",
84
+ IQ: "^(\\d{5})$",
85
+ IR: "^\\d{5}([\\-]\\d{5})?$",
86
+ IS: "^(\\d{3})$",
87
+ IT: "^(\\d{5})$",
88
+ JE: "(JE)([0-9]\\d{1})",
89
+ JM: "^((JM)[A-Z]{3,3}\\d{2,2})$",
90
+ JO: "^(\\d{5})$",
91
+ JP: "^(\\d{3}-\\d{4})$",
92
+ KE: "^(\\d{5})$",
93
+ KG: "^(\\d{6})$",
94
+ KH: "^(\\d{5})$",
95
+ KR: "^(\\d{3}[-]\\d{3})$",
96
+ KW: "^(\\d{5})$",
97
+ KY: "^[K][Y][0-9]{1}[-]([0-9]){4}$",
98
+ KZ: "^(\\d{6})$",
99
+ LA: "^(\\d{5})$",
100
+ LB: "^(\\d{4}(\\d{4})?)$",
101
+ LI: "^(\\d{4})$",
102
+ LK: "^(\\d{5})$",
103
+ LR: "^(\\d{4})$",
104
+ LS: "^(\\d{3})$",
105
+ LT: "^(?:LT)*(\\d{5})$",
106
+ LU: "^(\\d{4})$",
107
+ LV: "^[L]{1}[V]{1}[-]([0-9]){4}$",
108
+ LY: "^(\\d{5})$",
109
+ MA: "^(\\d{5})$",
110
+ MC: "^(\\d{5})$",
111
+ MD: "^(?:MD)*(\\d{4})$",
112
+ ME: "^(\\d{5})$",
113
+ MF: "^(\\d{5})$",
114
+ MG: "^(\\d{3})$",
115
+ MH: "^((969)[6-7][0-9])$",
116
+ MK: "^(\\d{4})$",
117
+ MM: "^(\\d{5})$",
118
+ MN: "^(\\d{5})$",
119
+ MP: "^(\\d{5})$",
120
+ MQ: "^(\\d{5})$",
121
+ MT: "^[A-Z]{3} [0-9]{4}$",
122
+ MU: "^([0-9A-Z]\\d{4})$",
123
+ MV: "^(\\d{5})$",
124
+ MX: "^(\\d{5})$",
125
+ MY: "^(\\d{5})$",
126
+ MZ: "^(\\d{4})$",
127
+ NC: "^(\\d{5})$",
128
+ NE: "^(\\d{4})$",
129
+ NF: "^(2899)$",
130
+ NG: "^(\\d{6})$",
131
+ NI: "^(\\d{5})$",
132
+ NL: "[0-9]{4} ?[A-Z]{2}",
133
+ NO: "^(\\d{4})$",
134
+ NP: "^(\\d{5})$",
135
+ NZ: "^(\\d{4})$",
136
+ OM: "^(\\d{3})$",
137
+ PE: "^(\\d{5})$",
138
+ PF: "^((987)\\d{2})$",
139
+ PG: "^(\\d{3})$",
140
+ PH: "^(\\d{4})$",
141
+ PK: "^(\\d{5})$",
142
+ PL: "^[0-9]{2}[-]([0-9]){3}$",
143
+ PM: "^(\\d{5})$",
144
+ PN: "^(PCR9 1ZZ)$",
145
+ PR: "^\\d{5}((-|\\s)?\\d{4})?$",
146
+ PS: "^(\\d{5})$",
147
+ PT: "^\\d{4}((-|\\s)?\\d{3})?$",
148
+ PW: "^(96940)$",
149
+ PY: "^(\\d{4})$",
150
+ RE: "[9]{1}[7|8][4|7|8]\\d{2}",
151
+ RO: "^(\\d{6})$",
152
+ RS: "^(\\d{5})$",
153
+ RU: "^(\\d{6})$",
154
+ SA: "^(\\d{5})$",
155
+ SD: "^(\\d{5})$",
156
+ SE: "^(\\d{3} \\d{2})$",
157
+ SG: "^(\\d{6})$",
158
+ SH: "^[A-Z]{4} (1ZZ)$",
159
+ SI: "^(\\d{4})$",
160
+ SJ: "^(\\d{4})$",
161
+ SK: "^(\\d{3} \\d{2})$",
162
+ SM: "^(4789\\d)$",
163
+ SN: "^(\\d{5})$",
164
+ SS: "^(\\d{5})$",
165
+ SV: "^(01101)$",
166
+ SX: "^(0000 AA)$",
167
+ SZ: "^([A-Z]\\d{3})$",
168
+ TC: "^(TKCA 1ZZ)$",
169
+ TD: "^(\\d{5})$",
170
+ TF: "^((984)\\d{2})$",
171
+ TH: "^(\\d{5})$",
172
+ TJ: "^(\\d{3})$",
173
+ TM: "^(\\d{6})$",
174
+ TN: "^(\\d{4})$",
175
+ TR: "^(\\d{5})$",
176
+ TW: "^(\\d{3} \\d{2})|(\\d{3})$",
177
+ UA: "^(\\d{5})$",
178
+ US: "^\\d{5}([\\-]\\d{4})?$",
179
+ UY: "^(\\d{5})$",
180
+ UZ: "^(\\d{6})$",
181
+ VC: "(VC)(\\d{4})",
182
+ VE: "^(\\d{4})$",
183
+ VG: "^(VG11)[0-6][0]$",
184
+ VI: "^(\\d{5})$",
185
+ VN: "^(\\d{6})$",
186
+ YT: "^(\\d{5})$",
187
+ ZA: "^(\\d{4})$",
188
+ ZM: "^(\\d{5})$"
189
+ }
190
+ end
@@ -4,6 +4,19 @@ module JanioAPI
4
4
  self.include_format_in_path = false
5
5
  self.connection_class = JanioAPI::Connection
6
6
 
7
+ def initialize(attributes = {}, persisted = false)
8
+ # check if config host and api token is set
9
+ unless JanioAPI.config.api_tokens || JanioAPI.config.api_token
10
+ raise ArgumentError, "JanioAPI api_token/api_tokens is missing, please set it in the config."
11
+ end
12
+
13
+ unless JanioAPI.config.api_host
14
+ raise ArgumentError, "JanioAPI api_host is missing, please set it in the config."
15
+ end
16
+
17
+ super
18
+ end
19
+
7
20
  class << self
8
21
  def headers
9
22
  if _headers_defined?
@@ -17,6 +17,7 @@ module JanioAPI
17
17
 
18
18
  SUPPORTED_PICKUP_COUNTRIES = SERVICES.map { |s| s[:pickup_country] }.uniq.freeze
19
19
  SUPPORTED_CONSIGNEE_COUNTRIES = SERVICES.map { |s| s[:consignee_country] }.uniq.freeze
20
+ PICKUP_DATE_ACCEPTED_COUNTRIES = ["Singapore"]
20
21
 
21
22
  POSTAL_EXCLUDED_COUNTRIES = ["Hong Kong", "Vietnam", "Brunei"].freeze
22
23
  VALID_PAYMENT_TYPES = ["cod", "prepaid"].freeze
@@ -59,8 +60,10 @@ module JanioAPI
59
60
 
60
61
  validates :service_id, :order_length, :order_width, :order_height, :order_weight,
61
62
  :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
+ :pickup_contact_name, :pickup_country, :pickup_address, :pickup_state, presence: true
63
64
 
65
+ validates :pickup_date, presence: true, if: -> { PICKUP_DATE_ACCEPTED_COUNTRIES.include?(pickup_country) }
66
+ validates :pickup_date, absence: true, if: -> { !PICKUP_DATE_ACCEPTED_COUNTRIES.include?(pickup_country) }
64
67
  validates :pickup_country, inclusion: {
65
68
  in: SUPPORTED_PICKUP_COUNTRIES,
66
69
  message: "%{value} is not a supported pickup country, supported countries are #{SUPPORTED_PICKUP_COUNTRIES.join(", ")}"
@@ -69,14 +72,14 @@ module JanioAPI
69
72
  in: SUPPORTED_CONSIGNEE_COUNTRIES,
70
73
  message: "%{value} is not a supported consignee country, supported countries are #{SUPPORTED_CONSIGNEE_COUNTRIES.join(", ")}"
71
74
  }
72
- validates :consignee_postal, presence: true, unless: -> { POSTAL_EXCLUDED_COUNTRIES.include?(consignee_country) }
73
- validates :pickup_postal, presence: true, unless: -> { POSTAL_EXCLUDED_COUNTRIES.include?(pickup_country) }
74
75
  validates :payment_type, inclusion: {
75
76
  in: VALID_PAYMENT_TYPES,
76
77
  message: "%{value} is not a valid payment type, valid payment types are #{VALID_PAYMENT_TYPES.join(", ")}"
77
78
  }
78
79
  validates :cod_amount_to_collect, presence: true, if: -> { payment_type == "cod" }
79
80
  validates :items, length: {minimum: 1, message: "are required. Please add at least one."}
81
+ validate :pickup_postal_valid?, unless: -> { POSTAL_EXCLUDED_COUNTRIES.include?(pickup_country) }
82
+ validate :consignee_postal_valid?, unless: -> { POSTAL_EXCLUDED_COUNTRIES.include?(consignee_country) }
80
83
  validate :pickup_contact_number_country_matched?
81
84
  validate :consignee_number_country_matched?
82
85
  validate :items_validation
@@ -114,26 +117,49 @@ module JanioAPI
114
117
  # Track one or more tracking nos
115
118
  #
116
119
  # Check http://apidocs.janio.asia/track for more information
117
- def track(tracking_nos)
118
- raise ArgumentError, "tracking_nos not an array" unless tracking_nos.is_a?(Array)
120
+ def track(tracking_nos, secret_key = nil)
121
+ raise ArgumentError, "tracking_nos must be an array" unless tracking_nos.is_a?(Array)
119
122
 
120
123
  body = {
121
124
  get_related_updates: true,
122
- flatten_data: true,
125
+ flatten_data: false,
123
126
  tracking_nos: tracking_nos
124
127
  }
125
- response = connection.post(tracking_path, body.to_json, headers)
128
+
129
+ headers[:secret_key] = secret_key unless secret_key.nil?
130
+
131
+ raise ArgumentError, "secret_key can't be blank" unless headers[:secret_key].present?
132
+
133
+ retries = 0
134
+ begin
135
+ retries += 1
136
+ response = connection.post(tracking_path, body.to_json, headers)
137
+ rescue ActiveResource::ConnectionError => e
138
+ retry unless retries <= 5
139
+ raise e
140
+ end
126
141
 
127
142
  self.format.decode(response.body)
128
143
  end
129
144
  end
130
145
 
131
146
  def initialize(attributes = {}, persisted = false)
147
+ if attributes[:pickup_date].is_a?(ActiveSupport::TimeWithZone)
148
+ attributes[:pickup_date] = attributes[:pickup_date].strftime("%Y-%-m-%-d")
149
+ end
132
150
  attributes = DEFAULT_ATTRS.merge(attributes)
133
151
  super
134
152
  set_service_id
135
153
  end
136
154
 
155
+ def pickup_date=(date)
156
+ @attributes[:pickup_date] = if date.is_a?(ActiveSupport::TimeWithZone) || date.is_a?(Time)
157
+ date.strftime("%Y-%-m-%-d")
158
+ else
159
+ date
160
+ end
161
+ end
162
+
137
163
  def get_service_id(service_category = "pickup")
138
164
  # only check with services offering pickup by default
139
165
  SERVICES.find do |s|
@@ -156,6 +182,7 @@ module JanioAPI
156
182
  flatten_data: true,
157
183
  tracking_nos: [@attributes[:tracking_no]]
158
184
  }
185
+
159
186
  response = connection.post(self.class.tracking_path, body.to_json, self.class.headers)
160
187
  self.class.format.decode(response.body)[0]
161
188
  end
@@ -168,22 +195,42 @@ module JanioAPI
168
195
 
169
196
  private
170
197
 
198
+ def pickup_country_code
199
+ ISO3166::Country.find_country_by_name(pickup_country)&.alpha2
200
+ end
201
+
202
+ def consignee_country_code
203
+ ISO3166::Country.find_country_by_name(consignee_country)&.alpha2
204
+ end
205
+
206
+ def pickup_postal_valid?
207
+ if pickup_country_code
208
+ regex = Regexp.new(POSTAL_CODE_REGEX[pickup_country_code.to_sym])
209
+ errors.add(:pickup_postal, "is invalid, must match #{regex.inspect}") unless regex.match(pickup_postal)
210
+ end
211
+ end
212
+
213
+ def consignee_postal_valid?
214
+ if consignee_country_code && POSTAL_CODE_REGEX[consignee_country_code.to_sym]
215
+ regex = Regexp.new(POSTAL_CODE_REGEX[consignee_country_code.to_sym])
216
+ errors.add(:consignee_postal, "is invalid, must match #{regex.inspect}") unless regex.match(consignee_postal)
217
+ end
218
+ end
219
+
171
220
  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
221
+ if Phonelib.invalid_for_country?(pickup_contact_number, pickup_country_code)
174
222
  errors.add(
175
223
  :pickup_contact_number,
176
- "is invalid, please make sure the phone's country code matches the pickup address's country"
224
+ "is invalid, please make sure the phone is valid and phone's country code matches the pickup address's country"
177
225
  )
178
226
  end
179
227
  end
180
228
 
181
229
  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
230
+ if Phonelib.invalid_for_country?(consignee_number, consignee_country_code)
184
231
  errors.add(
185
232
  :consignee_number,
186
- "is invalid, please make sure the phone's country code matches the consignee address's country"
233
+ "is invalid, please make sure the phone is valid and phone's country code matches the consignee address's country"
187
234
  )
188
235
  end
189
236
  end
@@ -220,21 +267,21 @@ module JanioAPI
220
267
  def reformat_before_save(blocking)
221
268
  attributes = @attributes.dup
222
269
  @attributes.clear
223
- @attributes[:secret_key] = retrieve_api_token
270
+ @attributes[:secret_key] = retrieve_api_token(attributes[:pickup_country])
224
271
  # set blocking until label generated
225
272
  @attributes[:blocking] = blocking
226
273
  # reformat attributes
227
274
  @attributes[:orders] = [attributes]
228
275
  end
229
276
 
230
- def retrieve_api_token
277
+ def retrieve_api_token(country)
231
278
  if JanioAPI.config.api_tokens
232
- country_code_sym = ISO3166::Country.find_country_by_name(@attributes[:pickup_country])&.alpha2&.to_sym
279
+ country_code_sym = ISO3166::Country.find_country_by_name(country)&.alpha2&.to_sym
233
280
  JanioAPI.config.api_tokens[country_code_sym]
234
281
  elsif JanioAPI.config.api_token
235
282
  JanioAPI.config.api_token
236
283
  else
237
- throw ArgumentError.new("JanioAPI api_token is missing, please set it in the config.")
284
+ raise ArgumentError, "JanioAPI api_token/api_tokens is missing, please set it in the config."
238
285
  end
239
286
  end
240
287
 
@@ -1,3 +1,3 @@
1
1
  module JanioAPI
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.7"
3
3
  end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: janio_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Chong
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-12 00:00:00.000000000 Z
11
+ date: 2020-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '5.0'
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'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: countries
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '3.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: '0'
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: phonelib
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '0.6'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '0.6'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -135,7 +135,6 @@ files:
135
135
  - ".travis.yml"
136
136
  - CODE_OF_CONDUCT.md
137
137
  - Gemfile
138
- - Gemfile.lock
139
138
  - Guardfile
140
139
  - LICENSE.txt
141
140
  - README.md
@@ -148,6 +147,7 @@ files:
148
147
  - lib/janio_api.rb
149
148
  - lib/janio_api/configuration.rb
150
149
  - lib/janio_api/connection.rb
150
+ - lib/janio_api/postal_code_regex_list.rb
151
151
  - lib/janio_api/redirect_fetcher.rb
152
152
  - lib/janio_api/resources/base.rb
153
153
  - lib/janio_api/resources/item.rb
@@ -1,113 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- janio_api (0.3.2)
5
- activeresource
6
- countries
7
- phonelib
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- activemodel (6.0.2.2)
13
- activesupport (= 6.0.2.2)
14
- activemodel-serializers-xml (1.0.2)
15
- activemodel (> 5.x)
16
- activesupport (> 5.x)
17
- builder (~> 3.1)
18
- activeresource (5.1.0)
19
- activemodel (>= 5.0, < 7)
20
- activemodel-serializers-xml (~> 1.0)
21
- activesupport (>= 5.0, < 7)
22
- activesupport (6.0.2.2)
23
- concurrent-ruby (~> 1.0, >= 1.0.2)
24
- i18n (>= 0.7, < 2)
25
- minitest (~> 5.1)
26
- tzinfo (~> 1.1)
27
- zeitwerk (~> 2.2)
28
- builder (3.2.4)
29
- byebug (11.1.1)
30
- coderay (1.1.2)
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)
36
- diff-lcs (1.3)
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)
54
- i18n (1.8.2)
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)
61
- method_source (1.0.0)
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)
68
- pry (0.13.1)
69
- coderay (~> 1.1)
70
- method_source (~> 1.0)
71
- pry-byebug (3.9.0)
72
- byebug (~> 11.0)
73
- pry (~> 0.13.0)
74
- rake (12.3.3)
75
- rb-fsevent (0.10.3)
76
- rb-inotify (0.10.1)
77
- ffi (~> 1.0)
78
- rspec (3.9.0)
79
- rspec-core (~> 3.9.0)
80
- rspec-expectations (~> 3.9.0)
81
- rspec-mocks (~> 3.9.0)
82
- rspec-core (3.9.1)
83
- rspec-support (~> 3.9.1)
84
- rspec-expectations (3.9.1)
85
- diff-lcs (>= 1.2.0, < 2.0)
86
- rspec-support (~> 3.9.0)
87
- rspec-mocks (3.9.1)
88
- diff-lcs (>= 1.2.0, < 2.0)
89
- rspec-support (~> 3.9.0)
90
- rspec-support (3.9.2)
91
- shellany (0.0.1)
92
- sixarm_ruby_unaccent (1.2.0)
93
- thor (1.0.1)
94
- thread_safe (0.3.6)
95
- tzinfo (1.2.7)
96
- thread_safe (~> 0.1)
97
- unicode_utils (1.4.0)
98
- zeitwerk (2.3.0)
99
-
100
- PLATFORMS
101
- ruby
102
-
103
- DEPENDENCIES
104
- dotenv
105
- guard-rspec
106
- janio_api!
107
- pry
108
- pry-byebug
109
- rake (~> 12.3)
110
- rspec (~> 3.2)
111
-
112
- BUNDLED WITH
113
- 2.1.4