domr 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Gemfile +1 -1
  2. data/lib/domr.rb +15 -15
  3. metadata +1 -1
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "rake"
3
+ gem "rspec"
4
4
  gem "rainbow"
5
5
  gem "json"
6
6
 
data/lib/domr.rb CHANGED
@@ -2,10 +2,9 @@ require 'rainbow'
2
2
  require 'uri'
3
3
  require 'net/http'
4
4
  require 'json'
5
-
5
+
6
6
  # The main class
7
7
  class Domr
8
-
9
8
  # Perform a query on domainr API
10
9
  #
11
10
  # Example:
@@ -18,33 +17,34 @@ class Domr
18
17
  # Arguments:
19
18
  # query: (String)
20
19
  def self.search query
21
-
20
+
22
21
  # Form the request string
23
22
  request = Net::HTTP::Get.new("/api/json/search?q=" << URI.escape(query))
24
-
23
+
25
24
  # Perform the actual query
26
- response = Net::HTTP.start("domai.nr") { |http|
25
+ response = Net::HTTP.start("domai.nr") do |http|
27
26
  http.request request
28
- }
29
-
27
+ end
28
+
30
29
  # Check for errors
31
30
  if response.code != "200"
32
- puts "HTTP error".color(:red).bright # Color is red
31
+ puts "HTTP error".color(:red).bright
33
32
  return false
34
33
  end
35
-
34
+
36
35
  # Output results
37
36
  JSON.parse(response.body)['results'].each do |result|
38
37
 
39
38
  # Determine color to show
40
- if result['availability'] == 'available'
39
+ case result['availability']
40
+ when 'available'
41
41
  color = :green
42
- elsif result['availability'] == 'taken' || result['availability'] == 'unavailable'
43
- color = :red
44
- elsif result['availability'] == 'maybe'
42
+ when 'taken', 'unavailable'
43
+ color = :default
44
+ when 'maybe'
45
45
  color = :yellow
46
46
  else
47
- color = :default
47
+ color = :default
48
48
  end
49
49
 
50
50
  # Construct final output string
@@ -53,7 +53,7 @@ class Domr
53
53
  # Output colorized string
54
54
  puts string.color(color).bright
55
55
  end
56
-
56
+
57
57
  return true
58
58
  end
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.1.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: