pl-operator-detector 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'faraday'
4
+
5
+ group :development do
6
+ gem "shoulda"
7
+ gem "rdoc"
8
+ gem "bundler"
9
+ gem "jeweler"
10
+ gem "vcr"
11
+ gem "webmock"
12
+ end
@@ -0,0 +1,55 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.0.0)
5
+ i18n (~> 0.6, >= 0.6.4)
6
+ minitest (~> 4.2)
7
+ multi_json (~> 1.3)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 0.3.37)
10
+ addressable (2.3.4)
11
+ atomic (1.1.10)
12
+ crack (0.4.0)
13
+ safe_yaml (~> 0.9.0)
14
+ faraday (0.8.7)
15
+ multipart-post (~> 1.1)
16
+ git (1.2.5)
17
+ i18n (0.6.4)
18
+ jeweler (1.8.4)
19
+ bundler (~> 1.0)
20
+ git (>= 1.2.5)
21
+ rake
22
+ rdoc
23
+ json (1.8.0)
24
+ minitest (4.7.5)
25
+ multi_json (1.7.7)
26
+ multipart-post (1.2.0)
27
+ rake (10.1.0)
28
+ rdoc (4.0.1)
29
+ json (~> 1.4)
30
+ safe_yaml (0.9.3)
31
+ shoulda (3.5.0)
32
+ shoulda-context (~> 1.0, >= 1.0.1)
33
+ shoulda-matchers (>= 1.4.1, < 3.0)
34
+ shoulda-context (1.1.4)
35
+ shoulda-matchers (2.2.0)
36
+ activesupport (>= 3.0.0)
37
+ thread_safe (0.1.0)
38
+ atomic
39
+ tzinfo (0.3.37)
40
+ vcr (2.5.0)
41
+ webmock (1.9.3)
42
+ addressable (>= 2.2.7)
43
+ crack (>= 0.3.2)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ bundler
50
+ faraday
51
+ jeweler
52
+ rdoc
53
+ shoulda
54
+ vcr
55
+ webmock
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Ernest Bursa
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ pl-operator-detector
2
+ ==============
3
+
4
+ [![Build Status](https://travis-ci.org/swistaczek/pl-operator-detector.png)](https://travis-ci.org/swistaczek/pl-operator-detector)
5
+
6
+ PlOperatorDetector is simple ruby wrapper arround few web services allowing user to check network name assigned to provided mobile phone number.
7
+
8
+ Usage example
9
+ --------------
10
+
11
+ ```ruby
12
+ > require 'pl-operator-detector'
13
+ => true
14
+ > PlOperatorDetector.new.find('696 666 333')
15
+ => {:number=>"48696666333", :operator_code=>"260 02", :operator=>"PTC / T-Mobile"}
16
+ # OR - :operator_code is optional response
17
+ => {:number=>"48696666333", :operator=>"PTC / T-Mobile"}
18
+ ```
19
+
20
+
21
+
22
+ Contributing to pl-operator-detector
23
+ --------------
24
+
25
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
26
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
27
+ * Fork the project.
28
+ * Start a feature/bugfix branch.
29
+ * Commit and push until you are happy with your contribution.
30
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
31
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
32
+
33
+ Copyright
34
+ --------------
35
+
36
+ Copyright (c) 2013 Ernest Bursa. See LICENSE.txt for
37
+ further details.
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "pl-operator-detector"
18
+ gem.homepage = "http://github.com/swistaczek/pl-operator-detector"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Ruby interface for identifying network operator for provided phone number}
21
+ gem.description = %Q{PlOperatorDetector is simple ruby wrapper arround few web services allowing user to check network name assigned to provided mobile phone number.}
22
+ gem.email = "ernest@bzdury.pl"
23
+ gem.authors = ["Ernest Bursa"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'rdoc/task'
38
+ Rake::RDocTask.new do |rdoc|
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ rdoc.rdoc_dir = 'rdoc'
42
+ rdoc.title = "pl-operator-detector #{version}"
43
+ rdoc.rdoc_files.include('README*')
44
+ rdoc.rdoc_files.include('lib/**/*.rb')
45
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,79 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://download.t-mobile.pl/updir/updir.cgi?msisdn=48790777777
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Mozilla/15.0.2.0 (Windows XP) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/2.0.27.0
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - ! '*/*'
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: !binary |-
20
+ T0s=
21
+ headers:
22
+ !binary "RGF0ZQ==":
23
+ - !binary |-
24
+ U2F0LCAyOSBKdW4gMjAxMyAyMzo0NjoxOSBHTVQ=
25
+ !binary "U2VydmVy":
26
+ - !binary |-
27
+ QXBhY2hl
28
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
29
+ - !binary |-
30
+ Y2h1bmtlZA==
31
+ !binary "Q29udGVudC1UeXBl":
32
+ - !binary |-
33
+ dGV4dC9odG1sOyBjaGFyc2V0PUlTTy04ODU5LTI=
34
+ !binary "Q29udGVudC1MYW5ndWFnZQ==":
35
+ - !binary |-
36
+ cGw=
37
+ body:
38
+ encoding: ASCII-8BIT
39
+ string: !binary |-
40
+ PGh0bWw+PGhlYWQ+DQo8bWV0YSBuYW1lPSJWSTYwX2RlZmF1bHRDbGllbnRT
41
+ Y3JpcHQiIGNvbnRlbnQ9IkphdmFTY3JpcHQiPg0KPG1ldGEgaHR0cC1lcXVp
42
+ dj0iQ29udGVudC1UeXBlIiBjb250ZW50PSJ0ZXh0L2h0bWw7IGNo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3RkPjx0ZD5QNDwvdGQ+Cjwv
75
+ dGFibGU+PGJyLz4KDQo8L3RkPg0KPC90cj4NCjwvdGJvZHk+PC90YWJsZT4N
76
+ Cg0KDQoJPC9mb3JtPg0KDQo8L2JvZHk+PC9odG1sPg==
77
+ http_version:
78
+ recorded_at: Sat, 29 Jun 2013 23:46:32 GMT
79
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,79 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://download.t-mobile.pl/updir/updir.cgi?msisdn=48602900000
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Opera/9.0 (Windows NT 6.0) AppleWebKit/537.36 (KHTML, like Gecko) Opera/19.0
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - ! '*/*'
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: !binary |-
20
+ T0s=
21
+ headers:
22
+ !binary "RGF0ZQ==":
23
+ - !binary |-
24
+ U2F0LCAyOSBKdW4gMjAxMyAyMzo0NjoyMCBHTVQ=
25
+ !binary "U2VydmVy":
26
+ - !binary |-
27
+ QXBhY2hl
28
+ !binary "VHJhbnNmZXItRW5jb2Rpbmc=":
29
+ - !binary |-
30
+ Y2h1bmtlZA==
31
+ !binary "Q29udGVudC1UeXBl":
32
+ - !binary |-
33
+ dGV4dC9odG1sOyBjaGFyc2V0PUlTTy04ODU5LTI=
34
+ !binary "Q29udGVudC1MYW5ndWFnZQ==":
35
+ - !binary |-
36
+ cGw=
37
+ body:
38
+ encoding: ASCII-8BIT
39
+ string: !binary |-
40
+ PGh0bWw+PGhlYWQ+DQo8bWV0YSBuYW1lPSJWSTYwX2RlZmF1bHRDbGllbnRT
41
+ Y3JpcHQiIGNvbnRlbnQ9IkphdmFTY3JpcHQiPg0KPG1ldGEgaHR0cC1lcXVp
42
+ dj0iQ29udGVudC1UeXBlIiBjb250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jxiPk9wZXJhdG9yOjwvYj48L3RkPjx0ZD5QVEM8L3RkPgo8
75
+ L3RhYmxlPjxici8+Cg0KPC90ZD4NCjwvdHI+DQo8L3Rib2R5PjwvdGFibGU+
76
+ DQoNCg0KCTwvZm9ybT4NCg0KPC9ib2R5PjwvaHRtbD4=
77
+ http_version:
78
+ recorded_at: Sat, 29 Jun 2013 23:46:33 GMT
79
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+ require 'faraday'
3
+ require 'pl-operator-detector/operator_name'
4
+ require 'pl-operator-detector/custom_user_agent'
5
+ require 'pl-operator-detector/t_mobile'
6
+ require 'pl-operator-detector/w_jakiej_sieci'
7
+ require 'pl-operator-detector/gate_sms'
8
+
9
+ class PlOperatorDetector
10
+
11
+ class ProcessingError < StandardError ; end
12
+
13
+ def initialize
14
+ @services = [ TMobile.new, WJakiejSieci.new, GateSms.new ]
15
+ end
16
+
17
+ def find(number)
18
+ number = number.split.join.to_i.to_s
19
+ number = "48" + number if number.size == 9
20
+
21
+ raise ArgumentError, "Please specify 9 or 11 digit number (including country code, for example: 48501501501)" if number.to_s.size < 9 || number.to_s.size > 11
22
+ raise ArgumentError, "Currently we support only polish numbers" if number.to_s.size == 11 && number[0..1] != "48"
23
+
24
+ @services.each do |service|
25
+ begin
26
+ @rsp = service.process(number)
27
+ break if @rsp
28
+ rescue Faraday::Error::TimeoutError, ProcessingError => e
29
+ next
30
+ end
31
+ end
32
+
33
+ raise ProcessingError, "Could not process given number" unless @rsp
34
+ @rsp[:operator] = OperatorName.normalize(@rsp[:operator]) if @rsp[:operator]
35
+ @rsp
36
+ end
37
+
38
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ class PlOperatorDetector
3
+ class CustomUserAgent
4
+
5
+ BROWSERS = %w(Opera Chrome Firefox IE)
6
+ PLATFORMS = ["Windows NT 6.0", "Windows XP", "X11", "Macintosh"]
7
+ ENGINES = ["AppleWebKit/537.36 (KHTML, like Gecko)", "Webkit"]
8
+ VENDOR = ["Mozilla", "Opera"]
9
+
10
+ class << self
11
+
12
+ def get_user_agent
13
+ "#{VENDOR[rand(VENDOR.size)]}/#{random_version} (#{PLATFORMS[rand(PLATFORMS.size)]}) #{ENGINES[rand(ENGINES.size)]} #{BROWSERS[rand(BROWSERS.size)]}/#{random_version}"
14
+ end
15
+
16
+ def random_version
17
+ (1+rand(2)).times.map {|x| (1+rand(20*(x+1))).round(1) }.join('.')
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ require 'faraday'
3
+
4
+ class PlOperatorDetector
5
+ class GateSms
6
+
7
+ def initialize
8
+ @conn = Faraday.new(:url => 'http://www.gatesms.eu') do |faraday|
9
+ faraday.request :url_encoded
10
+ faraday.adapter Faraday.default_adapter
11
+ faraday.headers["User-Agent"] = CustomUserAgent.get_user_agent
12
+ faraday.headers["Cookie"] = "hz_amChecked=1;gatesms_cook=1;"
13
+ end
14
+ end
15
+
16
+ def process(number)
17
+ number = number.gsub(/^48/, '')
18
+ @conn.get("sprawdz_operatora")
19
+ { number: number }.merge(process_response(@conn.get("sms_api.php", { spr_operator: number }).body))
20
+ rescue
21
+ raise PlOperatorDetector::ProcessingError, "Could not process given number"
22
+ end
23
+
24
+ private
25
+
26
+ def process_response(response)
27
+ raise PlOperatorDetector::ProcessingError, "Could not process given number" if response.match(/Chwilowe/)
28
+ { provider: response }
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ class PlOperatorDetector
3
+ class OperatorName
4
+
5
+ PATTERNS = {
6
+ play: [ /^P4/, /^Play/ ],
7
+ orange: [ /^Orange/ ],
8
+ tmobile: [ /^PTC/, /^T-Mobile/ ],
9
+ plus: [ /^Plus/ ],
10
+ heyah: [ /^T-Mobile \(Heyah\)/, /^Heyah/ ],
11
+ red_bull_mobile: [], # unable to identify, ex. 790666666
12
+ cyfrowy_polsat: [ /^Cyfrowy Polsat/ ],
13
+ m_pay: [], # unable to identify
14
+ novum: [], # unable to identify
15
+ w_rodzinie: [ /^CenterNet/ ],
16
+ carrefour_mova: [], # unable to identify
17
+ tu_biedronka: [],
18
+ fm_group_mobile: [],
19
+ lycamobile: [],
20
+ vectone: [],
21
+ mbank_mobile: [],
22
+ snickers_mobile: [],
23
+ netia_mobile: [],
24
+ virgin_mobile: [] # unable to identify (using P4)
25
+ }
26
+
27
+ class << self
28
+ def normalize(input)
29
+ @result = nil
30
+ PATTERNS.each do |k, v|
31
+ v.each do |pattern|
32
+ if input =~ pattern
33
+ @result = k
34
+ break
35
+ end
36
+ end
37
+ break if @result
38
+ end
39
+ @result
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+ require 'faraday'
3
+ class PlOperatorDetector
4
+ class TMobile
5
+
6
+ def initialize
7
+ @conn = Faraday.new(:url => 'http://download.t-mobile.pl/updir/') do |faraday|
8
+ faraday.request :url_encoded
9
+ faraday.adapter Faraday.default_adapter
10
+ faraday.headers["User-Agent"] = CustomUserAgent.get_user_agent
11
+ end
12
+ end
13
+
14
+ def process(number)
15
+ rsp = @conn.get 'updir.cgi', { msisdn: number }
16
+ { number: number }.merge process_response(rsp.body)
17
+ end
18
+
19
+ private
20
+
21
+ def process_response(response)
22
+ rslt = { }
23
+
24
+ match_opcode = response.match(/<b>Kod sieci:<\/b><\/td><td>([\d\s]+)<\/td>/)
25
+ rslt[:operator_code] = match_opcode[1] if match_opcode && match_opcode[1]
26
+
27
+ match_opstr = response.match(/<b>Operator:<\/b><\/td><td>(.{2,26})<\/td>/)
28
+ if match_opstr && match_opstr[1]
29
+ rslt[:operator] = match_opstr[1]
30
+ else
31
+ raise PlOperatorDetector::ProcessingError, "Could not process given number"
32
+ end
33
+ rslt
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ require 'faraday'
3
+ class PlOperatorDetector
4
+ class WJakiejSieci
5
+
6
+ def initialize
7
+ @conn = Faraday.new(:url => 'http://www.wjakiejsieci.pl/') do |faraday|
8
+ faraday.request :url_encoded
9
+ faraday.adapter Faraday.default_adapter
10
+ faraday.headers["User-Agent"] = CustomUserAgent.get_user_agent
11
+ end
12
+ end
13
+
14
+ def process(number)
15
+ prefix = number.size == 11 ? "+#{number[0..1]}" : "+48"
16
+ pnumbr = number.size == 11 ? number[2..12] : number
17
+
18
+ rsp = @conn.post '/', { prefix: prefix, phone: pnumbr }
19
+ { number: number }.merge process_response(rsp.body)
20
+ end
21
+
22
+ private
23
+
24
+ def process_response(response)
25
+ rslt = { }
26
+
27
+ match_opstr = response.match(/Operator: <strong>(.{2,20})<\/strong><\/p>/)
28
+ if match_opstr && match_opstr[1]
29
+ rslt[:operator] = match_opstr[1]
30
+ else
31
+ raise PlOperatorDetector::ProcessingError, "Could not process given number"
32
+ end
33
+ rslt
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,75 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "pl-operator-detector"
8
+ s.version = "1.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ernest Bursa"]
12
+ s.date = "2013-06-29"
13
+ s.description = "PlOperatorDetector is simple ruby wrapper arround few web services allowing user to check network name assigned to provided mobile phone number."
14
+ s.email = "ernest@bzdury.pl"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "fixtures/vcr_cassettes/test_play.yml",
28
+ "fixtures/vcr_cassettes/test_tmobile.yml",
29
+ "lib/pl-operator-detector.rb",
30
+ "lib/pl-operator-detector/custom_user_agent.rb",
31
+ "lib/pl-operator-detector/gate_sms.rb",
32
+ "lib/pl-operator-detector/operator_name.rb",
33
+ "lib/pl-operator-detector/t_mobile.rb",
34
+ "lib/pl-operator-detector/w_jakiej_sieci.rb",
35
+ "pl-operator-detector.gemspec",
36
+ "test/helper.rb",
37
+ "test/test_pl-operator-detector.rb"
38
+ ]
39
+ s.homepage = "http://github.com/swistaczek/pl-operator-detector"
40
+ s.licenses = ["MIT"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = "1.8.25"
43
+ s.summary = "Ruby interface for identifying network operator for provided phone number"
44
+
45
+ if s.respond_to? :specification_version then
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<faraday>, [">= 0"])
50
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
51
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
52
+ s.add_development_dependency(%q<bundler>, [">= 0"])
53
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
54
+ s.add_development_dependency(%q<vcr>, [">= 0"])
55
+ s.add_development_dependency(%q<webmock>, [">= 0"])
56
+ else
57
+ s.add_dependency(%q<faraday>, [">= 0"])
58
+ s.add_dependency(%q<shoulda>, [">= 0"])
59
+ s.add_dependency(%q<rdoc>, [">= 0"])
60
+ s.add_dependency(%q<bundler>, [">= 0"])
61
+ s.add_dependency(%q<jeweler>, [">= 0"])
62
+ s.add_dependency(%q<vcr>, [">= 0"])
63
+ s.add_dependency(%q<webmock>, [">= 0"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<faraday>, [">= 0"])
67
+ s.add_dependency(%q<shoulda>, [">= 0"])
68
+ s.add_dependency(%q<rdoc>, [">= 0"])
69
+ s.add_dependency(%q<bundler>, [">= 0"])
70
+ s.add_dependency(%q<jeweler>, [">= 0"])
71
+ s.add_dependency(%q<vcr>, [">= 0"])
72
+ s.add_dependency(%q<webmock>, [">= 0"])
73
+ end
74
+ end
75
+
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'vcr'
4
+
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'test/unit'
13
+ require 'shoulda'
14
+
15
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
16
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
17
+ require 'pl-operator-detector'
18
+
19
+ class Test::Unit::TestCase
20
+ end
21
+
22
+ VCR.configure do |c|
23
+ c.cassette_library_dir = 'fixtures/vcr_cassettes'
24
+ c.hook_into :webmock # or :fakeweb
25
+ end
@@ -0,0 +1,18 @@
1
+ require 'helper'
2
+ require 'vcr'
3
+
4
+ class TestPlOperatorDetector < Test::Unit::TestCase
5
+ should "identify P4 phone number" do
6
+ VCR.use_cassette('test_play') do
7
+ @detector = PlOperatorDetector.new
8
+ assert_equal(@detector.find('790 777 777')[:operator], :play)
9
+ end
10
+ end
11
+
12
+ should "identify TMobile (PTC) phone number" do
13
+ VCR.use_cassette('test_tmobile') do
14
+ @detector = PlOperatorDetector.new
15
+ assert_equal(@detector.find('602 900 000')[:operator], :tmobile)
16
+ end
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pl-operator-detector
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ernest Bursa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: shoulda
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: jeweler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: vcr
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: webmock
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: PlOperatorDetector is simple ruby wrapper arround few web services allowing
127
+ user to check network name assigned to provided mobile phone number.
128
+ email: ernest@bzdury.pl
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files:
132
+ - LICENSE.txt
133
+ - README.md
134
+ files:
135
+ - .document
136
+ - Gemfile
137
+ - Gemfile.lock
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - VERSION
142
+ - fixtures/vcr_cassettes/test_play.yml
143
+ - fixtures/vcr_cassettes/test_tmobile.yml
144
+ - lib/pl-operator-detector.rb
145
+ - lib/pl-operator-detector/custom_user_agent.rb
146
+ - lib/pl-operator-detector/gate_sms.rb
147
+ - lib/pl-operator-detector/operator_name.rb
148
+ - lib/pl-operator-detector/t_mobile.rb
149
+ - lib/pl-operator-detector/w_jakiej_sieci.rb
150
+ - pl-operator-detector.gemspec
151
+ - test/helper.rb
152
+ - test/test_pl-operator-detector.rb
153
+ homepage: http://github.com/swistaczek/pl-operator-detector
154
+ licenses:
155
+ - MIT
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ segments:
167
+ - 0
168
+ hash: -2199874905864588331
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ! '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ requirements: []
176
+ rubyforge_project:
177
+ rubygems_version: 1.8.25
178
+ signing_key:
179
+ specification_version: 3
180
+ summary: Ruby interface for identifying network operator for provided phone number
181
+ test_files: []