domr 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/domr.rb +21 -8
  2. metadata +9 -24
data/lib/domr.rb CHANGED
@@ -5,8 +5,10 @@
5
5
  # domr example.com
6
6
  # => example.com is taken
7
7
 
8
- require 'domainr'
9
8
  require 'rainbow'
9
+ require 'uri'
10
+ require 'net/http'
11
+ require 'json'
10
12
 
11
13
  # Simple search for domain names
12
14
  # The main class
@@ -26,26 +28,37 @@ class Domr
26
28
 
27
29
  # Output a newline
28
30
  puts "\n"
29
-
31
+
32
+ # Form the request string
33
+ request = Net::HTTP::Get.new("/api/json/search?q=" << URI.escape(query))
34
+
30
35
  # Perform the actual query
31
- response = Domainr.search(query)
36
+ response = Net::HTTP.start("domai.nr") { |http|
37
+ http.request request
38
+ }
39
+
40
+ # Check for errors
41
+ if response.code != "200"
42
+ puts "HTTP error".color(:red)
43
+ exit
44
+ end
32
45
 
33
46
  # Output results
34
- response.results.each do |result|
47
+ JSON.parse(response.body)['results'].each do |result|
35
48
 
36
49
  # Determine color to show
37
- if result.availability == 'available'
50
+ if result['availability'] == 'available'
38
51
  color = :green
39
- elsif result.availability == 'taken' || result.availability == 'unavailable'
52
+ elsif result['availability'] == 'taken' || result['availability'] == 'unavailable'
40
53
  color = :red
41
- elsif result.availability == 'maybe'
54
+ elsif result['availability'] == 'maybe'
42
55
  color = :yellow
43
56
  else
44
57
  color = :white
45
58
  end
46
59
 
47
60
  # Construct final output string
48
- string = " " << result.domain << " " << result.availability
61
+ string = " " << result['domain'] << " " << result['availability']
49
62
 
50
63
  # Output colorized string
51
64
  puts string.color(color)
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.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,8 +12,8 @@ cert_chain: []
12
12
  date: 2012-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: domainr
16
- requirement: !ruby/object:Gem::Requirement
15
+ name: json
16
+ requirement: &19424256 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
24
+ version_requirements: *19424256
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: rainbow
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &19421268 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ! '>='
@@ -37,15 +32,10 @@ dependencies:
37
32
  version: '0'
38
33
  type: :runtime
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
35
+ version_requirements: *19421268
46
36
  - !ruby/object:Gem::Dependency
47
37
  name: win32console
48
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &19420800 !ruby/object:Gem::Requirement
49
39
  none: false
50
40
  requirements:
51
41
  - - ! '>='
@@ -53,12 +43,7 @@ dependencies:
53
43
  version: '0'
54
44
  type: :runtime
55
45
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
46
+ version_requirements: *19420800
62
47
  description: Quickly search for available domains
63
48
  email: shveloo@gmail.com
64
49
  executables:
@@ -88,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
73
  version: '0'
89
74
  requirements: []
90
75
  rubyforge_project:
91
- rubygems_version: 1.8.23
76
+ rubygems_version: 1.8.16
92
77
  signing_key:
93
78
  specification_version: 3
94
79
  summary: Domainr quick search