npa_lookup 1.2.0 → 1.3.0
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/VERSION +1 -1
- data/bin/lookup +35 -11
- data/lib/npa_lookup.rb +35 -11
- data/npa_lookup.gemspec +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
data/bin/lookup
CHANGED
@@ -7,6 +7,16 @@ require 'terminal-table/import' #http://vision-media.ca/resources/ruby/ruby-term
|
|
7
7
|
|
8
8
|
SPACES = "18"
|
9
9
|
|
10
|
+
#Make sure we have numbers
|
11
|
+
def safeParse(strToParse)
|
12
|
+
if strToParse =~ /\A\d+\Z/
|
13
|
+
return strToParse.to_s
|
14
|
+
else
|
15
|
+
raise Exception
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
#colorize tables
|
10
20
|
def colorize(text, color_code,how_many_spaces)
|
11
21
|
"\e[#{color_code}m#{text}\e[#{how_many_spaces}C\033[0m\033[0m"
|
12
22
|
end
|
@@ -18,21 +28,29 @@ def blue(text,how_many_spaces); colorize(text, 34,how_many_spaces); end
|
|
18
28
|
def cyan(text,how_many_spaces); colorize(text, 36,how_many_spaces); end
|
19
29
|
def white(test,how_many_spaces);colorize(test,37,how_many_spaces);end
|
20
30
|
|
31
|
+
# format arguments for API call
|
21
32
|
def parse_args(i)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
begin
|
34
|
+
case safeParse(i).length
|
35
|
+
when 3
|
36
|
+
return i
|
37
|
+
when 6
|
38
|
+
i=i.dup
|
39
|
+
i.insert(3, '/')
|
40
|
+
when 10
|
41
|
+
return i
|
42
|
+
else
|
43
|
+
puts "Error {NumberError}"
|
44
|
+
exit!
|
45
|
+
end
|
46
|
+
rescue Exception
|
47
|
+
puts "#{i} is invalid"
|
32
48
|
exit!
|
33
49
|
end
|
34
50
|
end
|
35
51
|
|
52
|
+
## Take in args and hit API
|
53
|
+
|
36
54
|
ARGV.each do|a|
|
37
55
|
uri = URI.parse("http://digits.cloudvox.com/#{parse_args(a)}.json")
|
38
56
|
response = Net::HTTP.get_response(uri)
|
@@ -43,20 +61,26 @@ ARGV.each do|a|
|
|
43
61
|
exit!
|
44
62
|
end
|
45
63
|
|
64
|
+
## Simplify JSON structure
|
65
|
+
|
46
66
|
data = jsonObject['allocation']
|
47
67
|
|
68
|
+
## Start table (terminal-table)
|
48
69
|
t = table ['Data', 'Value']
|
49
70
|
t << [red("NPA","18"),yellow("#{data['npa']}",SPACES)]
|
50
71
|
|
72
|
+
## If nxx is not there don't include it in table
|
51
73
|
if data['nxx']!=nil; t << [red("Nxx","18"),yellow("#{data['nxx']}",SPACES)];end
|
52
74
|
|
75
|
+
## If ratecenter_formatted is not there don't include it in table
|
53
76
|
if data['ratecenter_formatted'] !=nil&&data['ratecenter_formatted']!=""; t << [red("City","18"),yellow("#{data['ratecenter_formatted']}",SPACES)]; end
|
54
77
|
|
55
78
|
t << [red("State","18"),yellow("#{data['region']}",SPACES)]
|
56
79
|
t << [red("Status","18"),yellow("#{data['status'].capitalize}",SPACES)]
|
57
80
|
|
81
|
+
## If carrier_name is not there don't include it in table
|
58
82
|
if data['carrier_name'] !=nil; t << [red("Carrier","18"),yellow("#{data['carrier_name']}",SPACES)]; end
|
59
83
|
|
60
84
|
puts t
|
61
|
-
puts "\n
|
85
|
+
puts "\n"
|
62
86
|
end
|
data/lib/npa_lookup.rb
CHANGED
@@ -7,6 +7,16 @@ require 'terminal-table/import' #http://vision-media.ca/resources/ruby/ruby-term
|
|
7
7
|
|
8
8
|
SPACES = "18"
|
9
9
|
|
10
|
+
#Make sure we have numbers
|
11
|
+
def safeParse(strToParse)
|
12
|
+
if strToParse =~ /\A\d+\Z/
|
13
|
+
return strToParse.to_s
|
14
|
+
else
|
15
|
+
raise Exception
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
#colorize tables
|
10
20
|
def colorize(text, color_code,how_many_spaces)
|
11
21
|
"\e[#{color_code}m#{text}\e[#{how_many_spaces}C\033[0m\033[0m"
|
12
22
|
end
|
@@ -18,21 +28,29 @@ def blue(text,how_many_spaces); colorize(text, 34,how_many_spaces); end
|
|
18
28
|
def cyan(text,how_many_spaces); colorize(text, 36,how_many_spaces); end
|
19
29
|
def white(test,how_many_spaces);colorize(test,37,how_many_spaces);end
|
20
30
|
|
31
|
+
# format arguments for API call
|
21
32
|
def parse_args(i)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
begin
|
34
|
+
case safeParse(i).length
|
35
|
+
when 3
|
36
|
+
return i
|
37
|
+
when 6
|
38
|
+
i=i.dup
|
39
|
+
i.insert(3, '/')
|
40
|
+
when 10
|
41
|
+
return i
|
42
|
+
else
|
43
|
+
puts "Error {NumberError}"
|
44
|
+
exit!
|
45
|
+
end
|
46
|
+
rescue Exception
|
47
|
+
puts "#{i} is invalid"
|
32
48
|
exit!
|
33
49
|
end
|
34
50
|
end
|
35
51
|
|
52
|
+
## Take in args and hit API
|
53
|
+
|
36
54
|
ARGV.each do|a|
|
37
55
|
uri = URI.parse("http://digits.cloudvox.com/#{parse_args(a)}.json")
|
38
56
|
response = Net::HTTP.get_response(uri)
|
@@ -43,20 +61,26 @@ ARGV.each do|a|
|
|
43
61
|
exit!
|
44
62
|
end
|
45
63
|
|
64
|
+
## Simplify JSON structure
|
65
|
+
|
46
66
|
data = jsonObject['allocation']
|
47
67
|
|
68
|
+
## Start table (terminal-table)
|
48
69
|
t = table ['Data', 'Value']
|
49
70
|
t << [red("NPA","18"),yellow("#{data['npa']}",SPACES)]
|
50
71
|
|
72
|
+
## If nxx is not there don't include it in table
|
51
73
|
if data['nxx']!=nil; t << [red("Nxx","18"),yellow("#{data['nxx']}",SPACES)];end
|
52
74
|
|
75
|
+
## If ratecenter_formatted is not there don't include it in table
|
53
76
|
if data['ratecenter_formatted'] !=nil&&data['ratecenter_formatted']!=""; t << [red("City","18"),yellow("#{data['ratecenter_formatted']}",SPACES)]; end
|
54
77
|
|
55
78
|
t << [red("State","18"),yellow("#{data['region']}",SPACES)]
|
56
79
|
t << [red("Status","18"),yellow("#{data['status'].capitalize}",SPACES)]
|
57
80
|
|
81
|
+
## If carrier_name is not there don't include it in table
|
58
82
|
if data['carrier_name'] !=nil; t << [red("Carrier","18"),yellow("#{data['carrier_name']}",SPACES)]; end
|
59
83
|
|
60
84
|
puts t
|
61
|
-
puts "\n
|
85
|
+
puts "\n"
|
62
86
|
end
|
data/npa_lookup.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: npa_lookup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Dyer
|