mobile-subscriber 0.0.1.alpha1

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.
@@ -0,0 +1,71 @@
1
+ # Read about factories at https://github.com/thoughtbot/factory_girl
2
+
3
+ FactoryGirl.define do
4
+
5
+ factory :common_mobile_request_env, class: Hash do
6
+ initialize_with do
7
+ {
8
+ "HTTP_HOST" => "www.example.com",
9
+ "HTTP_CONNECTION" => "keep-alive",
10
+ "HTTP_CACHE_CONTROL" => "max-age=0",
11
+ "HTTP_ACCEPT" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
12
+ "HTTP_USER_AGENT" => "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53",
13
+ "HTTP_ACCEPT_ENCODING" => "gzip, deflate, sdch",
14
+ "HTTP_ACCEPT_LANGUAGE" => "en-US,en;q=0.8,es;q=0.6",
15
+ "HTTP_VERSION" => "HTTP/1.1"
16
+ }
17
+ end
18
+ end
19
+
20
+ factory :mobile_request, class: Rack::Request do
21
+
22
+ initialize_with do
23
+ new build(:common_mobile_request_env).merge(
24
+ "REMOTE_ADDR" => "201.144.162.4",
25
+ "REMOTE_HOST" => "201.144.162.4"
26
+ )
27
+ end
28
+
29
+ factory :mobile_request_from_telcel_mexico do
30
+ initialize_with do
31
+ new build(:common_mobile_request_env).merge(
32
+ "REMOTE_ADDR" => "201.144.162.4",
33
+ "REMOTE_HOST" => "201.144.162.4",
34
+ "HTTP_X_NOKIA_MSISDN" => "528110000000"
35
+ )
36
+ end
37
+ end
38
+
39
+ factory :mobile_request_from_claro_argentina do
40
+ initialize_with do
41
+ new build(:common_mobile_request_env).merge(
42
+ "REMOTE_ADDR" => "170.51.255.240",
43
+ "REMOTE_HOST" => "170.51.255.240",
44
+ "HTTP_X_NOKIA_MSISDN" => "5491141098443"
45
+ )
46
+ end
47
+ end
48
+
49
+ factory :mobile_request_from_claro_brasil do
50
+ initialize_with do
51
+ new build(:common_mobile_request_env).merge(
52
+ "REMOTE_ADDR" => "187.26.59.4",
53
+ "REMOTE_HOST" => "187.26.59.4",
54
+ "HTTP_X_UP_CH_MSISDN" => "5500000000000"
55
+ )
56
+ end
57
+ end
58
+
59
+ factory :forged_mobile_request_from_telcel_mexico do
60
+ initialize_with do
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
65
+ )
66
+ end
67
+ end
68
+
69
+
70
+ end
71
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe MobileSubscriber do
4
+ it 'has a version number' do
5
+ expect(MobileSubscriber::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,165 @@
1
+ require "spec_helper"
2
+
3
+ describe MobileSubscriber::ISDN do
4
+
5
+ it "responds to #id" do
6
+ expect(subject).to respond_to :id
7
+ end
8
+
9
+ it "aliases #id as #to_s" do
10
+ expect(subject.to_s).to eq subject.id
11
+ end
12
+
13
+ it "responds to #mobile_country_code" do
14
+ expect(subject).to respond_to :mobile_country_code
15
+ end
16
+
17
+ it "responds to #mobile_network_code" do
18
+ expect(subject).to respond_to :mobile_network_code
19
+ end
20
+
21
+ it "responds to #dialing_code" do
22
+ expect(subject).to respond_to :dialing_code
23
+ end
24
+
25
+ it "responds to #iso_3166_country_code" do
26
+ expect(subject).to respond_to :iso_3166_country_code
27
+ end
28
+
29
+ it "responds to #mobile_network_brand" do
30
+ expect(subject).to respond_to :mobile_network_brand
31
+ end
32
+
33
+ it "responds to #mobile_network_operator" do
34
+ expect(subject).to respond_to :mobile_network_operator
35
+ end
36
+
37
+ it "responds to #http_validated?" do
38
+ expect(subject).to respond_to :http_validated?
39
+ end
40
+
41
+ describe "detection from request headers" do
42
+
43
+ shared_examples "of detection from a valid request" do
44
+ it "responds to #http_validated? with true" do
45
+ expect(subject).to be_http_validated
46
+ end
47
+
48
+ it "responds to #inspect with a string containing '(validated by HTTP)'" do
49
+ expect(subject.inspect).to match /\(validated by HTTP\)>\z/
50
+ end
51
+ end
52
+
53
+ shared_examples "of detection from a request made from a mexican mobile network" do
54
+ it "responds to #id with a string starting with '52'" do
55
+ expect(subject.id).to match /\A52/
56
+ end
57
+
58
+ it "responds to #mobile_country_code with '334'" do
59
+ expect(subject.mobile_country_code).to eq '334'
60
+ end
61
+
62
+ it "responds to #dialing_code with '52'" do
63
+ expect(subject.dialing_code).to eq '52'
64
+ end
65
+
66
+ it "responds to #iso_3166_country_code with 'MX'" do
67
+ expect(subject.iso_3166_country_code).to eq 'MX'
68
+ end
69
+ end
70
+
71
+ shared_examples "of detection from a request made from an argentinian mobile network" do
72
+ it "responds to #id with a string starting with '54'" do
73
+ expect(subject.id).to match /\A54/
74
+ end
75
+
76
+ it "responds to #mobile_country_code with '722'" do
77
+ expect(subject.mobile_country_code).to eq '722'
78
+ end
79
+
80
+ it "responds to #dialing_code with '54'" do
81
+ expect(subject.dialing_code).to eq '54'
82
+ end
83
+
84
+ it "responds to #iso_3166_country_code with 'AR'" do
85
+ expect(subject.iso_3166_country_code).to eq 'AR'
86
+ end
87
+ end
88
+
89
+ shared_examples "of detection from a request made from a brazilian mobile network" do
90
+ it "responds to #id with a string starting with '55'" do
91
+ expect(subject.id).to match /\A55/
92
+ end
93
+
94
+ it "responds to #mobile_country_code with '724'" do
95
+ expect(subject.mobile_country_code).to eq '724'
96
+ end
97
+
98
+ it "responds to #dialing_code with '55'" do
99
+ expect(subject.dialing_code).to eq '55'
100
+ end
101
+
102
+ it "responds to #iso_3166_country_code with 'BR'" do
103
+ expect(subject.iso_3166_country_code).to eq 'BR'
104
+ end
105
+ end
106
+
107
+ shared_examples "of detection from a request made from a Claro network" do
108
+ it "responds to #mobile_network_brand with a string containing 'Claro'" do
109
+ expect(subject.mobile_network_brand).to match /\AClaro/
110
+ end
111
+ end
112
+
113
+ context "from a request made from Telcel México" do
114
+
115
+ subject do
116
+ described_class.new_from_request(build :mobile_request_from_telcel_mexico)
117
+ end
118
+
119
+ include_examples "of detection from a valid request"
120
+ include_examples "of detection from a request made from a mexican mobile network"
121
+
122
+ it "responds to #mobile_network_brand with 'Telcel'" do
123
+ expect(subject.mobile_network_brand).to eq 'Telcel'
124
+ end
125
+
126
+ it "responds to #mobile_network_operator with 'América Móvil'" do
127
+ expect(subject.mobile_network_operator).to eq 'América Móvil'
128
+ end
129
+
130
+ end
131
+
132
+ context "from a request made from Claro Argentina" do
133
+
134
+ subject do
135
+ described_class.new_from_request(build :mobile_request_from_claro_argentina)
136
+ end
137
+
138
+ include_examples "of detection from a valid request"
139
+ include_examples "of detection from a request made from an argentinian mobile network"
140
+ include_examples "of detection from a request made from a Claro network"
141
+
142
+ it "responds to #mobile_network_operator with 'AMX Argentina S.A.'" do
143
+ expect(subject.mobile_network_operator).to eq 'AMX Argentina S.A.'
144
+ end
145
+
146
+ end
147
+
148
+ context "from a request made from Claro Brasil" do
149
+
150
+ subject do
151
+ described_class.new_from_request(build :mobile_request_from_claro_brasil)
152
+ end
153
+
154
+ include_examples "of detection from a valid request"
155
+ include_examples "of detection from a request made from a brazilian mobile network"
156
+ include_examples "of detection from a request made from a Claro network"
157
+
158
+ it "responds to #mobile_network_operator with 'Claro'" do
159
+ expect(subject.mobile_network_operator).to eq 'Claro'
160
+ end
161
+ end
162
+
163
+ end
164
+
165
+ end
@@ -0,0 +1,79 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'mobile_subscriber'
3
+ require 'byebug'
4
+ require 'factory_girl'
5
+ require 'rack'
6
+
7
+ RSpec.configure do |config|
8
+ # The settings below are suggested to provide a good initial experience
9
+ # with RSpec, but feel free to customize to your heart's content.
10
+
11
+ # These two settings work together to allow you to limit a spec run
12
+ # to individual examples or groups you care about by tagging them with
13
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
14
+ # get run.
15
+ config.filter_run :focus
16
+ config.run_all_when_everything_filtered = true
17
+
18
+ # Many RSpec users commonly either run the entire suite or an individual
19
+ # file, and it's useful to allow more verbose output when running an
20
+ # individual spec file.
21
+ if config.files_to_run.one?
22
+ # Use the documentation formatter for detailed output,
23
+ # unless a formatter has already been configured
24
+ # (e.g. via a command-line flag).
25
+ config.default_formatter = 'doc'
26
+ end
27
+
28
+ # Print the 5 slowest examples and example groups at the
29
+ # end of the spec run, to help surface which specs are running
30
+ # particularly slow.
31
+ config.profile_examples = 5
32
+
33
+ # Run specs in random order to surface order dependencies. If you find an
34
+ # order dependency and want to debug it, you can fix the order by providing
35
+ # the seed, which is printed after each run.
36
+ # --seed 1234
37
+ config.order = :random
38
+
39
+ # Seed global randomization in this process using the `--seed` CLI option.
40
+ # Setting this allows you to use `--seed` to deterministically reproduce
41
+ # test failures related to randomization by passing the same `--seed` value
42
+ # as the one that triggered the failure.
43
+ Kernel.srand config.seed
44
+
45
+ # rspec-expectations config goes here. You can use an alternate
46
+ # assertion/expectation library such as wrong or the stdlib/minitest
47
+ # assertions if you prefer.
48
+ config.expect_with :rspec do |expectations|
49
+ # Enable only the newer, non-monkey-patching expect syntax.
50
+ # For more details, see:
51
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
52
+ expectations.syntax = :expect
53
+ end
54
+
55
+ # rspec-mocks config goes here. You can use an alternate test double
56
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
57
+ config.mock_with :rspec do |mocks|
58
+ # Enable only the newer, non-monkey-patching expect syntax.
59
+ # For more details, see:
60
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
61
+ mocks.syntax = :expect
62
+
63
+ # Prevents you from mocking or stubbing a method that does not exist on
64
+ # a real object. This is generally recommended.
65
+ mocks.verify_partial_doubles = true
66
+ end
67
+
68
+ config.raise_errors_for_deprecations!
69
+
70
+
71
+
72
+ # Allow to use the FactoryGirl methods (build, create, build_stubbed)
73
+ # directly on specs, instead of prefacing them with "FactoryGirl":
74
+ config.include FactoryGirl::Syntax::Methods
75
+
76
+
77
+ Dir["spec/factories/*.rb"].each { |f| load f }
78
+
79
+ end
@@ -0,0 +1,4 @@
1
+ module MobileSubscriber
2
+ # Diccionario de Mobile Country Codes => ISO country codes:
3
+ MCC_ISO_COUNTRY_CODES = <%= @mcc_iso_country_codes.inspect %>.with_indifferent_access.freeze
4
+ end
@@ -0,0 +1,4 @@
1
+ module MobileSubscriber
2
+ # Diccionario de MCC+MNC => Operator DATA:
3
+ OPERATOR_DATA = <%= @operator_data.inspect %>.with_indifferent_access.freeze
4
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mobile-subscriber
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha1
5
+ platform: ruby
6
+ authors:
7
+ - Roberto Quintanilla
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: factory_girl
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.5'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.5'
97
+ description: Mobile MSISDN detection & validation. Only useful whenever your'e a Mobile
98
+ Operator 3rd Party and receive MSISDN headers.
99
+ email:
100
+ - roberto.quintanilla@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Dockerfile
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - build-docker.sh
114
+ - fig.yml
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
119
+ - lib/mobile_subscriber/dictionaries/mobile_and_iso_country_codes.rb
120
+ - lib/mobile_subscriber/dictionaries/operator_data.rb
121
+ - lib/mobile_subscriber/isdn.rb
122
+ - lib/mobile_subscriber/version.rb
123
+ - mobile-subscriber.gemspec
124
+ - mobile_subscriber.thor
125
+ - spec/factories/requests.rb
126
+ - spec/mobile_subscriber_spec.rb
127
+ - spec/models/isdn_spec.rb
128
+ - spec/spec_helper.rb
129
+ - templates/mobile_and_iso_country_codes.rb.erb
130
+ - templates/operator_data.rb.erb
131
+ homepage: ''
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">"
147
+ - !ruby/object:Gem::Version
148
+ version: 1.3.1
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.2.2
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Mobile MSISDN detection & validation.
155
+ test_files:
156
+ - spec/factories/requests.rb
157
+ - spec/mobile_subscriber_spec.rb
158
+ - spec/models/isdn_spec.rb
159
+ - spec/spec_helper.rb