janio_api 0.3.3 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/janio_api.gemspec +3 -3
- data/lib/dev/zeitwerk_loader.rb +1 -0
- data/lib/janio_api.rb +1 -0
- data/lib/janio_api/postal_code_regex_list.rb +190 -0
- data/lib/janio_api/resources/base.rb +10 -9
- data/lib/janio_api/resources/order.rb +59 -16
- data/lib/janio_api/version.rb +1 -1
- metadata +15 -15
- data/Gemfile.lock +0 -113
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae0cb146ffba0fbc7662773a8325a9cd72a6e5eb7714973acc335dfc9d717097
|
4
|
+
data.tar.gz: 5ff252c4242ce0d9d3b4b0446daadd9b0841b9af291507145f5bb2b47d137875
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbba3362c3a30f88300346b69205fca18d622503ff65dea468776a11f14d31c51d29b12b9a7b6e36bad6b35a7d3dea09166003281b649f1d306351ef7ff13ce5
|
7
|
+
data.tar.gz: 0abe6280d48b98d3c9e4598aa9c72326789001e6f949e31e51ee954b35d176ed3e126a6bbd137baa22c1bc7dbf89798705b440bfe122ff608acd120134c51ce5
|
data/.gitignore
CHANGED
data/janio_api.gemspec
CHANGED
@@ -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"
|
data/lib/dev/zeitwerk_loader.rb
CHANGED
@@ -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
|
data/lib/janio_api.rb
CHANGED
@@ -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,16 +4,17 @@ module JanioAPI
|
|
4
4
|
self.include_format_in_path = false
|
5
5
|
self.connection_class = JanioAPI::Connection
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
elsif superclass != Object && superclass.headers
|
12
|
-
superclass.headers
|
13
|
-
else
|
14
|
-
_headers ||= {}
|
15
|
-
end
|
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."
|
16
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
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
@@ -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,
|
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
|
@@ -115,25 +118,44 @@ module JanioAPI
|
|
115
118
|
#
|
116
119
|
# Check http://apidocs.janio.asia/track for more information
|
117
120
|
def track(tracking_nos)
|
118
|
-
raise ArgumentError, "tracking_nos
|
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:
|
125
|
+
flatten_data: false,
|
123
126
|
tracking_nos: tracking_nos
|
124
127
|
}
|
125
|
-
|
128
|
+
|
129
|
+
retries = 0
|
130
|
+
begin
|
131
|
+
retries += 1
|
132
|
+
response = connection.post(tracking_path, body.to_json, headers)
|
133
|
+
rescue ActiveResource::ConnectionError => e
|
134
|
+
retry unless retries <= 5
|
135
|
+
raise e
|
136
|
+
end
|
126
137
|
|
127
138
|
self.format.decode(response.body)
|
128
139
|
end
|
129
140
|
end
|
130
141
|
|
131
142
|
def initialize(attributes = {}, persisted = false)
|
143
|
+
if attributes[:pickup_date].is_a?(ActiveSupport::TimeWithZone)
|
144
|
+
attributes[:pickup_date] = attributes[:pickup_date].strftime("%Y-%-m-%-d")
|
145
|
+
end
|
132
146
|
attributes = DEFAULT_ATTRS.merge(attributes)
|
133
147
|
super
|
134
148
|
set_service_id
|
135
149
|
end
|
136
150
|
|
151
|
+
def pickup_date=(date)
|
152
|
+
@attributes[:pickup_date] = if date.is_a?(ActiveSupport::TimeWithZone) || date.is_a?(Time)
|
153
|
+
date.strftime("%Y-%-m-%-d")
|
154
|
+
else
|
155
|
+
date
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
137
159
|
def get_service_id(service_category = "pickup")
|
138
160
|
# only check with services offering pickup by default
|
139
161
|
SERVICES.find do |s|
|
@@ -156,6 +178,7 @@ module JanioAPI
|
|
156
178
|
flatten_data: true,
|
157
179
|
tracking_nos: [@attributes[:tracking_no]]
|
158
180
|
}
|
181
|
+
|
159
182
|
response = connection.post(self.class.tracking_path, body.to_json, self.class.headers)
|
160
183
|
self.class.format.decode(response.body)[0]
|
161
184
|
end
|
@@ -168,22 +191,42 @@ module JanioAPI
|
|
168
191
|
|
169
192
|
private
|
170
193
|
|
194
|
+
def pickup_country_code
|
195
|
+
ISO3166::Country.find_country_by_name(pickup_country)&.alpha2
|
196
|
+
end
|
197
|
+
|
198
|
+
def consignee_country_code
|
199
|
+
ISO3166::Country.find_country_by_name(consignee_country)&.alpha2
|
200
|
+
end
|
201
|
+
|
202
|
+
def pickup_postal_valid?
|
203
|
+
if pickup_country_code
|
204
|
+
regex = Regexp.new(POSTAL_CODE_REGEX[pickup_country_code.to_sym])
|
205
|
+
errors.add(:pickup_postal, "is invalid, must match #{regex.inspect}") unless regex.match(pickup_postal)
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
def consignee_postal_valid?
|
210
|
+
if consignee_country_code && POSTAL_CODE_REGEX[consignee_country_code.to_sym]
|
211
|
+
regex = Regexp.new(POSTAL_CODE_REGEX[consignee_country_code.to_sym])
|
212
|
+
errors.add(:consignee_postal, "is invalid, must match #{regex.inspect}") unless regex.match(consignee_postal)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
171
216
|
def pickup_contact_number_country_matched?
|
172
|
-
|
173
|
-
if Phonelib.invalid_for_country? pickup_contact_number, country_code
|
217
|
+
if Phonelib.invalid_for_country?(pickup_contact_number, pickup_country_code)
|
174
218
|
errors.add(
|
175
219
|
:pickup_contact_number,
|
176
|
-
"is invalid, please make sure the phone's country code matches the pickup address's country"
|
220
|
+
"is invalid, please make sure the phone is valid and phone's country code matches the pickup address's country"
|
177
221
|
)
|
178
222
|
end
|
179
223
|
end
|
180
224
|
|
181
225
|
def consignee_number_country_matched?
|
182
|
-
|
183
|
-
if Phonelib.invalid_for_country? consignee_number, country_code
|
226
|
+
if Phonelib.invalid_for_country?(consignee_number, consignee_country_code)
|
184
227
|
errors.add(
|
185
228
|
:consignee_number,
|
186
|
-
"is invalid, please make sure the phone's country code matches the consignee address's country"
|
229
|
+
"is invalid, please make sure the phone is valid and phone's country code matches the consignee address's country"
|
187
230
|
)
|
188
231
|
end
|
189
232
|
end
|
@@ -220,21 +263,21 @@ module JanioAPI
|
|
220
263
|
def reformat_before_save(blocking)
|
221
264
|
attributes = @attributes.dup
|
222
265
|
@attributes.clear
|
223
|
-
@attributes[:secret_key] = retrieve_api_token
|
266
|
+
@attributes[:secret_key] = retrieve_api_token(attributes[:pickup_country])
|
224
267
|
# set blocking until label generated
|
225
268
|
@attributes[:blocking] = blocking
|
226
269
|
# reformat attributes
|
227
270
|
@attributes[:orders] = [attributes]
|
228
271
|
end
|
229
272
|
|
230
|
-
def retrieve_api_token
|
273
|
+
def retrieve_api_token(country)
|
231
274
|
if JanioAPI.config.api_tokens
|
232
|
-
country_code_sym = ISO3166::Country.find_country_by_name(
|
275
|
+
country_code_sym = ISO3166::Country.find_country_by_name(country)&.alpha2&.to_sym
|
233
276
|
JanioAPI.config.api_tokens[country_code_sym]
|
234
277
|
elsif JanioAPI.config.api_token
|
235
278
|
JanioAPI.config.api_token
|
236
279
|
else
|
237
|
-
|
280
|
+
raise ArgumentError, "JanioAPI api_token/api_tokens is missing, please set it in the config."
|
238
281
|
end
|
239
282
|
end
|
240
283
|
|
data/lib/janio_api/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.8
|
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-
|
11
|
+
date: 2020-07-14 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
|
data/Gemfile.lock
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
janio_api (0.3.3)
|
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
|