mobile-subscriber 1.0.0.alpha4 → 1.0.0.alpha5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mobile-subscriber.rb +13 -3
  3. data/lib/mobile_subscriber/dictionaries/dialing_and_country_codes.rb +468 -28
  4. data/lib/mobile_subscriber/http/known_imsi_headers.rb +22 -0
  5. data/lib/mobile_subscriber/http/known_msisdn_headers.rb +68 -0
  6. data/lib/mobile_subscriber/http/request_info.rb +166 -0
  7. data/lib/mobile_subscriber/identity.rb +97 -1
  8. data/lib/mobile_subscriber/version.rb +1 -1
  9. data/mobile_subscriber.thor +41 -0
  10. data/spec/factories/mobile_requests.rb +28 -0
  11. data/spec/factories/mobile_requests_from_claro.rb +257 -0
  12. data/spec/factories/mobile_requests_from_iusacell.rb +13 -0
  13. data/spec/factories/mobile_requests_from_movistar.rb +15 -0
  14. data/spec/factories/mobile_requests_from_telcel.rb +14 -0
  15. data/spec/factories/mobile_requests_from_vivo.rb +13 -0
  16. data/spec/features/claro_user_detection_spec.rb +170 -0
  17. data/spec/features/iusacell_user_detection_spec.rb +19 -0
  18. data/spec/features/movistar_user_detection_spec.rb +19 -0
  19. data/spec/features/telcel_user_detection_spec.rb +19 -0
  20. data/spec/models/{isdn_spec.rb → identity_spec.rb} +5 -5
  21. data/spec/shared_examples/identity_detection_in_argentina.rb +11 -0
  22. data/spec/shared_examples/identity_detection_in_brazil.rb +12 -0
  23. data/spec/shared_examples/identity_detection_in_chile.rb +12 -0
  24. data/spec/shared_examples/identity_detection_in_colombia.rb +12 -0
  25. data/spec/shared_examples/identity_detection_in_costa_rica.rb +15 -0
  26. data/spec/shared_examples/identity_detection_in_dominican_republic.rb +12 -0
  27. data/spec/shared_examples/identity_detection_in_ecuador.rb +12 -0
  28. data/spec/shared_examples/identity_detection_in_el_salvador.rb +15 -0
  29. data/spec/shared_examples/identity_detection_in_guatemala.rb +15 -0
  30. data/spec/shared_examples/identity_detection_in_honduras.rb +11 -0
  31. data/spec/shared_examples/identity_detection_in_mexico.rb +11 -0
  32. data/spec/shared_examples/identity_detection_in_nicaragua.rb +12 -0
  33. data/spec/shared_examples/identity_detection_in_panama.rb +12 -0
  34. data/spec/shared_examples/identity_detection_in_peru.rb +12 -0
  35. data/spec/shared_examples/identity_detection_in_puerto_rico.rb +14 -0
  36. data/spec/shared_examples/of_msisdn_detection_from_http_request.rb +3 -188
  37. data/templates/dialing_and_country_codes.rb.erb +20 -0
  38. metadata +58 -28
  39. data/lib/mobile_subscriber/detection/from_msisdn_http_request_header.rb +0 -48
  40. data/lib/mobile_subscriber/detection/from_x_nokia_msisdn_http_request_header.rb +0 -58
  41. data/lib/mobile_subscriber/detection/from_x_up_calling_line_id_http_request_header.rb +0 -65
  42. data/lib/mobile_subscriber/detection/from_x_up_ch_msisdn_http_request_header.rb +0 -35
  43. data/lib/mobile_subscriber/detection/from_x_up_subno_http_request_header.rb +0 -44
  44. data/lib/mobile_subscriber/detection/from_x_wap_msisdn_http_request_header.rb +0 -37
  45. data/lib/mobile_subscriber/detection/from_x_wap_sesiones3g_mdn_http_request_header.rb +0 -39
  46. data/lib/mobile_subscriber/detection/from_x_ztgo_beareraddress_http_request_header.rb +0 -36
  47. data/lib/mobile_subscriber/detection/http_request_info.rb +0 -77
  48. data/lib/mobile_subscriber/isdn.rb +0 -89
  49. data/spec/detection/from_msisdn_http_request_header_spec.rb +0 -53
  50. data/spec/detection/from_x_nokia_msisdn_http_request_header_spec.rb +0 -99
  51. data/spec/detection/from_x_up_calling_line_id_http_request_header_spec.rb +0 -39
  52. data/spec/detection/from_x_up_subno_http_request_header_spec.rb +0 -43
  53. data/spec/detection/from_x_wap_msisdn_http_request_header_spec.rb +0 -32
  54. data/spec/detection/from_x_wap_sesiones3g_mdn_http_request_header_spec.rb +0 -29
  55. data/spec/factories/requests.rb +0 -229
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 824221695c48e812f55c982abdc9e4ede9333818
4
- data.tar.gz: 6339fc5ab174bf1197ff5946001a0c80583a13e7
3
+ metadata.gz: 762356966c9fe3a51b9189099d1a77cdf2dc8cf2
4
+ data.tar.gz: b83b4a4ff19ff13732e0488393611e4ec219c076
5
5
  SHA512:
6
- metadata.gz: 0fa3e242b91af01570b39bd5e26322b57f1037b488330f8f66026a1f04319cb69c96c5e6a90a140acff28c90784f758e0124083b25ecbc14682b1883fdb64647
7
- data.tar.gz: 2ae1fb0491f13732cfbf5da8198a37483f9bf32d6801831b7a3bcfa7928d43c33b4d06d44b0366e19aaf9cbdc69f7cad2102ced08c306d3641203de13921de2e
6
+ metadata.gz: ffafcf7d64b4051d2db1a1a2c4acd52c7c940847f40fdaf54636420fe4e564311388e72f3028763609c85ae5fae8d10ba0626b9ecdb2bdf007e0a97ea7c9d6f5
7
+ data.tar.gz: 8a5914e8cba72506eb8efa6ea945afd06a53cdb4b66a191b0dd5e6de138ba827098266e7fa3178c0a85a57ae0ed45245fe95c926dbcd601a1a46b4c2abe06d0f
@@ -4,9 +4,14 @@ require 'active_support/all'
4
4
  module MobileSubscriber
5
5
  extend ActiveSupport::Autoload
6
6
 
7
- autoload :ISDN, "mobile_subscriber/isdn.rb"
7
+ autoload :Identity
8
8
 
9
- module Detection
9
+ module HTTP
10
+ extend ActiveSupport::Autoload
11
+ autoload :RequestInfo
12
+ end
13
+
14
+ module MSISDNExtraction
10
15
  extend ActiveSupport::Autoload
11
16
  autoload :FromMsisdnHttpRequestHeader
12
17
  autoload :FromXNokiaMsisdnHttpRequestHeader
@@ -16,6 +21,11 @@ module MobileSubscriber
16
21
  autoload :FromXWapMsisdnHttpRequestHeader
17
22
  autoload :FromXWapSesiones3gMdnHttpRequestHeader
18
23
  autoload :FromXZtgoBeareraddressHttpRequestHeader
19
- autoload :HttpRequestInfo
24
+ end
25
+
26
+ module IMSIExtraction
27
+ extend ActiveSupport::Autoload
28
+ autoload :FromXImsiHttpRequestHeader
29
+ autoload :FromXNokiaImsiHttpRequestHeader
20
30
  end
21
31
  end
@@ -1,36 +1,476 @@
1
1
  module MobileSubscriber
2
- # See: http://countrycode.org/
3
- # Diccionario de Dialing Country Codes => ISO country codes:
2
+
3
+ # Country Dialing => ISO codes:
4
4
  DIALING_COUNTRY_CODES = {
5
- # WTF???
6
- '1' => 'PR', # Puerto Rico "1" country code...
7
5
 
8
- # Caribbean Islands' country codes are a mess!
6
+ # Codes collected from http://countrycode.org
7
+
8
+ '93' => 'AF', # Afghanistan
9
+
10
+ '355' => 'AL', # Albania
11
+
12
+ '213' => 'DZ', # Algeria
13
+
14
+ '1684' => 'AS', # American Samoa
15
+
16
+ '376' => 'AD', # Andorra
17
+
18
+ '244' => 'AO', # Angola
19
+
20
+ '1264' => 'AI', # Anguilla
21
+
22
+ '672' => 'AQ', # Antarctica
23
+
24
+ '1268' => 'AG', # Antigua and Barbuda
25
+
26
+ '54' => 'AR', # Argentina
27
+
28
+ '374' => 'AM', # Armenia
29
+
30
+ '297' => 'AW', # Aruba
31
+
32
+ '61' => 'AU', # Australia
33
+
34
+ '43' => 'AT', # Austria
35
+
36
+ '994' => 'AZ', # Azerbaijan
37
+
38
+ '1242' => 'BS', # Bahamas
39
+
40
+ '973' => 'BH', # Bahrain
41
+
42
+ '880' => 'BD', # Bangladesh
43
+
44
+ '1246' => 'BB', # Barbados
45
+
46
+ '375' => 'BY', # Belarus
47
+
48
+ '32' => 'BE', # Belgium
49
+
50
+ '501' => 'BZ', # Belize
51
+
52
+ '229' => 'BJ', # Benin
53
+
54
+ '1441' => 'BM', # Bermuda
55
+
56
+ '975' => 'BT', # Bhutan
57
+
58
+ '591' => 'BO', # Bolivia
59
+
60
+ '387' => 'BA', # Bosnia and Herzegovina
61
+
62
+ '267' => 'BW', # Botswana
63
+
64
+ '55' => 'BR', # Brazil
65
+
66
+ '1284' => 'VG', # British Virgin Islands
67
+
68
+ '673' => 'BN', # Brunei
69
+
70
+ '359' => 'BG', # Bulgaria
71
+
72
+ '226' => 'BF', # Burkina Faso
73
+
74
+ '95' => 'MM', # Burma (Myanmar)
75
+
76
+ '257' => 'BI', # Burundi
77
+
78
+ '855' => 'KH', # Cambodia
79
+
80
+ '237' => 'CM', # Cameroon
81
+
82
+ '1' => 'CA', # Canada
83
+
84
+ '238' => 'CV', # Cape Verde
85
+
86
+ '1345' => 'KY', # Cayman Islands
87
+
88
+ '236' => 'CF', # Central African Republic
89
+
90
+ '235' => 'TD', # Chad
91
+
92
+ '56' => 'CL', # Chile
93
+
94
+ '86' => 'CN', # China
95
+
96
+ '61' => 'CX', # Christmas Island
97
+
98
+ '61' => 'CC', # Cocos (Keeling) Islands
99
+
100
+ '57' => 'CO', # Colombia
101
+
102
+ '269' => 'KM', # Comoros
103
+
104
+ '242' => 'CG', # Republic of the Congo
105
+
106
+ '243' => 'CD', # Democratic Republic of the Congo
107
+
108
+ '682' => 'CK', # Cook Islands
109
+
110
+ '506' => 'CR', # Costa Rica
111
+
112
+ '385' => 'HR', # Croatia
113
+
114
+ '53' => 'CU', # Cuba
115
+
116
+ '357' => 'CY', # Cyprus
117
+
118
+ '420' => 'CZ', # Czech Republic
119
+
120
+ '45' => 'DK', # Denmark
121
+
122
+ '253' => 'DJ', # Djibouti
123
+
124
+ '1767' => 'DM', # Dominica
125
+
9
126
  '1809' => 'DO', # Dominican Republic
127
+
128
+ '670' => 'TL', # Timor-Leste
129
+
130
+ '593' => 'EC', # Ecuador
131
+
132
+ '20' => 'EG', # Egypt
133
+
134
+ '503' => 'SV', # El Salvador
135
+
136
+ '240' => 'GQ', # Equatorial Guinea
137
+
138
+ '291' => 'ER', # Eritrea
139
+
140
+ '372' => 'EE', # Estonia
141
+
142
+ '251' => 'ET', # Ethiopia
143
+
144
+ '500' => 'FK', # Falkland Islands
145
+
146
+ '298' => 'FO', # Faroe Islands
147
+
148
+ '679' => 'FJ', # Fiji
149
+
150
+ '358' => 'FI', # Finland
151
+
152
+ '33' => 'FR', # France
153
+
154
+ '689' => 'PF', # French Polynesia
155
+
156
+ '241' => 'GA', # Gabon
157
+
158
+ '220' => 'GM', # Gambia
159
+
160
+ '995' => 'GE', # Georgia
161
+
162
+ '49' => 'DE', # Germany
163
+
164
+ '233' => 'GH', # Ghana
165
+
166
+ '350' => 'GI', # Gibraltar
167
+
168
+ '30' => 'GR', # Greece
169
+
170
+ '299' => 'GL', # Greenland
171
+
172
+ '1473' => 'GD', # Grenada
173
+
174
+ '1671' => 'GU', # Guam
175
+
176
+ '502' => 'GT', # Guatemala
177
+
178
+ '224' => 'GN', # Guinea
179
+
180
+ '245' => 'GW', # Guinea-Bissau
181
+
182
+ '592' => 'GY', # Guyana
183
+
184
+ '509' => 'HT', # Haiti
185
+
186
+ '504' => 'HN', # Honduras
187
+
188
+ '852' => 'HK', # Hong Kong
189
+
190
+ '36' => 'HU', # Hungary
191
+
192
+ '354' => 'IS', # Iceland
193
+
194
+ '91' => 'IN', # India
195
+
196
+ '62' => 'ID', # Indonesia
197
+
198
+ '98' => 'IR', # Iran
199
+
200
+ '964' => 'IQ', # Iraq
201
+
202
+ '353' => 'IE', # Ireland
203
+
204
+ '44' => 'IM', # Isle of Man
205
+
206
+ '972' => 'IL', # Israel
207
+
208
+ '39' => 'IT', # Italy
209
+
210
+ '225' => 'CI', # Ivory Coast
211
+
212
+ '1876' => 'JM', # Jamaica
213
+
214
+ '81' => 'JP', # Japan
215
+
216
+ '962' => 'JO', # Jordan
217
+
218
+ '7' => 'KZ', # Kazakhstan
219
+
220
+ '254' => 'KE', # Kenya
221
+
222
+ '686' => 'KI', # Kiribati
223
+
224
+ '965' => 'KW', # Kuwait
225
+
226
+ '996' => 'KG', # Kyrgyzstan
227
+
228
+ '856' => 'LA', # Laos
229
+
230
+ '371' => 'LV', # Latvia
231
+
232
+ '961' => 'LB', # Lebanon
233
+
234
+ '266' => 'LS', # Lesotho
235
+
236
+ '231' => 'LR', # Liberia
237
+
238
+ '218' => 'LY', # Libya
239
+
240
+ '423' => 'LI', # Liechtenstein
241
+
242
+ '370' => 'LT', # Lithuania
243
+
244
+ '352' => 'LU', # Luxembourg
245
+
246
+ '853' => 'MO', # Macau
247
+
248
+ '389' => 'MK', # Macedonia
249
+
250
+ '261' => 'MG', # Madagascar
251
+
252
+ '265' => 'MW', # Malawi
253
+
254
+ '60' => 'MY', # Malaysia
255
+
256
+ '960' => 'MV', # Maldives
257
+
258
+ '223' => 'ML', # Mali
259
+
260
+ '356' => 'MT', # Malta
261
+
262
+ '692' => 'MH', # Marshall Islands
263
+
264
+ '222' => 'MR', # Mauritania
265
+
266
+ '230' => 'MU', # Mauritius
267
+
268
+ '262' => 'YT', # Mayotte
269
+
270
+ '52' => 'MX', # Mexico
271
+
272
+ '691' => 'FM', # Micronesia
273
+
274
+ '373' => 'MD', # Moldova
275
+
276
+ '377' => 'MC', # Monaco
277
+
278
+ '976' => 'MN', # Mongolia
279
+
280
+ '382' => 'ME', # Montenegro
281
+
282
+ '1664' => 'MS', # Montserrat
283
+
284
+ '212' => 'MA', # Morocco
285
+
286
+ '258' => 'MZ', # Mozambique
287
+
288
+ '264' => 'NA', # Namibia
289
+
290
+ '674' => 'NR', # Nauru
291
+
292
+ '977' => 'NP', # Nepal
293
+
294
+ '31' => 'NL', # Netherlands
295
+
296
+ '599' => 'AN', # Netherlands Antilles
297
+
298
+ '687' => 'NC', # New Caledonia
299
+
300
+ '64' => 'NZ', # New Zealand
301
+
302
+ '505' => 'NI', # Nicaragua
303
+
304
+ '227' => 'NE', # Niger
305
+
306
+ '234' => 'NG', # Nigeria
307
+
308
+ '683' => 'NU', # Niue
309
+
310
+ '1670' => 'MP', # Northern Mariana Islands
311
+
312
+ '850' => 'KP', # North Korea
313
+
314
+ '47' => 'NO', # Norway
315
+
316
+ '968' => 'OM', # Oman
317
+
318
+ '92' => 'PK', # Pakistan
319
+
320
+ '680' => 'PW', # Palau
321
+
322
+ '507' => 'PA', # Panama
323
+
324
+ '675' => 'PG', # Papua New Guinea
325
+
326
+ '595' => 'PY', # Paraguay
327
+
328
+ '51' => 'PE', # Peru
329
+
330
+ '63' => 'PH', # Philippines
331
+
332
+ '870' => 'PN', # Pitcairn Islands
333
+
334
+ '48' => 'PL', # Poland
335
+
336
+ '351' => 'PT', # Portugal
337
+
338
+ '1' => 'PR', # Puerto Rico
339
+
340
+ '974' => 'QA', # Qatar
341
+
342
+ '40' => 'RO', # Romania
343
+
344
+ '7' => 'RU', # Russia
345
+
346
+ '250' => 'RW', # Rwanda
347
+
348
+ '590' => 'BL', # Saint Barthelemy
349
+
350
+ '685' => 'WS', # Samoa
351
+
352
+ '378' => 'SM', # San Marino
353
+
354
+ '239' => 'ST', # Sao Tome and Principe
355
+
356
+ '966' => 'SA', # Saudi Arabia
357
+
358
+ '221' => 'SN', # Senegal
359
+
360
+ '381' => 'RS', # Serbia
361
+
362
+ '248' => 'SC', # Seychelles
363
+
364
+ '232' => 'SL', # Sierra Leone
365
+
366
+ '65' => 'SG', # Singapore
367
+
368
+ '421' => 'SK', # Slovakia
369
+
370
+ '386' => 'SI', # Slovenia
371
+
372
+ '677' => 'SB', # Solomon Islands
373
+
374
+ '252' => 'SO', # Somalia
375
+
376
+ '27' => 'ZA', # South Africa
377
+
378
+ '82' => 'KR', # South Korea
379
+
380
+ '34' => 'ES', # Spain
381
+
382
+ '94' => 'LK', # Sri Lanka
383
+
384
+ '290' => 'SH', # Saint Helena
385
+
386
+ '1869' => 'KN', # Saint Kitts and Nevis
387
+
388
+ '1758' => 'LC', # Saint Lucia
389
+
390
+ '1599' => 'MF', # Saint Martin
391
+
392
+ '508' => 'PM', # Saint Pierre and Miquelon
393
+
394
+ '1784' => 'VC', # Saint Vincent and the Grenadines
395
+
396
+ '249' => 'SD', # Sudan
397
+
398
+ '597' => 'SR', # Suriname
399
+
400
+ '268' => 'SZ', # Swaziland
401
+
402
+ '46' => 'SE', # Sweden
403
+
404
+ '41' => 'CH', # Switzerland
405
+
406
+ '963' => 'SY', # Syria
407
+
408
+ '886' => 'TW', # Taiwan
409
+
410
+ '992' => 'TJ', # Tajikistan
411
+
412
+ '255' => 'TZ', # Tanzania
413
+
414
+ '66' => 'TH', # Thailand
415
+
416
+ '228' => 'TG', # Togo
417
+
418
+ '690' => 'TK', # Tokelau
419
+
420
+ '676' => 'TO', # Tonga
421
+
422
+ '1868' => 'TT', # Trinidad and Tobago
423
+
424
+ '216' => 'TN', # Tunisia
425
+
426
+ '90' => 'TR', # Turkey
427
+
428
+ '993' => 'TM', # Turkmenistan
429
+
430
+ '1649' => 'TC', # Turks and Caicos Islands
431
+
432
+ '688' => 'TV', # Tuvalu
433
+
434
+ '971' => 'AE', # United Arab Emirates
435
+
436
+ '256' => 'UG', # Uganda
437
+
438
+ '44' => 'GB', # United Kingdom
439
+
440
+ '380' => 'UA', # Ukraine
441
+
442
+ '598' => 'UY', # Uruguay
443
+
444
+ '1' => 'US', # United States
445
+
446
+ '998' => 'UZ', # Uzbekistan
447
+
448
+ '678' => 'VU', # Vanuatu
449
+
450
+ '39' => 'VA', # Holy See (Vatican City)
451
+
452
+ '58' => 'VE', # Venezuela
453
+
454
+ '84' => 'VN', # Vietnam
455
+
456
+ '1340' => 'VI', # US Virgin Islands
457
+
458
+ '681' => 'WF', # Wallis and Futuna
459
+
460
+ '967' => 'YE', # Yemen
461
+
462
+ '260' => 'ZM', # Zambia
463
+
464
+ '263' => 'ZW', # Zimbabwe
465
+
466
+
467
+ # TODO: Block 1 countries:
468
+ '1787' => 'PR',
469
+
470
+ # Special cases:
471
+ # Boy! Caribbean Islands' codes do get messy!
10
472
  '1829' => 'DO', # Dominican Republic Overlay 1
11
473
  '1849' => 'DO', # Dominican Republic Overlay 2
12
474
 
13
- '225' => 'CI', # Costa de Marfil
14
-
15
- '501' => 'BZ', # Belize
16
- '502' => 'GT', # Guatemala
17
- '503' => 'SV', # El Salvador
18
- '504' => 'HN', # Honduras
19
- '505' => 'NI', # Nicaragua
20
- '506' => 'CR', # Costa Rica
21
- '507' => 'PA', # Panamá
22
- '509' => 'HT', # Haití
23
- '51' => 'PE', # Perú
24
- '52' => 'MX', # México
25
- '53' => 'CU', # Cuba
26
- '54' => 'AR', # Argentina
27
- '55' => 'BR', # Brasil
28
- '56' => 'CL', # Chile
29
- '57' => 'CO', # Colombia
30
- '58' => 'VE', # Venezuela
31
- '591' => 'BO', # Bolivia
32
- '593' => 'EC', # Ecuador
33
- '595' => 'PY', # Paraguay
34
- '598' => 'UY' # Uruguay
35
- }.with_indifferent_access.freeze
475
+ }.freeze
36
476
  end