domr 0.2.0 → 0.2.1

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 +2 -1
  2. data/lib/domr.rb +46 -46
  3. metadata +1 -1
data/bin/domr CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  require 'domr'
3
4
 
4
5
  # Check for empty query
@@ -9,7 +10,7 @@ else
9
10
  end
10
11
 
11
12
  # Perform the search
12
- if !Domr.search(arg)
13
+ if domr(arg) == false
13
14
  exit 1
14
15
  else
15
16
  exit 0
data/lib/domr.rb CHANGED
@@ -3,57 +3,57 @@ require 'uri'
3
3
  require 'net/http'
4
4
  require 'json'
5
5
 
6
- # The main class
7
- class Domr
8
- # Perform a query on domainr API
9
- #
10
- # Example:
11
- # >> Domr.search "example"
12
- # example.com taken
13
- # example.net taken
14
- # example.org taken
15
- # => true
16
- #
17
- # Arguments:
18
- # query: (String)
19
- def self.search query
20
-
21
- # Form the request string
22
- request = Net::HTTP::Get.new('/api/json/search?q=' << URI.escape(query))
23
-
24
- # Perform the actual query
25
- response = Net::HTTP.start('domai.nr') do |http|
26
- http.request request
27
- end
6
+ # Perform a query on domainr API
7
+
8
+ #
9
+ # Example:
10
+ # >> Domr.search "example"
11
+ # example.com taken
12
+ # example.net taken
13
+ # example.org taken
14
+ # => true
15
+ #
16
+ # Arguments:
17
+ # query: (String)
18
+ def domr query
19
+
20
+ # Form the request string
21
+ request = Net::HTTP::Get.new('/api/json/search?q=' << URI.escape(query))
22
+
23
+ # Perform the actual query
24
+ response = Net::HTTP.start('domai.nr') do |http|
25
+ http.request request
26
+ end
28
27
 
29
- # Check for errors
30
- if response.code != '200'
31
- puts "HTTP error".color(:red).bright
32
- return false
33
- end
28
+ # Check for errors
29
+ if response.code != '200'
30
+ puts "HTTP error".color(:red).bright
31
+ return false
32
+ end
34
33
 
35
- # Output results
36
- JSON.parse(response.body)['results'].each do |result|
37
-
38
- # Determine color to show
39
- case result['availability']
40
- when 'available'
41
- color = :green
42
- when 'taken', 'unavailable'
43
- color = :default
44
- when 'maybe'
45
- color = :yellow
46
- else
47
- color = :default
48
- end
34
+ results = JSON.parse(response.body)['results']
49
35
 
50
- # Construct final output string
51
- string = ' ' << result['domain'] << ' ' << result['availability']
36
+ # Output results
37
+ results.each do |result|
52
38
 
53
- # Output colorized string
54
- puts string.color(color).bright
39
+ # Determine color to show
40
+ case result['availability']
41
+ when 'available'
42
+ color = :green
43
+ when 'taken', 'unavailable'
44
+ color = :default
45
+ when 'maybe'
46
+ color = :yellow
47
+ else
48
+ color = :default
55
49
  end
56
50
 
57
- return true
51
+ # Construct final output string
52
+ string = ' ' << result['domain'] << ' ' << result['availability']
53
+
54
+ # Output colorized string
55
+ puts string.color(color).bright
58
56
  end
57
+
58
+ return results.length
59
59
  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.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: