Domainr 1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Domai.nr-1.0.gem ADDED
Binary file
data/Domainr-1.0.gem ADDED
Binary file
data/Domainr-1.1.gem ADDED
File without changes
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ domainr-gem
2
+ ===========
3
+
4
+ Domai.nr (http://domai.nr) is a web page which allows you to search nice domains. This is a gem which uses it\'s API
data/bin/domainr ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require 'domainr'
3
+ trap('INT') {
4
+ exit
5
+ }
6
+
7
+ Domainr::Console.new
data/domainr.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'Domainr'
3
+ s.version = '1.1'
4
+ s.summary = 'Domai.nr is a web page which allows you to search nice domains'
5
+ s.description = 'Domai.nr (http://domai.nr) is a web page which allows you to search nice domains. This is a gem which uses it\'s API'
6
+
7
+ s.authors = ['Pablo Merino']
8
+ s.email = ['pablo.perso1995@gmail.com']
9
+ s.homepage = 'https://github.com/pablo-merino/domainr-gem'
10
+
11
+ s.files = Dir['./**/*']
12
+
13
+ # Supress the warning about no rubyforge project
14
+ s.rubyforge_project = 'nowarning'
15
+ s.executables = `ls bin/*`.split("\n").map{ |f| File.basename(f) }
16
+
17
+ end
data/lib/domainr.rb ADDED
@@ -0,0 +1,41 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'readline'
4
+ require 'domainr/operations'
5
+ require 'domainr/colorize'
6
+
7
+ module Domainr
8
+ class Console
9
+ def initialize
10
+ loop {
11
+ buf = ::Readline::readline('domai.nr> ', true)
12
+ enter(buf)
13
+ }
14
+
15
+ end
16
+
17
+ def enter(command)
18
+ if command == 'exit'
19
+ exit
20
+ end
21
+ command =~ /(.*) (.*)/
22
+ cmd = $1
23
+ args = $2
24
+
25
+ case cmd
26
+ when 'search'
27
+ Operations.search(args)
28
+ when 'info'
29
+ Operations.info(args)
30
+
31
+ else
32
+ puts "Command not found"
33
+ end
34
+
35
+
36
+ end
37
+
38
+
39
+ end
40
+ end
41
+
@@ -0,0 +1,191 @@
1
+ #
2
+ # Colorize String class extension. By fazibear (https://github.com/fazibear). Edited to have bold (bright) letters by Pablo Merino (https://github.com/pablo-merino)
3
+ #
4
+ class String
5
+
6
+ #
7
+ # Colors Hash
8
+ #
9
+ COLORS = {
10
+ :black => 0,
11
+ :red => 1,
12
+ :green => 2,
13
+ :yellow => 3,
14
+ :blue => 4,
15
+ :magenta => 5,
16
+ :cyan => 6,
17
+ :white => 7,
18
+ :default => 9,
19
+
20
+ :light_black => 10,
21
+ :light_red => 11,
22
+ :light_green => 12,
23
+ :light_yellow => 13,
24
+ :light_blue => 14,
25
+ :light_magenta => 15,
26
+ :light_cyan => 16,
27
+ :light_white => 17
28
+ }
29
+
30
+ #
31
+ # Modes Hash
32
+ #
33
+ MODES = {
34
+ :default => 0, # Turn off all attributes
35
+ :bright => 1, # Set bright mode
36
+ :underline => 4, # Set underline mode
37
+ :blink => 5, # Set blink mode
38
+ :swap => 7, # Exchange foreground and background colors
39
+ :hide => 8 # Hide text (foreground color would be the same as background)
40
+ }
41
+
42
+ protected
43
+
44
+ #
45
+ # Set color values in new string intance
46
+ #
47
+ def set_color_parameters( params )
48
+ if (params.instance_of?(Hash))
49
+ @color = params[:color]
50
+ @background = params[:background]
51
+ @mode = params[:mode]
52
+ @uncolorized = params[:uncolorized]
53
+ self
54
+ else
55
+ nil
56
+ end
57
+ end
58
+
59
+ public
60
+
61
+ #
62
+ # Change color of string
63
+ #
64
+ # Examples:
65
+ #
66
+ # puts "This is blue".colorize( :blue )
67
+ # puts "This is light blue".colorize( :light_blue )
68
+ # puts "This is also blue".colorize( :color => :blue )
69
+ # puts "This is light blue with red background".colorize( :color => :light_blue, :background => :red )
70
+ # puts "This is light blue with red background".colorize( :light_blue ).colorize( :background => :red )
71
+ # puts "This is blue text on red".blue.on_red
72
+ # puts "This is red on blue".colorize( :red ).on_blue
73
+ # puts "This is red on blue and underline".colorize( :red ).on_blue.underline
74
+ # puts "This is blue text on red".blue.on_red.blink
75
+ # puts "This is uncolorized".blue.on_red.uncolorize
76
+ #
77
+ def colorize( params )
78
+ return self unless STDOUT.isatty
79
+
80
+ begin
81
+ require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/
82
+ rescue LoadError
83
+ raise 'You must gem install win32console to use colorize on Windows'
84
+ end
85
+
86
+ color_parameters = {}
87
+
88
+ if (params.instance_of?(Hash))
89
+ color_parameters[:color] = COLORS[params[:color]]
90
+ color_parameters[:background] = COLORS[params[:background]]
91
+ color_parameters[:mode] = MODES[params[:mode]]
92
+ elsif (params.instance_of?(Symbol))
93
+ color_parameters[:color] = COLORS[params]
94
+ end
95
+
96
+ color_parameters[:color] ||= @color ||= COLORS[:default]
97
+ color_parameters[:background] ||= @background ||= COLORS[:default]
98
+ color_parameters[:mode] ||= @mode ||= MODES[:default]
99
+
100
+ color_parameters[:uncolorized] ||= @uncolorized ||= self.dup
101
+
102
+ # calculate bright mode
103
+ color_parameters[:color] += 50 if color_parameters[:color] > 10
104
+
105
+ color_parameters[:background] += 50 if color_parameters[:background] > 10
106
+
107
+ "\033[#{color_parameters[:mode]};#{color_parameters[:color]+30};#{color_parameters[:background]+40}m#{color_parameters[:uncolorized]}\033[0m".set_color_parameters( color_parameters )
108
+ end
109
+
110
+ #
111
+ # Return uncolorized string
112
+ #
113
+ def uncolorize
114
+ @uncolorized || self
115
+ end
116
+
117
+ #
118
+ # Return true if sting is colorized
119
+ #
120
+ def colorized?
121
+ !defined?(@uncolorized).nil?
122
+ end
123
+
124
+ #
125
+ # Make some color and on_color methods
126
+ #
127
+ COLORS.each_key do | key |
128
+ next if key == :default
129
+
130
+ define_method key do
131
+ self.colorize( :color => key )
132
+ end
133
+
134
+ define_method "on_#{key}" do
135
+ self.colorize( :background => key )
136
+ end
137
+ end
138
+
139
+ #
140
+ # Methods for modes
141
+ #
142
+ MODES.each_key do | key |
143
+ next if key == :default
144
+
145
+ define_method key do
146
+ self.colorize( :mode => key )
147
+ end
148
+ end
149
+
150
+ class << self
151
+
152
+ #
153
+ # Return array of available modes used by colorize method
154
+ #
155
+ def modes
156
+ keys = []
157
+ MODES.each_key do | key |
158
+ keys << key
159
+ end
160
+ keys
161
+ end
162
+
163
+ #
164
+ # Return array of available colors used by colorize method
165
+ #
166
+ def colors
167
+ keys = []
168
+ COLORS.each_key do | key |
169
+ keys << key
170
+ end
171
+ keys
172
+ end
173
+
174
+ #
175
+ # Display color matrix with color names.
176
+ #
177
+ def color_matrix( txt = "[X]" )
178
+ size = String.colors.length
179
+ String.colors.each do | color |
180
+ String.colors.each do | back |
181
+ print txt.colorize( :color => color, :background => back )
182
+ end
183
+ puts " < #{color}"
184
+ end
185
+ String.colors.reverse.each_with_index do | back, index |
186
+ puts "#{"|".rjust(txt.length)*(size-index)} < #{back}"
187
+ end
188
+ ""
189
+ end
190
+ end
191
+ end
@@ -0,0 +1,86 @@
1
+ module Domainr
2
+ class Operations
3
+
4
+ def self.info(domain)
5
+ response = JSON.parse(Net::HTTP.get(URI("http://domai.nr/api/json/info?q=#{domain}")))
6
+ puts "Domain: #{response['domain']}"
7
+
8
+ response['registrars'].each do |result|
9
+ puts "Registrar: #{result['name']} (#{result['registrar']})"
10
+ end
11
+
12
+ puts "TLD: #{response['tld']['domain']}"
13
+ puts "IANA URL: #{response['tld']['iana_url']}"
14
+ puts "Wikipedia URL: #{response['tld']['wikipedia_url']}"
15
+ end
16
+
17
+
18
+ def self.search(query)
19
+ @responses_array = Array.new
20
+ response = JSON.parse(Net::HTTP.get(URI("http://domai.nr/api/json/search?q=#{query}")))
21
+ print_domains response
22
+ catch (:done) do
23
+ loop {
24
+ buf = ::Readline::readline('Select domain > ', true)
25
+ if buf == "list"
26
+ print_domains response
27
+ elsif buf == 'back'
28
+ throw :done
29
+ elsif buf.match(/\A[+-]?\d+?(\.\d+)?\Z/).nil?
30
+ puts "Write here the number of the domain you want!"
31
+ else
32
+ if @responses_array[buf.to_i-1]['availability'].to_sym == :unavailable
33
+ puts "That domain is not available"
34
+ elsif @responses_array[buf.to_i-1]['availability'].to_sym == :tld
35
+ puts "That domain is a TLD"
36
+ else
37
+ begin
38
+ subshell @responses_array[buf.to_i-1]
39
+ rescue
40
+ puts "Not a valid selection"
41
+ end
42
+ end
43
+ end
44
+ }
45
+ end
46
+ end
47
+
48
+ def self.subshell(response)
49
+ catch (:done) do
50
+ loop {
51
+ buf = ::Readline::readline("Selected #{response['domain']} > ", true)
52
+
53
+ case buf
54
+ when 'register'
55
+ puts 'Opening register window...'
56
+ system "open #{response['register_url']}"
57
+
58
+ when 'back'
59
+ throw :done
60
+ end
61
+ }
62
+ end
63
+ end
64
+
65
+ def self.print_domains(response)
66
+
67
+ puts "Query: #{response['query']}"
68
+ response['results'].each_with_index do |result, index|
69
+ puts "#{index+1}:"
70
+ puts "Domain: #{result['domain']}"
71
+ case result['availability'].to_sym
72
+ when :available
73
+ puts "Availability: #{result['availability'].green}"
74
+ when :taken
75
+ puts "Availability: #{result['availability'].yellow}"
76
+ when :unavailable
77
+ puts "Availability: #{result['availability'].red}"
78
+ when :tld
79
+ puts "Availability: #{result['availability'].red}"
80
+ end
81
+ @responses_array.push result
82
+ end
83
+
84
+ end
85
+ end
86
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Domainr
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Pablo Merino
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-19 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Domai.nr (http://domai.nr) is a web page which allows you to search nice
15
+ domains. This is a gem which uses it's API
16
+ email:
17
+ - pablo.perso1995@gmail.com
18
+ executables:
19
+ - domainr
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - ./bin/domainr
24
+ - ./Domai.nr-1.0.gem
25
+ - ./Domainr-1.0.gem
26
+ - ./Domainr-1.1.gem
27
+ - ./domainr.gemspec
28
+ - ./lib/domainr/colorize.rb
29
+ - ./lib/domainr/operations.rb
30
+ - ./lib/domainr.rb
31
+ - ./README.md
32
+ - !binary |-
33
+ YmluL2RvbWFpbnI=
34
+ homepage: https://github.com/pablo-merino/domainr-gem
35
+ licenses: []
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubyforge_project: nowarning
54
+ rubygems_version: 1.8.21
55
+ signing_key:
56
+ specification_version: 3
57
+ summary: Domai.nr is a web page which allows you to search nice domains
58
+ test_files: []