domr 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/Gemfile +10 -10
  2. data/bin/domr +18 -17
  3. data/index +8 -8
  4. data/lib/domr.rb +51 -65
  5. metadata +2 -2
data/Gemfile CHANGED
@@ -1,10 +1,10 @@
1
- source "http://rubygems.org"
2
-
3
- gem "rspec"
4
- gem "rainbow"
5
- gem "json"
6
-
7
- platforms :mswin, :mingw do
8
- gem "windows-pr"
9
- gem "win32console"
10
- end
1
+ source "http://rubygems.org"
2
+
3
+ gem "rspec"
4
+ gem "rainbow"
5
+ gem "httparty"
6
+
7
+ platforms :mswin, :mingw do
8
+ gem "windows-pr"
9
+ gem "win32console"
10
+ end
data/bin/domr CHANGED
@@ -1,17 +1,18 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'domr'
4
-
5
- # Check for empty query
6
- if !ARGV[0]
7
- arg = ''
8
- else
9
- arg = ARGV.join " "
10
- end
11
-
12
- # Perform the search
13
- if domr(arg) == false
14
- exit 1 # Exit with code 1 (error)
15
- else
16
- exit 0 # Exit with code 0 (success)
17
- end
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), %w[.. lib])
4
+ require 'domr'
5
+
6
+ # Check for empty query
7
+ if !ARGV[0]
8
+ arg = ''
9
+ else
10
+ arg = ARGV.join " "
11
+ end
12
+
13
+ # Perform the search
14
+ if domr(arg) == false
15
+ exit 1 # Exit with code 1 (error)
16
+ else
17
+ exit 0 # Exit with code 0 (success)
18
+ end
data/index CHANGED
@@ -1,9 +1,9 @@
1
- Simple search for domain names
2
-
3
- Usage:
4
-
5
- $ domr <name>
6
-
7
- Example:
8
-
1
+ Simple search for domain names
2
+
3
+ Usage:
4
+
5
+ $ domr <name>
6
+
7
+ Example:
8
+
9
9
  $ domr example.com
@@ -1,65 +1,51 @@
1
- require 'rainbow'
2
- require 'uri'
3
- require 'net/http'
4
- require 'json'
5
-
6
- # Perform a query on domainr API
7
-
8
- #
9
- # Example:
10
- # >> domr "example"
11
- # => 1
12
- #
13
- # Arguments:
14
- # query: (String)
15
- # flag: (:none or :silent)
16
- def domr(query, flag = :none)
17
-
18
- # Activate silent mode if flag is set
19
- if flag == :silent
20
- silent = true
21
- else
22
- silent = false
23
- end
24
-
25
- # Form the request string
26
- request = Net::HTTP::Get.new('/api/json/search?q=' << URI.escape(query))
27
-
28
- # Perform the actual query
29
- response = Net::HTTP.start('domai.nr') do |http|
30
- http.request request
31
- end
32
-
33
- # Check for errors
34
- if response.code != '200'
35
- puts "HTTP error".color(:red).bright if !silent
36
- return false
37
- end
38
-
39
- results = JSON.parse(response.body)['results']
40
-
41
- # Output results
42
- results.each do |result|
43
-
44
- # Determine color to show
45
- case result['availability']
46
- when 'available'
47
- color = :green
48
- when 'taken', 'unavailable'
49
- color = :default
50
- when 'maybe'
51
- color = :yellow
52
- else
53
- color = :default
54
- end
55
-
56
- # Construct final output string
57
- string = ' ' << result['domain'] << ' ' << result['availability']
58
-
59
- # Output colorized string
60
- puts string.color(color).bright if !silent
61
- end
62
-
63
- # Return number of available domain names
64
- return results.count { |result| result['availability'] == 'available' }
65
- end
1
+ require 'rainbow'
2
+ require 'uri'
3
+ require 'httparty'
4
+
5
+ # Perform a query on domainr API
6
+
7
+ #
8
+ # Example:
9
+ # >> domr "example"
10
+ # => 1
11
+ #
12
+ # Arguments:
13
+ # query: (String)
14
+ # flag: (:none or :silent)
15
+ def domr(query, flag = :none)
16
+
17
+ # Activate silent mode if flag is set
18
+ if flag == :silent
19
+ silent = true
20
+ else
21
+ silent = false
22
+ end
23
+
24
+ # Query the Domainr API
25
+ results = HTTParty.get('http://domai.nr/api/json/search?q=' << URI.escape(query))['results'];
26
+
27
+ # Output results
28
+ results.each do |result|
29
+
30
+ # Determine color to show
31
+ case result['availability']
32
+ when 'available'
33
+ color = :green
34
+ when 'taken', 'unavailable'
35
+ color = :red
36
+ when 'maybe'
37
+ color = :yellow
38
+ else
39
+ color = :default
40
+ end
41
+
42
+ # Construct final output string
43
+ string = ' ' << result['domain'] << ' ' << result['availability']
44
+
45
+ # Output colorized string
46
+ puts string.color(color).bright if !silent
47
+ end
48
+
49
+ # Return number of available domain names
50
+ return results.count { |result| result['availability'] == 'available' }
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: domr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ cert_chain: []
12
12
  date: 2012-07-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: json
15
+ name: httparty
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements: