rudester516-netnumber 0.0.3
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.
- data/History.txt +4 -0
- data/Manifest.txt +25 -0
- data/README.txt +48 -0
- data/Rakefile +4 -0
- data/lib/netnumber/version.rb +9 -0
- data/lib/netnumber.rb +88 -0
- data/netnumber.gemspec +23 -0
- data/test/test_netnumber.rb +11 -0
- metadata +70 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
PostInstall.txt
|
5
|
+
README.txt
|
6
|
+
Rakefile
|
7
|
+
config/hoe.rb
|
8
|
+
config/requirements.rb
|
9
|
+
lib/netnumber.rb
|
10
|
+
lib/netnumber/version.rb
|
11
|
+
script/console
|
12
|
+
script/destroy
|
13
|
+
script/generate
|
14
|
+
script/txt2html
|
15
|
+
setup.rb
|
16
|
+
tasks/deployment.rake
|
17
|
+
tasks/environment.rake
|
18
|
+
tasks/website.rake
|
19
|
+
test/test_helper.rb
|
20
|
+
test/test_netnumber.rb
|
21
|
+
website/index.html
|
22
|
+
website/index.txt
|
23
|
+
website/javascripts/rounded_corners_lite.inc.js
|
24
|
+
website/stylesheets/screen.css
|
25
|
+
website/template.html.erb
|
data/README.txt
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= netnumber
|
2
|
+
|
3
|
+
* FIX (url)
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
FIX (describe your package)
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIX (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* FIX (sudo gem install, anything else)
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2008 FIXME full name
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/lib/netnumber.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'dnsruby'
|
2
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
3
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
4
|
+
|
5
|
+
class Netnumber
|
6
|
+
|
7
|
+
# hash of Tapioca Mobile supported wireless carriers, mapping the NNIDs to the carrier IDs
|
8
|
+
NNID_TO_CARRIER_ID = {
|
9
|
+
"100313" => 1, # Verizon Wireless
|
10
|
+
"100321" => 2, # AT&T Wireless
|
11
|
+
"100335" => 5, # T-Mobile USA
|
12
|
+
"100343" => 3 # Sprint Spectrum
|
13
|
+
}
|
14
|
+
|
15
|
+
WIRELESS_NNIDS = NNID_TO_CARRIER_ID.keys
|
16
|
+
|
17
|
+
attr_reader :nnid, :response, :error_message
|
18
|
+
|
19
|
+
def initialize(mobile_phone)
|
20
|
+
@mobile_phone = mobile_phone
|
21
|
+
@response = query_netnumber_service(@mobile_phone)
|
22
|
+
end
|
23
|
+
|
24
|
+
def carrier_id
|
25
|
+
@nnid and NNID_TO_CARRIER_ID[@nnid]
|
26
|
+
end
|
27
|
+
|
28
|
+
# query the NetNumber service
|
29
|
+
def query_netnumber_service(mobile_phone)
|
30
|
+
services = ["65.214.42.88", "65.216.77.208"]
|
31
|
+
#services = ["0.0.0.0", "0.0.0.0"]
|
32
|
+
|
33
|
+
# transform the phone number into reverse dot notation format
|
34
|
+
mobile_phone = "1" << mobile_phone unless mobile_phone[0,1] == '1'
|
35
|
+
mobile_phone.reverse!
|
36
|
+
if mobile_phone.length == 11
|
37
|
+
index = 1
|
38
|
+
for k in 1..11
|
39
|
+
mobile_phone.insert(index, '.')
|
40
|
+
index += 2
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# randomly pick a spot on the services edge array, then go through the rest of the array if the current service fails
|
45
|
+
current_index = rand(services.size)
|
46
|
+
for i in 1..services.length
|
47
|
+
begin
|
48
|
+
resolver = Dnsruby::Resolver.new(:nameserver => services[current_index], :query_timeout => 15)
|
49
|
+
@response = resolver.query(mobile_phone,'ANY')
|
50
|
+
@nnid = decode_nnid_from_answer(@response)
|
51
|
+
break
|
52
|
+
# if the phone number format was incorrect, a NXDomain exception is thrown by dnsruby
|
53
|
+
rescue Dnsruby::NXDomain
|
54
|
+
@response = 0
|
55
|
+
break
|
56
|
+
# dnsruby is unable to query NetNumber due to a timeout and/or service failure
|
57
|
+
rescue Dnsruby::ResolvError, Dnsruby::ResolvTimeout
|
58
|
+
@error_message = "We are unable to determine your carrier at this time. Please select your carrier from the list below."
|
59
|
+
end
|
60
|
+
|
61
|
+
if current_index == services.size - 1
|
62
|
+
current_index = 0
|
63
|
+
else
|
64
|
+
current_index += 1
|
65
|
+
end
|
66
|
+
end # end looping thru services array
|
67
|
+
|
68
|
+
resolver.close
|
69
|
+
return @response
|
70
|
+
end
|
71
|
+
|
72
|
+
# checks if this company is one of the wireless carriers
|
73
|
+
def valid?
|
74
|
+
WIRELESS_NNIDS.include? nnid
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
# once a valid response is received from NetNumber, we need to pull just the six digit NNID from the response
|
79
|
+
def decode_nnid_from_answer(response)
|
80
|
+
nnid = ""
|
81
|
+
response.each_answer {|answer| nnid << answer.rdata_to_string}
|
82
|
+
readable_nnid = ""
|
83
|
+
for j in 8..nnid.length
|
84
|
+
readable_nnid << nnid[j,1] if j % 2 == 0
|
85
|
+
end
|
86
|
+
return readable_nnid
|
87
|
+
end
|
88
|
+
end
|
data/netnumber.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "netnumber"
|
3
|
+
s.version = "0.0.3"
|
4
|
+
s.date = "2008-09-23"
|
5
|
+
s.summary = "Object model interface to a git repo"
|
6
|
+
s.email = "rsombillo@gmail.com"
|
7
|
+
s.homepage = "http://github.com/rudester516"
|
8
|
+
s.description = "A ruby gem that uses the NetNumber interface to determine the service provider of a phone number."
|
9
|
+
s.author = "Rudy A. Sombillo"
|
10
|
+
s.files = s.files = ["History.txt",
|
11
|
+
"Manifest.txt",
|
12
|
+
"README.txt",
|
13
|
+
"Rakefile",
|
14
|
+
"netnumber.gemspec",
|
15
|
+
"lib/netnumber/version.rb",
|
16
|
+
"lib/netnumber.rb"]
|
17
|
+
s.test_files = "test/test_netnumber.rb"
|
18
|
+
s.has_rdoc = true
|
19
|
+
s.rdoc_options = ["--main", "README.txt"]
|
20
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
21
|
+
s.add_dependency "dnsruby", ">= 1.1"
|
22
|
+
end
|
23
|
+
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rudester516-netnumber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rudy A. Sombillo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-09-23 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: dnsruby
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "1.1"
|
23
|
+
version:
|
24
|
+
description: A ruby gem that uses the NetNumber interface to determine the service provider of a phone number.
|
25
|
+
email: rsombillo@gmail.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- History.txt
|
32
|
+
- Manifest.txt
|
33
|
+
- README.txt
|
34
|
+
files:
|
35
|
+
- History.txt
|
36
|
+
- Manifest.txt
|
37
|
+
- README.txt
|
38
|
+
- Rakefile
|
39
|
+
- netnumber.gemspec
|
40
|
+
- lib/netnumber/version.rb
|
41
|
+
- lib/netnumber.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/rudester516
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --main
|
47
|
+
- README.txt
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.2.0
|
66
|
+
signing_key:
|
67
|
+
specification_version: 2
|
68
|
+
summary: Object model interface to a git repo
|
69
|
+
test_files:
|
70
|
+
- test/test_netnumber.rb
|