railsware-telesign 0.0.2
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.
- data/MIT-LICENSE +20 -0
- data/README.markdown +66 -0
- data/lib/telesign.rb +60 -0
- data/lib/telesign/api/default.rb +874 -0
- data/lib/telesign/api/defaultDriver.rb +105 -0
- data/lib/telesign/api/defaultMappingRegistry.rb +661 -0
- data/lib/telesign/api_request.rb +22 -0
- data/lib/telesign/api_response.rb +24 -0
- data/lib/telesign/call/request.rb +9 -0
- data/lib/telesign/call/response.rb +8 -0
- data/lib/telesign/lib/country.rb +474 -0
- data/lib/telesign/lib/exceptions.rb +28 -0
- data/lib/telesign/lib/language.rb +67 -0
- data/lib/telesign/lib/phone_type.rb +29 -0
- data/lib/telesign/phone.rb +11 -0
- data/lib/telesign/phone_id/request.rb +18 -0
- data/lib/telesign/phone_id/response.rb +31 -0
- data/lib/telesign/phone_verification/request.rb +25 -0
- data/lib/telesign/phone_verification/response.rb +11 -0
- data/lib/telesign/sms/request.rb +14 -0
- data/lib/telesign/sms/response.rb +7 -0
- data/lib/telesign/status/request.rb +17 -0
- data/lib/telesign/status/response.rb +36 -0
- metadata +83 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
module Telesign
|
2
|
+
class ApiRequest
|
3
|
+
|
4
|
+
mattr_accessor :customer_id, :authentication_id
|
5
|
+
|
6
|
+
alias_method :customerID, :customer_id
|
7
|
+
alias_method :authenticationID, :authentication_id
|
8
|
+
|
9
|
+
def self.request_method(method = nil)
|
10
|
+
@request_method ||= method
|
11
|
+
@request_method
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
driver.send(self.class.request_method, self)
|
16
|
+
end
|
17
|
+
|
18
|
+
def driver
|
19
|
+
Telesign::API::TelesignAPISoap.new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Telesign
|
2
|
+
class ApiResponse
|
3
|
+
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
def self.response_method(method = nil)
|
7
|
+
@response_method ||= method
|
8
|
+
@response_method
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(response)
|
12
|
+
@response = response.send(self.class.response_method)
|
13
|
+
raise_exceptions
|
14
|
+
after_initialize
|
15
|
+
end
|
16
|
+
|
17
|
+
def after_initialize
|
18
|
+
end
|
19
|
+
|
20
|
+
def raise_exceptions
|
21
|
+
Exceptions::raise_if_error(api_error)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,474 @@
|
|
1
|
+
module Telesign
|
2
|
+
module Country
|
3
|
+
|
4
|
+
class InvalidCountryName < ArgumentError; end
|
5
|
+
|
6
|
+
NAMES_TO_ALPHA2 = {
|
7
|
+
"Andorra" => "AD",
|
8
|
+
"United Arab Emirates" => "AE",
|
9
|
+
"Afghanistan" => "AF",
|
10
|
+
"Anguilla" => "AI",
|
11
|
+
"Albania" => "AL",
|
12
|
+
"Armenia" => "AM",
|
13
|
+
"Netherlands Antilles" => "AN",
|
14
|
+
"Angola" => "AO",
|
15
|
+
"Antarctica" => "AQ",
|
16
|
+
"Argentina" => "AR",
|
17
|
+
"American Samoa" => "AS",
|
18
|
+
"Austria" => "AT",
|
19
|
+
"Australia" => "AU",
|
20
|
+
"Aruba" => "AW",
|
21
|
+
"Azerbaijan" => "AZ",
|
22
|
+
"Bosnia and Herzegovina" => "BA",
|
23
|
+
"Barbados" => "BB",
|
24
|
+
"Bangladesh" => "BD",
|
25
|
+
"Belgium" => "BE",
|
26
|
+
"Burkina Faso" => "BF",
|
27
|
+
"Bulgaria" => "BG",
|
28
|
+
"Bahrain" => "BH",
|
29
|
+
"Burundi" => "BI",
|
30
|
+
"Benin" => "BJ",
|
31
|
+
"Bermuda" => "BM",
|
32
|
+
"Brunei Darussalam" => "BN",
|
33
|
+
"Bolivia" => "BO",
|
34
|
+
"Brazil" => "BR",
|
35
|
+
"Bahamas" => "BS",
|
36
|
+
"Bhutan" => "BT",
|
37
|
+
"Bouvet Island" => "BV",
|
38
|
+
"Botswana" => "BW",
|
39
|
+
"Belarus" => "BY",
|
40
|
+
"Belize" => "BZ",
|
41
|
+
"Canada" => "CA",
|
42
|
+
"Cocos (Keeling) Islands" => "CC",
|
43
|
+
"Central African Republic" => "CF",
|
44
|
+
"Congo" => "CG",
|
45
|
+
"Democratic Republic of the Congo" => "CD",
|
46
|
+
"Switzerland" => "CH",
|
47
|
+
"Cote d'Ivoire" => "CI",
|
48
|
+
"Cook Islands" => "CK",
|
49
|
+
"Chile" => "CL",
|
50
|
+
"Cameroon" => "CM",
|
51
|
+
"China" => "CN",
|
52
|
+
"Colombia" => "CO",
|
53
|
+
"Costa Rica" => "CR",
|
54
|
+
"Former Czechoslovakia" => "CS",
|
55
|
+
"Cuba" => "CU",
|
56
|
+
"Cape Verde" => "CV",
|
57
|
+
"Christmas Island" => "CX",
|
58
|
+
"Cyprus" => "CY",
|
59
|
+
"Czech Republic" => "CZ",
|
60
|
+
"Germany" => "DE",
|
61
|
+
"Djibouti" => "DJ",
|
62
|
+
"Denmark" => "DK",
|
63
|
+
"Dominica" => "DM",
|
64
|
+
"Dominican Republic" => "DO",
|
65
|
+
"Algeria" => "DZ",
|
66
|
+
"Ecuador" => "EC",
|
67
|
+
"Estonia" => "EE",
|
68
|
+
"Egypt" => "EG",
|
69
|
+
"Western Sahara" => "EH",
|
70
|
+
"Eritrea" => "ER",
|
71
|
+
"Spain" => "ES",
|
72
|
+
"Ethiopia" => "ET",
|
73
|
+
"Finland" => "FI",
|
74
|
+
"Fiji" => "FJ",
|
75
|
+
"Falkland Islands" => "FK",
|
76
|
+
"Micronesia" => "FM",
|
77
|
+
"Faroe Islands" => "FO",
|
78
|
+
"France" => "FR",
|
79
|
+
"France (European Territory)" => "FX",
|
80
|
+
"Gabon" => "GA",
|
81
|
+
"Great Britain" => "GB",
|
82
|
+
"Grenada" => "GD",
|
83
|
+
"Georgia" => "GE",
|
84
|
+
"French Guiana" => "GF",
|
85
|
+
"Ghana" => "GH",
|
86
|
+
"Gibraltar" => "GI",
|
87
|
+
"Greenland" => "GL",
|
88
|
+
"Gambia" => "GM",
|
89
|
+
"Guinea" => "GN",
|
90
|
+
"Guadeloupe" => "GP",
|
91
|
+
"Equatorial Guinea" => "GQ",
|
92
|
+
"Greece" => "GR",
|
93
|
+
"S. Georgia & S. Sandwich Isls." => "GS",
|
94
|
+
"Guatemala" => "GT",
|
95
|
+
"Guam (USA)" => "GU",
|
96
|
+
"Guinea Bissau" => "GW",
|
97
|
+
"Guyana" => "GY",
|
98
|
+
"Hong Kong" => "HK",
|
99
|
+
"Heard and McDonald Islands" => "HM",
|
100
|
+
"Honduras" => "HN",
|
101
|
+
"Croatia" => "HR",
|
102
|
+
"Haiti" => "HT",
|
103
|
+
"Hungary" => "HU",
|
104
|
+
"Indonesia" => "ID",
|
105
|
+
"Ireland" => "IE",
|
106
|
+
"Israel" => "IL",
|
107
|
+
"India" => "IN",
|
108
|
+
"British Indian Ocean Territory" => "IO",
|
109
|
+
"Iraq" => "IQ",
|
110
|
+
"Iran" => "IR",
|
111
|
+
"Iceland" => "IS",
|
112
|
+
"Italy" => "IT",
|
113
|
+
"Jamaica" => "JM",
|
114
|
+
"Jordan" => "JO",
|
115
|
+
"Japan" => "JP",
|
116
|
+
"Kenya" => "KE",
|
117
|
+
"Kyrgyzstan" => "KG",
|
118
|
+
"Cambodia" => "KH",
|
119
|
+
"Kiribati" => "KI",
|
120
|
+
"Comoros" => "KM",
|
121
|
+
"Saint Kitts & Nevis Anguilla" => "KN",
|
122
|
+
"North Korea" => "KP",
|
123
|
+
"South Korea" => "KR",
|
124
|
+
"Kuwait" => "KW",
|
125
|
+
"Cayman Islands" => "KY",
|
126
|
+
"Kazakhstan" => "KZ",
|
127
|
+
"Laos" => "LA",
|
128
|
+
"Lebanon" => "LB",
|
129
|
+
"Saint Lucia" => "LC",
|
130
|
+
"Liechtenstein" => "LI",
|
131
|
+
"Sri Lanka" => "LK",
|
132
|
+
"Liberia" => "LR",
|
133
|
+
"Lesotho" => "LS",
|
134
|
+
"Lithuania" => "LT",
|
135
|
+
"Luxembourg" => "LU",
|
136
|
+
"Latvia" => "LV",
|
137
|
+
"Libya" => "LY",
|
138
|
+
"Morocco" => "MA",
|
139
|
+
"Monaco" => "MC",
|
140
|
+
"Moldova" => "MD",
|
141
|
+
"Madagascar" => "MG",
|
142
|
+
"Marshall Islands" => "MH",
|
143
|
+
"Macedonia" => "MK",
|
144
|
+
"Mali" => "ML",
|
145
|
+
"Myanmar" => "MM",
|
146
|
+
"Mongolia" => "MN",
|
147
|
+
"Macau" => "MO",
|
148
|
+
"Northern Mariana Islands" => "MP",
|
149
|
+
"Martinique" => "MQ",
|
150
|
+
"Mauritania" => "MR",
|
151
|
+
"Montserrat" => "MS",
|
152
|
+
"Malta" => "MT",
|
153
|
+
"Mauritius" => "MU",
|
154
|
+
"Maldives" => "MV",
|
155
|
+
"Malawi" => "MW",
|
156
|
+
"Mexico" => "MX",
|
157
|
+
"Malaysia" => "MY",
|
158
|
+
"Mozambique" => "MZ",
|
159
|
+
"Namibia" => "NA",
|
160
|
+
"New Caledonia" => "NC",
|
161
|
+
"Niger" => "NE",
|
162
|
+
"Norfolk Island" => "NF",
|
163
|
+
"Nigeria" => "NG",
|
164
|
+
"Nicaragua" => "NI",
|
165
|
+
"Netherlands" => "NL",
|
166
|
+
"Norway" => "NO",
|
167
|
+
"Nepal" => "NP",
|
168
|
+
"Nauru" => "NR",
|
169
|
+
"Neutral Zone" => "NT",
|
170
|
+
"Niue" => "NU",
|
171
|
+
"New Zealand" => "NZ",
|
172
|
+
"Oman" => "OM",
|
173
|
+
"Panama" => "PA",
|
174
|
+
"Peru" => "PE",
|
175
|
+
"French Polynesia" => "PF",
|
176
|
+
"Papua New Guinea" => "PG",
|
177
|
+
"Philippines" => "PH",
|
178
|
+
"Pakistan" => "PK",
|
179
|
+
"Poland" => "PL",
|
180
|
+
"St. Pierre and Miquelon" => "PM",
|
181
|
+
"Pitcairn Island" => "PN",
|
182
|
+
"Portugal" => "PT",
|
183
|
+
"Palau" => "PW",
|
184
|
+
"Paraguay" => "PY",
|
185
|
+
"Qatar" => "QA",
|
186
|
+
"Reunion" => "RE",
|
187
|
+
"Romania" => "RO",
|
188
|
+
"Russia" => "RU",
|
189
|
+
"Rwanda" => "RW",
|
190
|
+
"Saudi Arabia" => "SA",
|
191
|
+
"Solomon Islands" => "SB",
|
192
|
+
"Serbia and Montenegro" => "RS",
|
193
|
+
"Seychelles" => "SC",
|
194
|
+
"Sudan" => "SD",
|
195
|
+
"Sweden" => "SE",
|
196
|
+
"Singapore" => "SG",
|
197
|
+
"St. Helena" => "SH",
|
198
|
+
"Slovenia" => "SI",
|
199
|
+
"Svalbard and Jan Mayen Islands" => "SJ",
|
200
|
+
"Slovakia" => "SK",
|
201
|
+
"Sierra Leone" => "SL",
|
202
|
+
"San Marino" => "SM",
|
203
|
+
"Senegal" => "SN",
|
204
|
+
"Somalia" => "SO",
|
205
|
+
"Suriname" => "SR",
|
206
|
+
"Sao Tome and Principe" => "ST",
|
207
|
+
"Former USSR" => "SU",
|
208
|
+
"El Salvador" => "SV",
|
209
|
+
"Syria" => "SY",
|
210
|
+
"Swaziland" => "SZ",
|
211
|
+
"Turks and Caicos Islands" => "TC",
|
212
|
+
"Chad" => "TD",
|
213
|
+
"French Southern Territories" => "TF",
|
214
|
+
"Togo" => "TG",
|
215
|
+
"Thailand" => "TH",
|
216
|
+
"Tajikistan" => "TJ",
|
217
|
+
"Tokelau" => "TK",
|
218
|
+
"Turkmenistan" => "TM",
|
219
|
+
"Tunisia" => "TN",
|
220
|
+
"Tonga" => "TO",
|
221
|
+
"East Timor" => "TP",
|
222
|
+
"Turkey" => "TR",
|
223
|
+
"Trinidad and Tobago" => "TT",
|
224
|
+
"Tuvalu" => "TV",
|
225
|
+
"Taiwan" => "TW",
|
226
|
+
"Tanzania" => "TZ",
|
227
|
+
"Ukraine" => "UA",
|
228
|
+
"Uganda" => "UG",
|
229
|
+
"United Kingdom" => "UK",
|
230
|
+
"United States" => "US",
|
231
|
+
"Uruguay" => "UY",
|
232
|
+
"Uzbekistan" => "UZ",
|
233
|
+
"Vatican" => "VA",
|
234
|
+
"Saint Vincent & Grenadines" => "VC",
|
235
|
+
"Venezuela" => "VE",
|
236
|
+
"Virgin Islands (British)" => "VG",
|
237
|
+
"Virgin Islands (USA)" => "VI",
|
238
|
+
"Vietnam" => "VN",
|
239
|
+
"Vanuatu" => "VU",
|
240
|
+
"Wallis and Futuna Islands" => "WF",
|
241
|
+
"Samoa" => "WS",
|
242
|
+
"Yemen" => "YE",
|
243
|
+
"Mayotte" => "YT",
|
244
|
+
"Yugoslavia" => "YU",
|
245
|
+
"South Africa" => "ZA",
|
246
|
+
"Zambia" => "ZM",
|
247
|
+
"Zaire" => "ZR",
|
248
|
+
"Zimbabwe" => "ZW"
|
249
|
+
}
|
250
|
+
|
251
|
+
ALPHA2_TO_CODE = {
|
252
|
+
"AD" => 376,
|
253
|
+
"AE" => 971,
|
254
|
+
"AF" => 93,
|
255
|
+
"AL" => 355,
|
256
|
+
"AM" => 374,
|
257
|
+
"AN" => 599,
|
258
|
+
"AO" => 244,
|
259
|
+
"AR" => 54,
|
260
|
+
"AT" => 43,
|
261
|
+
"AU" => 61,
|
262
|
+
"AW" => 297,
|
263
|
+
"AZ" => 994,
|
264
|
+
"BA" => 387,
|
265
|
+
"BD" => 880,
|
266
|
+
"BE" => 32,
|
267
|
+
"BF" => 226,
|
268
|
+
"BG" => 359,
|
269
|
+
"BH" => 973,
|
270
|
+
"BI" => 257,
|
271
|
+
"BJ" => 229,
|
272
|
+
"BN" => 673,
|
273
|
+
"BO" => 591,
|
274
|
+
"BR" => 55,
|
275
|
+
"BT" => 975,
|
276
|
+
"BW" => 267,
|
277
|
+
"BY" => 375,
|
278
|
+
"BZ" => 501,
|
279
|
+
"CA" => 1,
|
280
|
+
"CD" => 243,
|
281
|
+
"CF" => 236,
|
282
|
+
"CG" => 242,
|
283
|
+
"CH" => 41,
|
284
|
+
"CI" => 225,
|
285
|
+
"CK" => 682,
|
286
|
+
"CL" => 56,
|
287
|
+
"CM" => 237,
|
288
|
+
"CN" => 86,
|
289
|
+
"CO" => 57,
|
290
|
+
"CR" => 506,
|
291
|
+
"CU" => 53,
|
292
|
+
"CV" => 238,
|
293
|
+
"CY" => 357,
|
294
|
+
"CZ" => 420,
|
295
|
+
"DE" => 49,
|
296
|
+
"DJ" => 253,
|
297
|
+
"DK" => 45,
|
298
|
+
"DO" => 1,
|
299
|
+
"DZ" => 213,
|
300
|
+
"EC" => 593,
|
301
|
+
"EE" => 372,
|
302
|
+
"EG" => 20,
|
303
|
+
"ER" => 291,
|
304
|
+
"ES" => 34,
|
305
|
+
"ET" => 251,
|
306
|
+
"FI" => 358,
|
307
|
+
"FJ" => 679,
|
308
|
+
"FK" => 500,
|
309
|
+
"FM" => 691,
|
310
|
+
"FO" => 298,
|
311
|
+
"FR" => 33,
|
312
|
+
"GA" => 241,
|
313
|
+
"GB" => 44,
|
314
|
+
"GD" => 473,
|
315
|
+
"GE" => 995,
|
316
|
+
"GF" => 594,
|
317
|
+
"GH" => 233,
|
318
|
+
"GI" => 350,
|
319
|
+
"GL" => 299,
|
320
|
+
"GM" => 220,
|
321
|
+
"GN" => 224,
|
322
|
+
"GP" => 590,
|
323
|
+
"GQ" => 240,
|
324
|
+
"GR" => 30,
|
325
|
+
"GT" => 502,
|
326
|
+
"GW" => 245,
|
327
|
+
"GY" => 592,
|
328
|
+
"HK" => 852,
|
329
|
+
"HN" => 504,
|
330
|
+
"HR" => 385,
|
331
|
+
"HT" => 509,
|
332
|
+
"HU" => 36,
|
333
|
+
"ID" => 62,
|
334
|
+
"IE" => 353,
|
335
|
+
"IL" => 972,
|
336
|
+
"IN" => 91,
|
337
|
+
"IQ" => 964,
|
338
|
+
"IR" => 98,
|
339
|
+
"IS" => 354,
|
340
|
+
"IT" => 39,
|
341
|
+
"JM" => 876,
|
342
|
+
"JO" => 962,
|
343
|
+
"JP" => 81,
|
344
|
+
"KE" => 254,
|
345
|
+
"KG" => 996,
|
346
|
+
"KH" => 855,
|
347
|
+
"KI" => 686,
|
348
|
+
"KM" => 269,
|
349
|
+
"KP" => 850,
|
350
|
+
"KR" => 82,
|
351
|
+
"KW" => 965,
|
352
|
+
"KZ" => 7,
|
353
|
+
"LA" => 856,
|
354
|
+
"LB" => 961,
|
355
|
+
"LI" => 423,
|
356
|
+
"LK" => 94,
|
357
|
+
"LR" => 231,
|
358
|
+
"LS" => 266,
|
359
|
+
"LT" => 370,
|
360
|
+
"LU" => 352,
|
361
|
+
"LV" => 371,
|
362
|
+
"LY" => 218,
|
363
|
+
"MA" => 212,
|
364
|
+
"MC" => 377,
|
365
|
+
"MD" => 373,
|
366
|
+
"MG" => 261,
|
367
|
+
"MH" => 692,
|
368
|
+
"MK" => 389,
|
369
|
+
"ML" => 223,
|
370
|
+
"MM" => 95,
|
371
|
+
"MN" => 976,
|
372
|
+
"MO" => 853,
|
373
|
+
"MQ" => 596,
|
374
|
+
"MR" => 222,
|
375
|
+
"MT" => 356,
|
376
|
+
"MU" => 230,
|
377
|
+
"MV" => 960,
|
378
|
+
"MW" => 265,
|
379
|
+
"MX" => 52,
|
380
|
+
"MY" => 60,
|
381
|
+
"MZ" => 258,
|
382
|
+
"NA" => 264,
|
383
|
+
"NC" => 687,
|
384
|
+
"NE" => 227,
|
385
|
+
"NG" => 234,
|
386
|
+
"NI" => 505,
|
387
|
+
"NL" => 31,
|
388
|
+
"NO" => 47,
|
389
|
+
"NP" => 977,
|
390
|
+
"NR" => 674,
|
391
|
+
"NU" => 683,
|
392
|
+
"NZ" => 64,
|
393
|
+
"OM" => 968,
|
394
|
+
"PA" => 507,
|
395
|
+
"PE" => 51,
|
396
|
+
"PF" => 689,
|
397
|
+
"PG" => 675,
|
398
|
+
"PH" => 63,
|
399
|
+
"PK" => 92,
|
400
|
+
"PL" => 48,
|
401
|
+
"PM" => 508,
|
402
|
+
"PR" => 1,
|
403
|
+
"PT" => 351,
|
404
|
+
"PW" => 680,
|
405
|
+
"PY" => 595,
|
406
|
+
"QA" => 974,
|
407
|
+
"RE" => 262,
|
408
|
+
"RO" => 40,
|
409
|
+
"RS" => 381,
|
410
|
+
"RU" => 7,
|
411
|
+
"RW" => 250,
|
412
|
+
"SA" => 966,
|
413
|
+
"SB" => 677,
|
414
|
+
"SC" => 248,
|
415
|
+
"SD" => 249,
|
416
|
+
"SE" => 46,
|
417
|
+
"SG" => 65,
|
418
|
+
"SH" => 290,
|
419
|
+
"SI" => 386,
|
420
|
+
"SK" => 421,
|
421
|
+
"SL" => 232,
|
422
|
+
"SM" => 378,
|
423
|
+
"SN" => 221,
|
424
|
+
"SO" => 252,
|
425
|
+
"SR" => 597,
|
426
|
+
"ST" => 239,
|
427
|
+
"SV" => 503,
|
428
|
+
"SY" => 963,
|
429
|
+
"SZ" => 268,
|
430
|
+
"TD" => 235,
|
431
|
+
"TG" => 228,
|
432
|
+
"TH" => 66,
|
433
|
+
"TJ" => 992,
|
434
|
+
"TK" => 690,
|
435
|
+
"TM" => 993,
|
436
|
+
"TN" => 216,
|
437
|
+
"TO" => 676,
|
438
|
+
"TP" => 670,
|
439
|
+
"TR" => 90,
|
440
|
+
"TV" => 688,
|
441
|
+
"TW" => 886,
|
442
|
+
"TZ" => 255,
|
443
|
+
"UA" => 380,
|
444
|
+
"UG" => 256,
|
445
|
+
"UK" => 44,
|
446
|
+
"US" => 1,
|
447
|
+
"UY" => 598,
|
448
|
+
"UZ" => 998,
|
449
|
+
"VA" => 379,
|
450
|
+
"VE" => 58,
|
451
|
+
"VN" => 84,
|
452
|
+
"VU" => 678,
|
453
|
+
"WF" => 681,
|
454
|
+
"WS" => 685,
|
455
|
+
"YE" => 967,
|
456
|
+
"YT" => 269,
|
457
|
+
"YU" => 381,
|
458
|
+
"ZA" => 27,
|
459
|
+
"ZM" => 260,
|
460
|
+
"ZW" => 263
|
461
|
+
}
|
462
|
+
|
463
|
+
def self.country_code_for_name(name)
|
464
|
+
return name.to_i if name =~ /^\d+$/ && ALPHA2_TO_CODE.values.include?(name.to_i)
|
465
|
+
|
466
|
+
alpha2 = name =~ /^\w{2}$/ ?
|
467
|
+
name :
|
468
|
+
NAMES_TO_ALPHA2[name]
|
469
|
+
|
470
|
+
code = ALPHA2_TO_CODE[alpha2] if alpha2
|
471
|
+
code || raise(InvalidCountryName.new("Could not locate country code for name: #{name}"))
|
472
|
+
end
|
473
|
+
end
|
474
|
+
end
|