mobile-subscriber 0.0.1.alpha2 → 0.0.1.alpha3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6b29c8cf76516b361c8753086b5bfe49b923d00c
4
- data.tar.gz: fa9a11ddf533e3b8ef39b10468da7f788f899343
3
+ metadata.gz: 05c532c346541fb9e968134f7513aae13e009372
4
+ data.tar.gz: 3397d7e1ab671876b3d3b20f435451369c8f40a8
5
5
  SHA512:
6
- metadata.gz: f36e4adef6a826ef1722b103380953593ed3b1a1be28d10a59f78743293d48ec67402c4c56c36718e5370327edaa476abcaaf4ea40ee6c6d843b8cb0df5a7ee2
7
- data.tar.gz: 58bd599c9534d5a7d13cd2b04743316f828e697ef0b6bc286f782818da041997e660249b8a5055df7d4c2e4251f50475f5acec53d90ac1f389991051ddc9a3ec
6
+ metadata.gz: 96511b79ddd731ced98b6c72f626d70971725fac9820e0515c0f62d53a6c4564f6a168ef916d0d9119578ddf60144bd6a349519ec41717fb732a7f8130a92c58
7
+ data.tar.gz: 7acf06ddc07c20291526bf1940212229d4de5907e70f45a447f5cb93a9044513b339becc1f5293ac34f9a87c40d9b04a0954e1d24dd389d03dd84d1c7014759d
@@ -8,8 +8,9 @@ module MobileSubscriber
8
8
 
9
9
  module Detection
10
10
  extend ActiveSupport::Autoload
11
- autoload :FromMsisdnHeader
12
- autoload :FromXNokiaMsisdnHeader
13
- autoload :FromXUpChMsisdnHeader
11
+ autoload :FromMsisdnHttpRequestHeader
12
+ autoload :FromXNokiaMsisdnHttpRequestHeader
13
+ autoload :FromXUpChMsisdnHttpRequestHeader
14
+ autoload :FromXUpCallingLineIdHttpRequestHeader
14
15
  end
15
16
  end
@@ -4,7 +4,7 @@ module MobileSubscriber
4
4
  # Módulo que provee métodos de deteccion y validacion para MSISDN por el
5
5
  # header de HTTP 'Msisdn':
6
6
  # - Vivo Brasil
7
- module FromMsisdnHeader
7
+ module FromMsisdnHttpRequestHeader
8
8
 
9
9
  extend ActiveSupport::Concern
10
10
 
@@ -15,20 +15,26 @@ module MobileSubscriber
15
15
 
16
16
  isdn_attributes = nil
17
17
 
18
- if msisdn = request.env[header_env_key]
18
+ isdn_attributes = if msisdn = request.env[header_env_key] and msisdn.length >= 8
19
19
 
20
- # Determinar la procedencia del MSISDN
21
- # TODO: Validar por IP, etc.
22
- isdn_attributes = case
23
-
24
- # Vivo BR (Claro):
25
- when msisdn =~ /\A55/ then {
26
- id: msisdn,
27
- mobile_country_code: "724",
28
- mobile_network_code: "06"
20
+ detection_cues = {
21
+ remote_ip: request.env["REMOTE_ADDR"],
22
+ http_request_headers: { 'Msisdn' => msisdn }
29
23
  }
30
24
 
31
- end if msisdn.length >= 8
25
+ country_code = MobileSubscriber::DIALING_COUNTRY_CODES[msisdn[0,2]]
26
+
27
+ # Determinar la procedencia del MSISDN
28
+ # TODO: Validar por IP, etc.
29
+ case country_code
30
+ when 'BR'
31
+ # Vivo BR (Claro):
32
+ {
33
+ id: msisdn,
34
+ mobile_country_code: "724",
35
+ mobile_network_code: "06"
36
+ }
37
+ end
32
38
 
33
39
  end
34
40
 
@@ -0,0 +1,52 @@
1
+ module MobileSubscriber
2
+ module Detection
3
+
4
+ # Módulo que provee métodos de deteccion y validacion para MSISDN's de:
5
+ # - Telcel México
6
+ # - Claro Argentina
7
+ module FromXNokiaMsisdnHttpRequestHeader
8
+
9
+ extend ActiveSupport::Concern
10
+
11
+ module ClassMethods
12
+ def extract_from_x_nokia_msisdn_http_request_header(request)
13
+
14
+ header_name = 'X-Nokia-Msisdn'
15
+ header_env_key = "HTTP_#{header_name.gsub('-','_').upcase}"
16
+
17
+ isdn_attributes = if msisdn = request.env[header_env_key] and msisdn.length >= 8
18
+ detection_cues = {
19
+ remote_ip: request.env["REMOTE_ADDR"],
20
+ http_request_headers: { 'X-Nokia-Msisdn' => msisdn }
21
+ }
22
+
23
+ country_code = MobileSubscriber::DIALING_COUNTRY_CODES[msisdn[0,2]]
24
+
25
+ # Determinar la procedencia del MSISDN
26
+ # TODO: Validar por IP, etc.
27
+ case country_code
28
+ when 'MX'
29
+ # Telcel México:
30
+ {
31
+ id: msisdn,
32
+ mobile_country_code: "334",
33
+ mobile_network_code: "020"
34
+ }.merge(detection_cues: detection_cues)
35
+
36
+ # Claro Argentina:
37
+ when 'AR'
38
+ {
39
+ id: msisdn,
40
+ mobile_country_code: "722",
41
+ mobile_network_code: "330"
42
+ }.merge(detection_cues: detection_cues)
43
+ end
44
+ end
45
+
46
+ isdn_attributes
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,99 @@
1
+ module MobileSubscriber
2
+ module Detection
3
+
4
+ # Módulo que provee métodos de deteccion y validacion para MSISDN por el
5
+ # header de HTTP 'X-Up-Calling-Line-Id':
6
+ # - Claro Perú
7
+ # - TIM (Telecom Italia Mobile) Brasil
8
+ # - OI Brasil
9
+ # - Movistar México
10
+ # - Movistar Argentina
11
+ # - Movistar Ecuador
12
+ # - Movistar Perú
13
+ module FromXUpCallingLineIdHttpRequestHeader
14
+
15
+ extend ActiveSupport::Concern
16
+
17
+ module ClassMethods
18
+ def extract_from_x_up_calling_line_id_http_request_header(request)
19
+ header_name = 'X-Up-Calling-Line-Id'
20
+ header_env_key = "HTTP_#{header_name.gsub('-','_').upcase}"
21
+
22
+ isdn_attributes = if msisdn = request.env[header_env_key] and msisdn.length >= 8
23
+
24
+ detection_cues = {
25
+ remote_ip: request.env["REMOTE_ADDR"],
26
+ http_request_headers: { header_name => msisdn }
27
+ }
28
+
29
+ country_code = MobileSubscriber::DIALING_COUNTRY_CODES[msisdn[0,2]] || MobileSubscriber::DIALING_COUNTRY_CODES[msisdn[0,3]]
30
+
31
+ case country_code
32
+ when 'PE'
33
+ if (http_request_via_header = request.env["HTTP_VIA"]).present? and http_request_via_header =~ /Comverse/i
34
+ # Is Claro Peru subscriber:
35
+ detection_cues[:http_request_headers]['Via'] = http_request_via_header
36
+ {
37
+ id: msisdn,
38
+ mobile_country_code: "716",
39
+ mobile_network_code: "10"
40
+ }.merge(detection_cues: detection_cues)
41
+ else
42
+ # Is a Movistar Peru subscriber:
43
+ {
44
+ id: msisdn,
45
+ mobile_country_code: "716",
46
+ mobile_network_code: "06"
47
+ }.merge(detection_cues: detection_cues)
48
+ end
49
+ when 'BR'
50
+ if http_request_x_msp_apn_header = request.env["HTTP_X_MSP_APN"] and http_request_x_msp_apn_header.present?
51
+ detection_cues[:http_request_headers]['X-Msp-Apn'] = http_request_x_msp_apn_header
52
+ if http_request_x_msp_apn_header =~ /OI/i
53
+ # Is a Oi Brazil subscriber:
54
+ {
55
+ id: msisdn,
56
+ mobile_country_code: "724",
57
+ mobile_network_code: "30"
58
+ }.merge(detection_cues: detection_cues)
59
+ else
60
+ # Is a TIM Brasil subscriber:
61
+ {
62
+ id: msisdn,
63
+ mobile_country_code: "724",
64
+ mobile_network_code: "02"
65
+ }.merge(detection_cues: detection_cues)
66
+ end
67
+ end
68
+ when 'MX'
69
+ # Is a Movistar Mexico subscriber:
70
+ {
71
+ id: msisdn,
72
+ mobile_country_code: "334",
73
+ mobile_network_code: "030"
74
+ }.merge(detection_cues: detection_cues)
75
+ when 'AR'
76
+ # Is a Movistar Argentina subscriber:
77
+ # TODO: Detect if MNC is 010 or 070 (Different MHz Bands)
78
+ {
79
+ id: msisdn,
80
+ mobile_country_code: "722",
81
+ mobile_network_code: "010"
82
+ }.merge(detection_cues: detection_cues)
83
+ when 'EC'
84
+ # Is a Movistar Ecuador subscriber:
85
+ {
86
+ id: msisdn,
87
+ mobile_country_code: "740",
88
+ mobile_network_code: "00"
89
+ }.merge(detection_cues: detection_cues)
90
+ end
91
+ end
92
+
93
+ isdn_attributes
94
+ end
95
+ end
96
+
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,44 @@
1
+ module MobileSubscriber
2
+ module Detection
3
+
4
+ # Módulo que provee métodos de deteccion y validacion para MSISDN's de:
5
+ # - Claro Brasil
6
+ module FromXUpChMsisdnHttpRequestHeader
7
+
8
+ extend ActiveSupport::Concern
9
+
10
+ module ClassMethods
11
+ def extract_from_x_up_ch_msisdn_http_request_header(request)
12
+ header_name = 'X-Up-Ch-Msisdn'
13
+ header_env_key = "HTTP_#{header_name.gsub('-','_').upcase}"
14
+
15
+ isdn_attributes = if msisdn = request.env[header_env_key] and msisdn.length >= 8
16
+
17
+ detection_cues = {
18
+ remote_ip: request.env["REMOTE_ADDR"],
19
+ http_request_headers: { 'X-Up-Ch-Msisdn' => msisdn }
20
+ }
21
+
22
+ country_code = MobileSubscriber::DIALING_COUNTRY_CODES[msisdn[0,2]]
23
+
24
+ # Determinar la procedencia del MSISDN
25
+ # TODO: Validar por IP, etc.
26
+ case country_code
27
+ when 'BR'
28
+ # Claro BR (Claro):
29
+ {
30
+ id: msisdn,
31
+ mobile_country_code: "724",
32
+ mobile_network_code: "05"
33
+ }.merge(detection_cues: detection_cues)
34
+ end
35
+
36
+ end
37
+ isdn_attributes
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,25 @@
1
+ module MobileSubscriber
2
+ # Diccionario de Mobile Country Codes => ISO country codes:
3
+ DIALING_COUNTRY_CODES = {
4
+ '501' => 'BZ', # Belize
5
+ '502' => 'GT', # Guatemala
6
+ '503' => 'SV', # El Salvador
7
+ '504' => 'HN', # Honduras
8
+ '505' => 'NI', # Nicaragua
9
+ '506' => 'CR', # Costa Rica
10
+ '507' => 'CI', # Costa de Marfil
11
+ '509' => 'HT', # Haití
12
+ '51' => 'PE', # Perú
13
+ '52' => 'MX', # México
14
+ '53' => 'CU', # Cuba
15
+ '54' => 'AR', # Argentina
16
+ '55' => 'BR', # Brasil
17
+ '56' => 'CL', # Chile
18
+ '57' => 'CO', # Colombia
19
+ '58' => 'VE', # Venezuela
20
+ '591' => 'BO', # Bolivia
21
+ '593' => 'EC', # Ecuador
22
+ '595' => 'PY', # Paraguay
23
+ '598' => 'UY' # Uruguay
24
+ }.with_indifferent_access.freeze
25
+ end
@@ -1,21 +1,24 @@
1
1
  require 'mobile_subscriber/dictionaries/mobile_and_iso_country_codes'
2
+ require 'mobile_subscriber/dictionaries/dialing_and_country_codes'
2
3
  require 'mobile_subscriber/dictionaries/operator_data'
3
4
 
4
5
  module MobileSubscriber
5
6
 
6
7
  class ISDN
7
8
 
8
- attr_reader :id, :mobile_country_code, :mobile_network_code
9
+ attr_reader :id, :mobile_country_code, :mobile_network_code, :detection_cues
9
10
  alias_method :to_s, :id
10
11
 
11
- include MobileSubscriber::Detection::FromMsisdnHeader
12
- include MobileSubscriber::Detection::FromXNokiaMsisdnHeader
13
- include MobileSubscriber::Detection::FromXUpChMsisdnHeader
12
+ include MobileSubscriber::Detection::FromMsisdnHttpRequestHeader
13
+ include MobileSubscriber::Detection::FromXNokiaMsisdnHttpRequestHeader
14
+ include MobileSubscriber::Detection::FromXUpChMsisdnHttpRequestHeader
15
+ include MobileSubscriber::Detection::FromXUpCallingLineIdHttpRequestHeader
14
16
 
15
17
  def initialize(attributes={})
16
18
  @id = attributes.delete :id
17
19
  @mobile_country_code = attributes.delete :mobile_country_code
18
20
  @mobile_network_code = attributes.delete :mobile_network_code
21
+ @detection_cues = attributes.delete :detection_cues
19
22
  end
20
23
 
21
24
  def dialing_code
@@ -1,3 +1,3 @@
1
1
  module MobileSubscriber
2
- VERSION = "0.0.1.alpha2"
2
+ VERSION = "0.0.1.alpha3"
3
3
  end
@@ -56,12 +56,13 @@ FactoryGirl.define do
56
56
  end
57
57
  end
58
58
 
59
- factory :forged_mobile_request_from_telcel_mexico do
59
+ factory :mobile_request_from_claro_peru do
60
60
  initialize_with do
61
61
  new build(:common_mobile_request_env).merge(
62
- "REMOTE_ADDR" => "170.51.255.240", # An argentinian IP Address
63
- "REMOTE_HOST" => "170.51.255.240", # An argentinian IP Address
64
- "HTTP_X_NOKIA_MSISDN" => "528110000000" # A mexican MSISDN
62
+ "REMOTE_ADDR" => "190.113.192.9",
63
+ "REMOTE_HOST" => "190.113.192.9",
64
+ "HTTP_X_UP_CALLING_LINE_ID" => "5100000000000",
65
+ "HTTP_VIA" => "aa Comverse aaa"
65
66
  )
66
67
  end
67
68
  end
@@ -41,6 +41,10 @@ describe MobileSubscriber::ISDN do
41
41
  describe "detection from request headers" do
42
42
 
43
43
  shared_examples "of detection from a valid request" do
44
+ it "is not nil" do
45
+ expect(subject).not_to be_nil
46
+ end
47
+
44
48
  it "responds to #http_validated? with true" do
45
49
  expect(subject).to be_http_validated
46
50
  end
@@ -50,6 +54,7 @@ describe MobileSubscriber::ISDN do
50
54
  end
51
55
  end
52
56
 
57
+ # of detection from a request made from a {Demonym} mobile network:
53
58
  shared_examples "of detection from a request made from a mexican mobile network" do
54
59
  it "responds to #id with a string starting with '52'" do
55
60
  expect(subject.id).to match /\A52/
@@ -104,6 +109,24 @@ describe MobileSubscriber::ISDN do
104
109
  end
105
110
  end
106
111
 
112
+ shared_examples "of detection from a request made from a peruvian mobile network" do
113
+ it "responds to #id with a string starting with '51'" do
114
+ expect(subject.id).to match /\A51/
115
+ end
116
+
117
+ it "responds to #mobile_country_code with '716'" do
118
+ expect(subject.mobile_country_code).to eq '716'
119
+ end
120
+
121
+ it "responds to #dialing_code with '51'" do
122
+ expect(subject.dialing_code).to eq '51'
123
+ end
124
+
125
+ it "responds to #iso_3166_country_code with 'PE'" do
126
+ expect(subject.iso_3166_country_code).to eq 'PE'
127
+ end
128
+ end
129
+
107
130
  shared_examples "of detection from a request made from a Claro network" do
108
131
  it "responds to #mobile_network_brand with a string containing 'Claro'" do
109
132
  expect(subject.mobile_network_brand).to match /\AClaro/
@@ -160,6 +183,22 @@ describe MobileSubscriber::ISDN do
160
183
  end
161
184
  end
162
185
 
186
+ context "from a request made from Claro Perú" do
187
+
188
+ subject do
189
+ described_class.new_from_request(build :mobile_request_from_claro_peru)
190
+ end
191
+
192
+ include_examples "of detection from a valid request"
193
+ include_examples "of detection from a request made from a peruvian mobile network"
194
+ include_examples "of detection from a request made from a Claro network"
195
+
196
+ it "responds to #mobile_network_operator with 'América Móvil Perú'" do
197
+ expect(subject.mobile_network_operator).to eq 'América Móvil Perú'
198
+ end
199
+
200
+ end
201
+
163
202
  end
164
203
 
165
204
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require 'mobile_subscriber'
2
+ require 'mobile-subscriber'
3
3
  require 'byebug'
4
4
  require 'factory_girl'
5
5
  require 'rack'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobile-subscriber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha2
4
+ version: 0.0.1.alpha3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Quintanilla
@@ -113,9 +113,11 @@ files:
113
113
  - build-docker.sh
114
114
  - fig.yml
115
115
  - lib/mobile-subscriber.rb
116
- - lib/mobile_subscriber/detection/from_msisdn_header.rb
117
- - lib/mobile_subscriber/detection/from_x_nokia_msisdn_header.rb
118
- - lib/mobile_subscriber/detection/from_x_up_ch_msisdn_header.rb
116
+ - lib/mobile_subscriber/detection/from_msisdn_http_request_header.rb
117
+ - lib/mobile_subscriber/detection/from_x_nokia_msisdn_http_request_header.rb
118
+ - lib/mobile_subscriber/detection/from_x_up_calling_line_id_http_request_header.rb
119
+ - lib/mobile_subscriber/detection/from_x_up_ch_msisdn_http_request_header.rb
120
+ - lib/mobile_subscriber/dictionaries/dialing_and_country_codes.rb
119
121
  - lib/mobile_subscriber/dictionaries/mobile_and_iso_country_codes.rb
120
122
  - lib/mobile_subscriber/dictionaries/operator_data.rb
121
123
  - lib/mobile_subscriber/isdn.rb
@@ -1,47 +0,0 @@
1
- module MobileSubscriber
2
- module Detection
3
-
4
- # Módulo que provee métodos de deteccion y validacion para MSISDN's de:
5
- # - Telcel México
6
- # - Claro Argentina
7
- module FromXNokiaMsisdnHeader
8
-
9
- extend ActiveSupport::Concern
10
-
11
- module ClassMethods
12
- def extract_from_x_nokia_msisdn_http_request_header(request)
13
-
14
- header_name = 'X-Nokia-Msisdn'
15
- header_env_key = "HTTP_#{header_name.gsub('-','_').upcase}"
16
-
17
- isdn_attributes = nil
18
-
19
- if msisdn = request.env[header_env_key]
20
-
21
- # Determinar la procedencia del MSISDN
22
- # TODO: Validar por IP, etc.
23
- isdn_attributes = case
24
-
25
- # Telcel México:
26
- when msisdn =~ /\A52/ then {
27
- id: msisdn,
28
- mobile_country_code: "334",
29
- mobile_network_code: "020"
30
- }
31
-
32
- # Claro Argentina:
33
- when msisdn =~ /\A54/ then {
34
- id: msisdn,
35
- mobile_country_code: "722",
36
- mobile_network_code: "330"
37
- }
38
- end if msisdn.length >= 8
39
- end
40
-
41
- isdn_attributes
42
- end
43
-
44
- end
45
- end
46
- end
47
- end
@@ -1,39 +0,0 @@
1
- module MobileSubscriber
2
- module Detection
3
-
4
- # Módulo que provee métodos de deteccion y validacion para MSISDN's de:
5
- # - Claro Brasil
6
- module FromXUpChMsisdnHeader
7
-
8
- extend ActiveSupport::Concern
9
-
10
- module ClassMethods
11
- def extract_from_x_up_ch_msisdn_http_request_header(request)
12
- header_name = 'X-Up-Ch-Msisdn'
13
- header_env_key = "HTTP_#{header_name.gsub('-','_').upcase}"
14
- isdn_attributes = nil
15
-
16
- if msisdn = request.env[header_env_key]
17
-
18
- # Determinar la procedencia del MSISDN
19
- # TODO: Validar por IP, etc.
20
- isdn_attributes = case
21
-
22
- # Claro BR (Claro):
23
- when msisdn =~ /\A55/ then {
24
- id: msisdn,
25
- mobile_country_code: "724",
26
- mobile_network_code: "05"
27
- }
28
-
29
- end if msisdn.length >= 8
30
-
31
- end
32
- isdn_attributes
33
- end
34
-
35
- end
36
-
37
- end
38
- end
39
- end