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.
- checksums.yaml +4 -4
- data/lib/mobile-subscriber.rb +13 -3
- data/lib/mobile_subscriber/dictionaries/dialing_and_country_codes.rb +468 -28
- data/lib/mobile_subscriber/http/known_imsi_headers.rb +22 -0
- data/lib/mobile_subscriber/http/known_msisdn_headers.rb +68 -0
- data/lib/mobile_subscriber/http/request_info.rb +166 -0
- data/lib/mobile_subscriber/identity.rb +97 -1
- data/lib/mobile_subscriber/version.rb +1 -1
- data/mobile_subscriber.thor +41 -0
- data/spec/factories/mobile_requests.rb +28 -0
- data/spec/factories/mobile_requests_from_claro.rb +257 -0
- data/spec/factories/mobile_requests_from_iusacell.rb +13 -0
- data/spec/factories/mobile_requests_from_movistar.rb +15 -0
- data/spec/factories/mobile_requests_from_telcel.rb +14 -0
- data/spec/factories/mobile_requests_from_vivo.rb +13 -0
- data/spec/features/claro_user_detection_spec.rb +170 -0
- data/spec/features/iusacell_user_detection_spec.rb +19 -0
- data/spec/features/movistar_user_detection_spec.rb +19 -0
- data/spec/features/telcel_user_detection_spec.rb +19 -0
- data/spec/models/{isdn_spec.rb → identity_spec.rb} +5 -5
- data/spec/shared_examples/identity_detection_in_argentina.rb +11 -0
- data/spec/shared_examples/identity_detection_in_brazil.rb +12 -0
- data/spec/shared_examples/identity_detection_in_chile.rb +12 -0
- data/spec/shared_examples/identity_detection_in_colombia.rb +12 -0
- data/spec/shared_examples/identity_detection_in_costa_rica.rb +15 -0
- data/spec/shared_examples/identity_detection_in_dominican_republic.rb +12 -0
- data/spec/shared_examples/identity_detection_in_ecuador.rb +12 -0
- data/spec/shared_examples/identity_detection_in_el_salvador.rb +15 -0
- data/spec/shared_examples/identity_detection_in_guatemala.rb +15 -0
- data/spec/shared_examples/identity_detection_in_honduras.rb +11 -0
- data/spec/shared_examples/identity_detection_in_mexico.rb +11 -0
- data/spec/shared_examples/identity_detection_in_nicaragua.rb +12 -0
- data/spec/shared_examples/identity_detection_in_panama.rb +12 -0
- data/spec/shared_examples/identity_detection_in_peru.rb +12 -0
- data/spec/shared_examples/identity_detection_in_puerto_rico.rb +14 -0
- data/spec/shared_examples/of_msisdn_detection_from_http_request.rb +3 -188
- data/templates/dialing_and_country_codes.rb.erb +20 -0
- metadata +58 -28
- data/lib/mobile_subscriber/detection/from_msisdn_http_request_header.rb +0 -48
- data/lib/mobile_subscriber/detection/from_x_nokia_msisdn_http_request_header.rb +0 -58
- data/lib/mobile_subscriber/detection/from_x_up_calling_line_id_http_request_header.rb +0 -65
- data/lib/mobile_subscriber/detection/from_x_up_ch_msisdn_http_request_header.rb +0 -35
- data/lib/mobile_subscriber/detection/from_x_up_subno_http_request_header.rb +0 -44
- data/lib/mobile_subscriber/detection/from_x_wap_msisdn_http_request_header.rb +0 -37
- data/lib/mobile_subscriber/detection/from_x_wap_sesiones3g_mdn_http_request_header.rb +0 -39
- data/lib/mobile_subscriber/detection/from_x_ztgo_beareraddress_http_request_header.rb +0 -36
- data/lib/mobile_subscriber/detection/http_request_info.rb +0 -77
- data/lib/mobile_subscriber/isdn.rb +0 -89
- data/spec/detection/from_msisdn_http_request_header_spec.rb +0 -53
- data/spec/detection/from_x_nokia_msisdn_http_request_header_spec.rb +0 -99
- data/spec/detection/from_x_up_calling_line_id_http_request_header_spec.rb +0 -39
- data/spec/detection/from_x_up_subno_http_request_header_spec.rb +0 -43
- data/spec/detection/from_x_wap_msisdn_http_request_header_spec.rb +0 -32
- data/spec/detection/from_x_wap_sesiones3g_mdn_http_request_header_spec.rb +0 -29
- data/spec/factories/requests.rb +0 -229
@@ -0,0 +1,13 @@
|
|
1
|
+
# Read about factories at https://github.com/thoughtbot/factory_girl
|
2
|
+
|
3
|
+
FactoryGirl.define do
|
4
|
+
|
5
|
+
factory :mobile_request_from_iusacell_mexico, parent: :mobile_request do
|
6
|
+
initialize_with do
|
7
|
+
new build(:common_mobile_request_env).merge(
|
8
|
+
"REMOTE_ADDR" => "201.144.162.4",
|
9
|
+
"HTTP_X_WAP_SESIONES3G_MDN" => "528110000000"
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Read about factories at https://github.com/thoughtbot/factory_girl
|
2
|
+
|
3
|
+
FactoryGirl.define do
|
4
|
+
|
5
|
+
# http://myip.ms/view/ip_owners/7424/Telefonica_Del_Peru_Saa.html
|
6
|
+
factory :mobile_request_from_movistar_peru, parent: :mobile_request do
|
7
|
+
initialize_with do
|
8
|
+
new build(:common_mobile_request_env).merge(
|
9
|
+
"REMOTE_ADDR" => "190.42.165.87",
|
10
|
+
"HTTP_X_UP_CALLING_LINE_ID" => "5112100000"
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Read about factories at https://github.com/thoughtbot/factory_girl
|
2
|
+
|
3
|
+
FactoryGirl.define do
|
4
|
+
|
5
|
+
factory :mobile_request_from_telcel_mexico, parent: :mobile_request do
|
6
|
+
initialize_with do
|
7
|
+
new build(:common_mobile_request_env).merge(
|
8
|
+
"REMOTE_ADDR" => "201.144.162.4",
|
9
|
+
"HTTP_X_NOKIA_MSISDN" => "528110000000"
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Read about factories at https://github.com/thoughtbot/factory_girl
|
2
|
+
|
3
|
+
FactoryGirl.define do
|
4
|
+
|
5
|
+
factory :mobile_request_from_vivo_brasil, parent: :mobile_request do
|
6
|
+
initialize_with do
|
7
|
+
new build(:common_mobile_request_env).merge(
|
8
|
+
"REMOTE_ADDR" => "187.26.59.4",
|
9
|
+
"HTTP_X_UP_CH_MSISDN" => "5500000000000"
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Claro HTTP subscriber identity detection" do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
MobileSubscriber::Identity.new_from_request test_request
|
7
|
+
end
|
8
|
+
|
9
|
+
context "from Argentina" do
|
10
|
+
|
11
|
+
let :test_request do
|
12
|
+
build :mobile_request_from_claro_argentina
|
13
|
+
end
|
14
|
+
|
15
|
+
include_examples "of mobile subcriber identity detection from a valid argentinian mobile network http request"
|
16
|
+
|
17
|
+
# TODO: Bad test... we need to test for each network code, if it can be determined:
|
18
|
+
it "the mobile network code is '310', '320', or '330'" do
|
19
|
+
expect(%w(310 320 330)).to include subject.mobile_network_code
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "from Brasil" do
|
24
|
+
let :test_request do
|
25
|
+
build :mobile_request_from_claro_brasil
|
26
|
+
end
|
27
|
+
|
28
|
+
include_examples "of mobile subcriber identity detection from a valid brazilian mobile network http request"
|
29
|
+
|
30
|
+
it "the mobile network code is '05' or '38'" do
|
31
|
+
expect(%w(05 38)).to include subject.mobile_network_code
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "from Colombia" do
|
36
|
+
|
37
|
+
let(:test_request) { build :mobile_request_from_claro_colombia }
|
38
|
+
|
39
|
+
include_examples "of mobile subcriber identity detection from a valid colombian mobile network http request"
|
40
|
+
|
41
|
+
it "the mobile network code is '101'" do
|
42
|
+
expect(subject.mobile_network_code).to eq '101'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "from Panamá" do
|
47
|
+
|
48
|
+
let(:test_request) { build :mobile_request_from_claro_panama }
|
49
|
+
|
50
|
+
include_examples "of mobile subcriber identity detection from a valid panamanian mobile network http request"
|
51
|
+
|
52
|
+
it "the mobile network code is '03'" do
|
53
|
+
expect(subject.mobile_network_code).to eq '03'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "from Ecuador" do
|
58
|
+
let(:test_request) { build :mobile_request_from_claro_ecuador }
|
59
|
+
|
60
|
+
include_examples "of mobile subcriber identity detection from a valid ecuadorian mobile network http request"
|
61
|
+
|
62
|
+
it "the mobile network code is '01'" do
|
63
|
+
expect(subject.mobile_network_code).to eq '01'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "from República Dominicana" do
|
68
|
+
let(:test_request) { build :mobile_request_from_claro_dominican_republic }
|
69
|
+
|
70
|
+
include_examples "of mobile subcriber identity detection from a valid dominican mobile network http request"
|
71
|
+
|
72
|
+
it "the mobile network code is '02'" do
|
73
|
+
expect(subject.mobile_network_code).to eq '02'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "from Argentina" do
|
78
|
+
let(:test_request) { build :mobile_request_from_claro_argentina }
|
79
|
+
|
80
|
+
include_examples "of mobile subcriber identity detection from a valid argentinian mobile network http request"
|
81
|
+
|
82
|
+
# TODO: Bad test... we need to test for each network code, if it can be determined:
|
83
|
+
it "the mobile network code is '310', '320', or '330'" do
|
84
|
+
expect(subject.mobile_network_code).to match /310|320|330/
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "from Costa Rica" do
|
89
|
+
let(:test_request) { build :mobile_request_from_claro_costa_rica }
|
90
|
+
|
91
|
+
include_examples "of mobile subcriber identity detection from a valid costa rican mobile network http request"
|
92
|
+
|
93
|
+
it "the mobile network code is '03'" do
|
94
|
+
expect(subject.mobile_network_code).to eq '03'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
context "from Puerto Rico" do
|
99
|
+
let(:test_request) { build :mobile_request_from_claro_puerto_rico }
|
100
|
+
|
101
|
+
include_examples "of mobile subcriber identity detection from a valid puerto rican mobile network http request"
|
102
|
+
|
103
|
+
it "the mobile network code is '110'" do
|
104
|
+
expect(subject.mobile_network_code).to eq '110'
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "from Chile" do
|
109
|
+
let :test_request do
|
110
|
+
build :mobile_request_from_claro_chile
|
111
|
+
end
|
112
|
+
|
113
|
+
include_examples "of mobile subcriber identity detection from a valid chilean mobile network http request"
|
114
|
+
|
115
|
+
it "the mobile network code is '03'" do
|
116
|
+
expect(subject.mobile_network_code).to eq '03'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context "from Guatemala" do
|
121
|
+
let(:test_request) { build :mobile_request_from_claro_guatemala }
|
122
|
+
|
123
|
+
include_examples "of mobile subcriber identity detection from a valid guatemalan mobile network http request"
|
124
|
+
|
125
|
+
it "the mobile network code is '01'" do
|
126
|
+
expect(subject.mobile_network_code).to eq '01'
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context "from Honduras" do
|
131
|
+
let(:test_request) { build :mobile_request_from_claro_honduras }
|
132
|
+
|
133
|
+
include_examples "of mobile subcriber identity detection from a valid honduran mobile network http request"
|
134
|
+
|
135
|
+
it "the mobile network code is '001'" do
|
136
|
+
expect(subject.mobile_network_code).to eq '001'
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "from Nicaragua" do
|
141
|
+
let(:test_request) { build :mobile_request_from_claro_nicaragua }
|
142
|
+
|
143
|
+
include_examples "of mobile subcriber identity detection from a valid nicaraguan mobile network http request"
|
144
|
+
|
145
|
+
it "the mobile network code is '21'" do
|
146
|
+
expect(subject.mobile_network_code).to eq '21'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "from El Salvador" do
|
151
|
+
let(:test_request) { build :mobile_request_from_claro_el_salvador }
|
152
|
+
|
153
|
+
include_examples "of mobile subcriber identity detection from a valid salvadoran mobile network http request"
|
154
|
+
|
155
|
+
it "the mobile network code is '01'" do
|
156
|
+
expect(subject.mobile_network_code).to eq '01'
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context "from Perú" do
|
161
|
+
let(:test_request) { build :mobile_request_from_claro_peru }
|
162
|
+
|
163
|
+
include_examples "of mobile subcriber identity detection from a valid peruvian mobile network http request"
|
164
|
+
|
165
|
+
it "the mobile network code is '10'" do
|
166
|
+
expect(subject.mobile_network_code).to eq '10'
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Iusacell HTTP subscriber identity detection" do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
MobileSubscriber::Identity.new_from_request test_request
|
7
|
+
end
|
8
|
+
|
9
|
+
context "from México" do
|
10
|
+
let(:test_request) { build :mobile_request_from_iusacell_mexico }
|
11
|
+
|
12
|
+
include_examples "of mobile subcriber identity detection from a valid mexican mobile network http request"
|
13
|
+
|
14
|
+
it "the mobile network code is '040' or '050'" do
|
15
|
+
expect(subject.mobile_network_code).to match /040|050/i
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Movistar HTTP subscriber identity detection" do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
MobileSubscriber::Identity.new_from_request test_request
|
7
|
+
end
|
8
|
+
|
9
|
+
context "from Perú" do
|
10
|
+
let(:test_request) { build :mobile_request_from_movistar_peru }
|
11
|
+
|
12
|
+
include_examples "of mobile subcriber identity detection from a valid peruvian mobile network http request"
|
13
|
+
|
14
|
+
it "the mobile network code is '06'" do
|
15
|
+
expect(subject.mobile_network_code).to eq '06'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Telcel HTTP subscriber identity detection" do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
MobileSubscriber::Identity.new_from_request test_request
|
7
|
+
end
|
8
|
+
|
9
|
+
context "from México" do
|
10
|
+
let(:test_request) { build :mobile_request_from_telcel_mexico }
|
11
|
+
|
12
|
+
include_examples "of mobile subcriber identity detection from a valid mexican mobile network http request"
|
13
|
+
|
14
|
+
it "the mobile network code is '020'" do
|
15
|
+
expect(subject.mobile_network_code).to eq '020'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe MobileSubscriber::
|
3
|
+
describe MobileSubscriber::Identity do
|
4
4
|
|
5
5
|
it "responds to #id" do
|
6
6
|
expect(subject).to respond_to :id
|
7
7
|
end
|
8
8
|
|
9
|
-
it "aliases #id
|
10
|
-
expect(subject.
|
9
|
+
it "aliases #id to #to_s" do
|
10
|
+
expect(subject.id).to eq subject.to_s
|
11
11
|
end
|
12
12
|
|
13
13
|
it "responds to #mobile_country_code" do
|
@@ -47,7 +47,7 @@ describe MobileSubscriber::ISDN do
|
|
47
47
|
context "from a request made from a valid mobile network" do
|
48
48
|
|
49
49
|
subject do
|
50
|
-
described_class.new_from_request(build :
|
50
|
+
described_class.new_from_request(build :mobile_request_from_claro_panama)
|
51
51
|
end
|
52
52
|
|
53
53
|
it "is not nil" do
|
@@ -63,7 +63,7 @@ describe MobileSubscriber::ISDN do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
it "#id is present" do
|
66
|
-
expect(subject.
|
66
|
+
expect(subject.msisdn).to be_present
|
67
67
|
end
|
68
68
|
|
69
69
|
it "#mobile_country_code is present" do
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
shared_examples "of mobile subcriber identity detection from a valid argentinian mobile network http request" do
|
4
|
+
|
5
|
+
it "the msisdn starts with '54'" do
|
6
|
+
expect(subject.msisdn).to start_with '54'
|
7
|
+
end
|
8
|
+
it "the mobile country code is '722'" do
|
9
|
+
expect(subject.mobile_country_code).to eq '722'
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
shared_examples "of mobile subcriber identity detection from a valid brazilian mobile network http request" do
|
4
|
+
|
5
|
+
it "the msisdn starts with '55'" do
|
6
|
+
expect(subject.msisdn).to start_with '55'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "the mobile country code is '724'" do
|
10
|
+
expect(subject.mobile_country_code).to eq '724'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
shared_examples "of mobile subcriber identity detection from a valid chilean mobile network http request" do
|
4
|
+
|
5
|
+
it "the msisdn starts with '56'" do
|
6
|
+
expect(subject.msisdn).to start_with '56'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "the mobile country code is '730'" do
|
10
|
+
expect(subject.mobile_country_code).to eq '730'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
shared_examples "of mobile subcriber identity detection from a valid colombian mobile network http request" do
|
4
|
+
|
5
|
+
it "the msisdn starts with '57'" do
|
6
|
+
expect(subject.msisdn).to start_with '57'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "the mobile country code is '732'" do
|
10
|
+
expect(subject.mobile_country_code).to eq '732'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
shared_examples "of mobile subcriber identity detection from a valid costa rican mobile network http request" do
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
it "the msisdn starts with '506'" do
|
8
|
+
expect(subject.msisdn).to start_with '506'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "the mobile country code is '712'" do
|
12
|
+
expect(subject.mobile_country_code).to eq '712'
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
shared_examples "of mobile subcriber identity detection from a valid dominican mobile network http request" do
|
4
|
+
|
5
|
+
it "the msisdn starts with '1809'" do
|
6
|
+
expect(subject.msisdn).to start_with '1809'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "the mobile country code is '370'" do
|
10
|
+
expect(subject.mobile_country_code).to eq '370'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
shared_examples "of mobile subcriber identity detection from a valid ecuadorian mobile network http request" do
|
4
|
+
|
5
|
+
it "the msisdn starts with '593'" do
|
6
|
+
expect(subject.msisdn).to start_with '593'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "the mobile country code is '740'" do
|
10
|
+
expect(subject.mobile_country_code).to eq '740'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
shared_examples "of mobile subcriber identity detection from a valid salvadoran mobile network http request" do
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
it "the msisdn starts with '503'" do
|
8
|
+
expect(subject.msisdn).to start_with '503'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "the mobile country code is '706'" do
|
12
|
+
expect(subject.mobile_country_code).to eq '706'
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
shared_examples "of mobile subcriber identity detection from a valid guatemalan mobile network http request" do
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
it "the msisdn starts with '502'" do
|
8
|
+
expect(subject.msisdn).to start_with '502'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "the mobile country code is '704'" do
|
12
|
+
expect(subject.mobile_country_code).to eq '704'
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|