em-whois 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -1
- data/README.md +14 -5
- data/VERSION.yml +2 -2
- data/lib/em-whois.rb +33 -28
- metadata +6 -17
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -5,12 +5,13 @@ GEM
|
|
5
5
|
em-synchrony (1.0.0)
|
6
6
|
eventmachine (>= 1.0.0.beta.1)
|
7
7
|
eventmachine (1.0.0.beta.4)
|
8
|
+
rake (0.9.2.2)
|
8
9
|
rspec (2.9.0)
|
9
10
|
rspec-core (~> 2.9.0)
|
10
11
|
rspec-expectations (~> 2.9.0)
|
11
12
|
rspec-mocks (~> 2.9.0)
|
12
13
|
rspec-core (2.9.0)
|
13
|
-
rspec-expectations (2.9.
|
14
|
+
rspec-expectations (2.9.1)
|
14
15
|
diff-lcs (~> 1.1.3)
|
15
16
|
rspec-mocks (2.9.0)
|
16
17
|
whois (2.5.0)
|
@@ -20,5 +21,6 @@ PLATFORMS
|
|
20
21
|
|
21
22
|
DEPENDENCIES
|
22
23
|
em-synchrony
|
24
|
+
rake
|
23
25
|
rspec
|
24
26
|
whois (= 2.5.0)
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# em-whois
|
1
|
+
# em-whois [![Build Status](https://secure.travis-ci.org/mikejarema/em-whois.png)](http://travis-ci.org/mikejarema/em-whois)
|
2
2
|
|
3
3
|
This is a container for the synchronous WHOIS gem which replaces socket communications
|
4
4
|
with the EventMachine equivalent. The result is a gem permitting asynchronous WHOIS
|
@@ -8,14 +8,21 @@ lookups.
|
|
8
8
|
inside the reactor, and fallback to original sockets outside the reactor context.
|
9
9
|
|
10
10
|
|
11
|
+
## Supported Ruby Versions
|
12
|
+
|
13
|
+
Tested and used in production with MRI 1.9+.
|
14
|
+
|
15
|
+
`em-whois` relies on Ruby Fibers and `em-synchrony`, imposing a 1.9+ requirement.
|
16
|
+
|
17
|
+
|
11
18
|
## Examples
|
12
19
|
|
13
|
-
Simple example to
|
20
|
+
Simple example to check domain availability via WHOIS within the EventMachine loop:
|
14
21
|
|
15
22
|
```ruby
|
23
|
+
require 'em-whois'
|
24
|
+
|
16
25
|
EM.synchrony do
|
17
|
-
|
18
|
-
# Async domain availability lookup via WHOIS info
|
19
26
|
whois = Whois.whois(ARGV[0] || "github.com")
|
20
27
|
puts whois.properties[:available?] ? "Domain Available" : "Domain Taken"
|
21
28
|
|
@@ -23,10 +30,12 @@ EM.synchrony do
|
|
23
30
|
end
|
24
31
|
```
|
25
32
|
|
33
|
+
Also take a look at `examples/async_whois.rb`.
|
34
|
+
|
26
35
|
|
27
36
|
## TODO
|
28
37
|
|
29
|
-
*
|
38
|
+
* Support for ruby 1.8 (remove em-synchrony/Fiber requirement)
|
30
39
|
|
31
40
|
|
32
41
|
## License & Notes
|
data/VERSION.yml
CHANGED
data/lib/em-whois.rb
CHANGED
@@ -4,15 +4,17 @@ require 'em-synchrony'
|
|
4
4
|
module Whois
|
5
5
|
class Server
|
6
6
|
module Adapters
|
7
|
+
|
7
8
|
class Base
|
9
|
+
|
8
10
|
private
|
9
11
|
|
10
|
-
# This method handles the lowest connection
|
11
|
-
# to the WHOIS server.
|
12
12
|
#
|
13
|
-
#
|
13
|
+
# Overwrite Whois::Server::Adapters::Base#ask_the_socket to
|
14
|
+
# be EventMachine-aware, and send calls offs asynchronously
|
15
|
+
# if the EM reactor is running, otherwise fallback to the
|
16
|
+
# synchronous connection.
|
14
17
|
#
|
15
|
-
# @api internal
|
16
18
|
|
17
19
|
alias :orig_ask_the_socket :ask_the_socket
|
18
20
|
|
@@ -21,32 +23,35 @@ module Whois
|
|
21
23
|
end # ask_the_socket
|
22
24
|
|
23
25
|
def em_ask_the_socket(query, *args)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# and I really want to use read instead of gets.
|
28
|
-
|
29
|
-
response = ""
|
30
|
-
|
31
|
-
# Synchrony TCPSocket behaves a little differently, seems to require
|
32
|
-
# polling until an IO exception is thrown.
|
33
|
-
# TODO: There's gotta be a more elegant way to achieve this.
|
34
|
-
while true do
|
35
|
-
begin
|
36
|
-
response += client.read
|
37
|
-
rescue IOError => e
|
38
|
-
break
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
response
|
43
|
-
|
44
|
-
ensure
|
45
|
-
client.close if client # If != client something went wrong.
|
46
|
-
|
26
|
+
fiber = Fiber.current
|
27
|
+
EM::connect args[0], args[1], AsyncClient, query, fiber
|
28
|
+
Fiber.yield
|
47
29
|
end # em_ask_the_socket
|
48
30
|
|
49
|
-
end
|
31
|
+
end # Base
|
32
|
+
|
33
|
+
class AsyncClient < EventMachine::Connection
|
34
|
+
|
35
|
+
def initialize *args
|
36
|
+
@query, @fiber = args[0..1]
|
37
|
+
@data = ""
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
def post_init
|
42
|
+
send_data "#{@query}\r\n"
|
43
|
+
end
|
44
|
+
|
45
|
+
def receive_data(data)
|
46
|
+
@data << data
|
47
|
+
end
|
48
|
+
|
49
|
+
def unbind
|
50
|
+
@fiber.resume @data
|
51
|
+
end
|
52
|
+
|
53
|
+
end # AsyncClient
|
54
|
+
|
50
55
|
end
|
51
56
|
end
|
52
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: em-whois
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,8 +12,8 @@ cert_chain: []
|
|
12
12
|
date: 2012-04-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement: &
|
15
|
+
name: em-synchrony
|
16
|
+
requirement: &70340966931840 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70340966931840
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: whois
|
27
|
-
requirement: &
|
27
|
+
requirement: &70340966931120 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - =
|
@@ -32,18 +32,7 @@ dependencies:
|
|
32
32
|
version: 2.5.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: em-synchrony
|
38
|
-
requirement: &70096718675440 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ! '>='
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '0'
|
44
|
-
type: :runtime
|
45
|
-
prerelease: false
|
46
|
-
version_requirements: *70096718675440
|
35
|
+
version_requirements: *70340966931120
|
47
36
|
description: Wrapper around whois gem providing asynchronous WHOIS queries via EventMachine
|
48
37
|
email: mike@jarema.com
|
49
38
|
executables: []
|