docheck 1.0.1 → 1.1.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/README.rdoc +6 -6
- data/bin/docheck +24 -1
- data/docheck.gemspec +7 -4
- data/lib/docheck.rb +51 -50
- data/test/docheck_test.rb +31 -4
- data/version.rb +3 -0
- metadata +20 -7
- data/VERSION +0 -1
data/README.rdoc
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
= Docheck
|
2
|
-
|
2
|
+
Domain name availability checker. By default, It will return all available and registered domains.
|
3
3
|
|
4
4
|
|
5
5
|
== Requirements
|
@@ -16,17 +16,17 @@
|
|
16
16
|
== Usage
|
17
17
|
From the command line:
|
18
18
|
|
19
|
-
docheck google
|
19
|
+
docheck -n google
|
20
20
|
|
21
21
|
From the Ruby file or IRB.
|
22
22
|
|
23
23
|
require 'rubygems'
|
24
24
|
require 'docheck'
|
25
25
|
|
26
|
-
# Docheck only have two methods: print and fetch
|
27
|
-
Docheck.new('github').print
|
26
|
+
# Docheck only have two instance methods: print and fetch
|
27
|
+
Docheck::Application.new('github').print
|
28
28
|
# or
|
29
|
-
Docheck.new('github').fetch
|
29
|
+
Docheck::Application.new('github').fetch
|
30
30
|
|
31
31
|
|
32
32
|
== Author
|
@@ -36,4 +36,4 @@ Author:: {Kunto Aji Kristianto}[http://www.railsmine.net/] <kunto.aji.kr@gmail.c
|
|
36
36
|
|
37
37
|
== License
|
38
38
|
|
39
|
-
Copyright (c)
|
39
|
+
Copyright (c) 2010 Kunto Aji Kristianto, Docheck is released under the MIT license.
|
data/bin/docheck
CHANGED
@@ -7,4 +7,27 @@ rescue LoadError
|
|
7
7
|
require File.expand_path('../../lib/docheck.rb', __FILE__)
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
require 'optparse'
|
11
|
+
|
12
|
+
begin
|
13
|
+
OptionParser.new do |opts|
|
14
|
+
opts.banner = "Usage: docheck [basename]. Example: docheck google"
|
15
|
+
|
16
|
+
opts.on("-v", "--version", "Show version") do
|
17
|
+
puts "Docheck #{Docheck::VERSION}"
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on("-n", "--name NAME", "Execute domain name checker") do |name|
|
21
|
+
Docheck::Application.new(name).print
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on_tail("-h", "--help", "Show help") do
|
25
|
+
puts opts
|
26
|
+
exit
|
27
|
+
end
|
28
|
+
end.parse!
|
29
|
+
rescue OptionParser::InvalidOption
|
30
|
+
puts "Invalid option"
|
31
|
+
rescue OptionParser::MissingArgument
|
32
|
+
puts "Missing argument"
|
33
|
+
end
|
data/docheck.gemspec
CHANGED
@@ -1,14 +1,17 @@
|
|
1
|
+
require File.expand_path('../version.rb', __FILE__)
|
2
|
+
|
1
3
|
Gem::Specification.new do |spec|
|
2
4
|
spec.authors = 'Kunto Aji Kristianto'
|
3
5
|
spec.add_dependency('whois', '~> 1.3.8')
|
6
|
+
spec.add_development_dependency('shoulda')
|
4
7
|
spec.description = <<-EOF
|
5
|
-
|
8
|
+
Domain name availability checker.
|
6
9
|
EOF
|
7
10
|
spec.email = 'kunto.aji.kr@gmail.com'
|
8
11
|
spec.executables << 'docheck'
|
9
|
-
spec.extra_rdoc_files = ['README.rdoc', 'LICENSE'
|
12
|
+
spec.extra_rdoc_files = ['README.rdoc', 'LICENSE']
|
10
13
|
spec.files = ['.gitignore', 'docheck.gemspec', 'LICENSE',
|
11
|
-
'README.rdoc', '
|
14
|
+
'README.rdoc', 'version.rb', 'bin/docheck', 'lib/docheck.rb',
|
12
15
|
'test/docheck_test.rb', 'test/helper.rb']
|
13
16
|
spec.has_rdoc = true
|
14
17
|
spec.homepage = 'http://github.com/kuntoaji/docheck'
|
@@ -18,5 +21,5 @@ Gem::Specification.new do |spec|
|
|
18
21
|
spec.requirements << 'ruby-whois, v1.3.8 or greater'
|
19
22
|
spec.summary = 'Domain name availability checker.'
|
20
23
|
spec.test_files = ['test/docheck_test.rb', 'test/helper.rb']
|
21
|
-
spec.version =
|
24
|
+
spec.version = Docheck::VERSION
|
22
25
|
end
|
data/lib/docheck.rb
CHANGED
@@ -4,66 +4,67 @@
|
|
4
4
|
# Copyright:: Copyright (c) 2010 Kunto Aji Kristianto
|
5
5
|
# License:: Distributes under MIT license
|
6
6
|
|
7
|
+
require File.expand_path('../../version.rb', __FILE__)
|
7
8
|
require 'whois'
|
8
9
|
|
9
|
-
|
10
|
+
module Docheck
|
11
|
+
class Application
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
# DNS name of the generic top-level domain
|
14
|
+
# http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains
|
15
|
+
TLD = %w[aero asia biz cat com coop edu gov info
|
16
|
+
int jobs mil mobi museum name net org pro tel travel]
|
14
17
|
|
15
|
-
|
16
|
-
# registered domains
|
17
|
-
attr_reader :available_domains, :registered_domains
|
18
|
+
attr_reader :available_domains, :registered_domains
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
# base_name is sld (Second Level Domain) and
|
21
|
+
# converted to lower case.
|
22
|
+
def initialize(base_name)
|
23
|
+
@base_name = base_name.to_s.downcase
|
24
|
+
@available_domains = []
|
25
|
+
@registered_domains = []
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
28
|
+
# Print the fetch result.
|
29
|
+
def print
|
30
|
+
result = fetch
|
31
|
+
|
32
|
+
puts "\nDocheck Result\n"
|
33
|
+
puts "--------------\n"
|
34
|
+
puts "Available Domains:"
|
35
|
+
result.first.map{|domain_name| puts "- #{domain_name}"}
|
36
|
+
puts "\n"
|
37
|
+
puts "Registered Domains:"
|
38
|
+
result.last.map{|domain_name| puts "- #{domain_name}"}
|
39
|
+
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
41
|
+
# Check domain name availability
|
42
|
+
# and return the result as array.
|
43
|
+
#
|
44
|
+
# The first element of array will return all
|
45
|
+
# available domains as array.
|
46
|
+
#
|
47
|
+
# The last element of array will return all
|
48
|
+
# registered domains as array.
|
49
|
+
def fetch
|
50
|
+
TLD.each do |tld|
|
51
|
+
domain_name = "#{@base_name}.#{tld}"
|
52
|
+
begin
|
53
|
+
whois_domain = Whois.whois(domain_name)
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
if whois_domain.available?
|
56
|
+
@available_domains << domain_name
|
57
|
+
elsif whois_domain.registered?
|
58
|
+
@registered_domains << domain_name
|
59
|
+
end
|
60
|
+
rescue Timeout::Error
|
61
|
+
next
|
62
|
+
rescue
|
63
|
+
next
|
59
64
|
end
|
60
|
-
rescue Timeout::Error
|
61
|
-
next
|
62
|
-
rescue
|
63
|
-
next
|
64
65
|
end
|
65
|
-
end
|
66
66
|
|
67
|
-
|
67
|
+
return [@available_domains, @registered_domains]
|
68
|
+
end
|
68
69
|
end
|
69
70
|
end
|
data/test/docheck_test.rb
CHANGED
@@ -7,19 +7,46 @@ class TestDocheck < Test::Unit::TestCase
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
+
context "Docheck command" do
|
11
|
+
setup do
|
12
|
+
@docheck_bin = File.expand_path("../../bin/docheck", __FILE__)
|
13
|
+
end
|
14
|
+
|
15
|
+
should "shows version" do
|
16
|
+
assert_equal "Docheck #{Docheck::VERSION}\n", `ruby #{@docheck_bin} -v`
|
17
|
+
assert_equal "Docheck #{Docheck::VERSION}\n", `ruby #{@docheck_bin} --version`
|
18
|
+
end
|
19
|
+
|
20
|
+
should "executes domain name checker correctly" do
|
21
|
+
assert `ruby #{@docheck_bin} -n railsmine`
|
22
|
+
assert `ruby #{@docheck_bin} --name railsmine`
|
23
|
+
end
|
24
|
+
|
25
|
+
should "prints 'Invalid option'" do
|
26
|
+
assert_equal "Invalid option\n", `ruby #{@docheck_bin} -f`
|
27
|
+
assert_equal "Invalid option\n", `ruby #{@docheck_bin} --foo`
|
28
|
+
assert_equal "Invalid option\n", `ruby #{@docheck_bin} --foo bar`
|
29
|
+
end
|
30
|
+
|
31
|
+
should "prints 'Missing argument'" do
|
32
|
+
assert_equal "Missing argument\n", `ruby #{@docheck_bin} -n`
|
33
|
+
assert_equal "Missing argument\n", `ruby #{@docheck_bin} --name`
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
10
37
|
context "A Docheck instance" do
|
11
38
|
setup do
|
12
|
-
@docheck = Docheck.new('railsmine')
|
39
|
+
@docheck = Docheck::Application.new('railsmine')
|
13
40
|
end
|
14
41
|
|
15
|
-
should "
|
42
|
+
should "responds to all its public instance method" do
|
16
43
|
assert @docheck.respond_to?(:fetch)
|
17
44
|
assert @docheck.respond_to?(:print)
|
18
45
|
assert @docheck.respond_to?(:available_domains)
|
19
46
|
assert @docheck.respond_to?(:registered_domains)
|
20
47
|
end
|
21
48
|
|
22
|
-
should "
|
49
|
+
should "returns all availability and registered domain" do
|
23
50
|
result = @docheck.fetch
|
24
51
|
assert result.is_a?(Array)
|
25
52
|
assert result.first.is_a?(Array)
|
@@ -31,7 +58,7 @@ class TestDocheck < Test::Unit::TestCase
|
|
31
58
|
assert_not_nil result
|
32
59
|
end
|
33
60
|
|
34
|
-
should "
|
61
|
+
should "runs #print successfully" do
|
35
62
|
assert @docheck.print
|
36
63
|
end
|
37
64
|
end
|
data/version.rb
ADDED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docheck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kunto Aji Kristianto
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-17 00:00:00 +07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -34,7 +34,21 @@ dependencies:
|
|
34
34
|
version: 1.3.8
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
|
-
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: shoulda
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
description: " Domain name availability checker.\n"
|
38
52
|
email: kunto.aji.kr@gmail.com
|
39
53
|
executables:
|
40
54
|
- docheck
|
@@ -43,13 +57,12 @@ extensions: []
|
|
43
57
|
extra_rdoc_files:
|
44
58
|
- README.rdoc
|
45
59
|
- LICENSE
|
46
|
-
- VERSION
|
47
60
|
files:
|
48
61
|
- .gitignore
|
49
62
|
- docheck.gemspec
|
50
63
|
- LICENSE
|
51
64
|
- README.rdoc
|
52
|
-
-
|
65
|
+
- version.rb
|
53
66
|
- bin/docheck
|
54
67
|
- lib/docheck.rb
|
55
68
|
- test/docheck_test.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.0.1
|