domr 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/domr +3 -3
  2. data/lib/domr.rb +16 -10
  3. metadata +1 -1
data/bin/domr CHANGED
@@ -6,12 +6,12 @@ require 'domr'
6
6
  if !ARGV[0]
7
7
  arg = ''
8
8
  else
9
- arg = ARGV[0]
9
+ arg = ARGV.join " "
10
10
  end
11
11
 
12
12
  # Perform the search
13
13
  if domr(arg) == false
14
- exit 1
14
+ exit 1 # Exit with code 1 (error)
15
15
  else
16
- exit 0
16
+ exit 0 # Exit with code 0 (success)
17
17
  end
@@ -7,16 +7,21 @@ require 'json'
7
7
 
8
8
  #
9
9
  # Example:
10
- # >> Domr.search "example"
11
- # example.com taken
12
- # example.net taken
13
- # example.org taken
14
- # => true
10
+ # >> domr "example"
11
+ # => 1
15
12
  #
16
13
  # Arguments:
17
14
  # query: (String)
18
- def domr query
15
+ # flag: (:none or :silent)
16
+ def domr(query, flag = :none)
19
17
 
18
+ # Activate silent mode if flag is set
19
+ if flag == :silent
20
+ silent = true
21
+ else
22
+ silent = false
23
+ end
24
+
20
25
  # Form the request string
21
26
  request = Net::HTTP::Get.new('/api/json/search?q=' << URI.escape(query))
22
27
 
@@ -27,8 +32,8 @@ def domr query
27
32
 
28
33
  # Check for errors
29
34
  if response.code != '200'
30
- puts "HTTP error".color(:red).bright
31
- return false
35
+ puts "HTTP error".color(:red).bright if !silent
36
+ return false
32
37
  end
33
38
 
34
39
  results = JSON.parse(response.body)['results']
@@ -52,8 +57,9 @@ def domr query
52
57
  string = ' ' << result['domain'] << ' ' << result['availability']
53
58
 
54
59
  # Output colorized string
55
- puts string.color(color).bright
60
+ puts string.color(color).bright if !silent
56
61
  end
57
62
 
58
- return results.length
63
+ # Return number of available domain names
64
+ return results.count { |result| result['availability'] == 'available' }
59
65
  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.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: