em-whois 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 296c06f91c3611d827936840716c2aec957e9583
4
+ data.tar.gz: 5b2e8942634183b97df58b1124653a6dd046369f
5
+ SHA512:
6
+ metadata.gz: 7bc371df9f18f9b8ea7ebc3cfe048ecd588d99244c111c250ad869febf4478e8faac6fc2d8c7453949ebc7c403c37e642333c9fa5d693a8a12d56d5ddcd346d1
7
+ data.tar.gz: f40c7a6db917393b42a70aeb51fb393eee9717420bdba75adea005c11e1ec5f5f5a7caba0c94140c0c62bc85e38f4c53dc21b8c2e88687e58a6969ccfe25d5b9
data/Gemfile CHANGED
@@ -1,9 +1,10 @@
1
- source :gemcutter
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gem 'em-synchrony'
4
- gem 'whois', '= 2.7.0' # Locked to specific version as internals of whois gem are overridden
4
+ gem 'whois', '= 4.0.6' # Locked to specific version as internals of whois gem are overridden
5
5
 
6
- group :development do
6
+ group :test do
7
7
  gem 'rake'
8
8
  gem 'rspec'
9
+ gem 'whois-parser', '= 1.1.0'
9
10
  end
data/README.md CHANGED
@@ -10,9 +10,7 @@ inside the reactor, and fallback to original sockets outside the reactor context
10
10
 
11
11
  ## Supported Ruby Versions
12
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.
13
+ `em-whois` requires ruby 2.0+, with which it has been tested and used in production.
16
14
 
17
15
 
18
16
  ## Examples
@@ -21,16 +19,16 @@ Simple example to check domain availability via WHOIS within the EventMachine lo
21
19
 
22
20
  ```ruby
23
21
  require 'em-whois'
22
+ require 'whois-parser'
24
23
 
25
- EM.synchrony do
24
+ EM.synchrony do
26
25
  whois = Whois.whois(ARGV[0] || "github.com")
27
- puts whois.properties[:available?] ? "Domain Available" : "Domain Taken"
28
-
26
+ puts whois.parser.available? ? "Domain Available" : "Domain Taken"
29
27
  EM.stop
30
28
  end
31
29
  ```
32
30
 
33
- Also take a look at `examples/async_whois.rb`.
31
+ Also take a look at the async examples in `examples/`.
34
32
 
35
33
 
36
34
  ## License & Notes
@@ -1,4 +1,4 @@
1
- ---
2
- :patch: 0
1
+ ---
3
2
  :major: 0
4
- :minor: 3
3
+ :minor: 4
4
+ :patch: 0
@@ -0,0 +1,53 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{em-whois}
5
+ s.version = "0.4.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Mike Jarema"]
9
+ s.date = %q{2018-06-25}
10
+ s.description = %q{Asynchronous WHOIS queries via EventMachine (based on synchronous whois gem)}
11
+ s.email = %q{mike@jarema.com}
12
+ s.files = [
13
+ "Gemfile",
14
+ "README.md",
15
+ "Rakefile",
16
+ "VERSION.yml",
17
+ "em-whois.gemspec",
18
+ "examples",
19
+ "lib",
20
+ "spec",
21
+
22
+ "VERSION.yml",
23
+ "README.md",
24
+ ".rspec",
25
+ "Gemfile",
26
+ "Rakefile",
27
+ "examples/async_whois.rb",
28
+ "examples/async_parallel_whois.rb",
29
+ "examples/sync_whois.rb",
30
+ "lib/em-whois.rb",
31
+ "spec/em-whois_spec.rb",
32
+ "spec/helper/all.rb",
33
+ ]
34
+ s.has_rdoc = true
35
+ s.homepage = %q{http://github.com/mikejarema/em-whois}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.2}
39
+ s.summary = %q{Query WHOIS servers using native EventMachine connection classes.}
40
+ s.test_files = [
41
+ "spec/em-whois_spec.rb",
42
+ "spec/helper/all.rb",
43
+ ]
44
+ s.required_ruby_version = Gem::Requirement.new(">= 2.0.0".freeze)
45
+
46
+ s.add_runtime_dependency('em-synchrony')
47
+ s.add_runtime_dependency('whois', '= 4.0.6')
48
+
49
+ s.add_development_dependency('rake')
50
+ s.add_development_dependency('rspec')
51
+ s.add_development_dependency('whois-parser', '= 1.1.0')
52
+
53
+ end
@@ -1,13 +1,13 @@
1
1
  $: << File.dirname(__FILE__) + '/../lib'
2
2
  require 'em-whois'
3
- require 'atomic'
3
+ require 'whois-parser'
4
4
 
5
5
  # Asynchronous, parallel multi-domain WHOIS lookup
6
6
  domains = ARGV.empty? ? ["github.com", "google.com", "bing.com", "yahoo.com", "mikejarema.com"] : ARGV
7
7
  whois = {}
8
8
 
9
- EM.synchrony do
10
-
9
+ EM.synchrony do
10
+
11
11
  # Progress indicator
12
12
  EM.add_periodic_timer(0.1) do
13
13
  STDERR.print "."
@@ -18,10 +18,10 @@ EM.synchrony do
18
18
  if domains.size == whois.keys.size
19
19
  puts ""
20
20
  whois.each do |k,v|
21
- if v.properties[:available?]
21
+ if v.parser.available?
22
22
  puts "#{k}: available"
23
23
  else
24
- puts "#{k}: taken, expires #{v.properties[:expires_on]}"
24
+ puts "#{k}: taken, expires #{v.parser.expires_on}"
25
25
  end
26
26
  end
27
27
 
@@ -1,10 +1,11 @@
1
1
  $: << File.dirname(__FILE__) + '/../lib'
2
2
  require 'em-whois'
3
+ require 'whois-parser'
3
4
 
4
5
  # Asynchronous WHOIS lookup -- em-whois should opt to use EM-based TcpSocket
5
6
 
6
- EM.synchrony do
7
-
7
+ EM.synchrony do
8
+
8
9
  # EM pulse
9
10
  EM.add_periodic_timer(0.1) do
10
11
  STDERR.print "."
@@ -12,12 +13,12 @@ EM.synchrony do
12
13
 
13
14
  # Async WHOIS lookup
14
15
  domain = ARGV[0] || "github.com"
15
-
16
+
16
17
  r = Whois.whois(domain)
17
-
18
+
18
19
  puts "\r#{domain}\n#{"-" * domain.length}"
19
20
  [:available?, :status, :expires_on].each do |k|
20
- puts "#{k}: #{r.properties[k]}"
21
+ puts "#{k}: #{r.parser.send(k)}"
21
22
  end
22
23
 
23
24
  EM.stop
@@ -1,5 +1,6 @@
1
1
  $: << File.dirname(__FILE__) + '/../lib'
2
2
  require 'em-whois'
3
+ require 'whois-parser'
3
4
 
4
5
  # Synchronous WHOIS lookup -- em-whois should opt to use original TcpSocket
5
6
 
@@ -9,5 +10,5 @@ r = Whois.whois(domain)
9
10
 
10
11
  puts "\r#{domain}\n#{"-" * domain.length}"
11
12
  [:available?, :status, :expires_on].each do |k|
12
- puts "#{k}: #{r.properties[k]}"
13
+ puts "#{k}: #{r.parser.send(k)}"
13
14
  end
@@ -3,55 +3,50 @@ require 'em-synchrony'
3
3
 
4
4
  module Whois
5
5
  class Server
6
- module Adapters
6
+ class SocketHandler
7
7
 
8
- class Base
8
+ #
9
+ # Overwrite Whois::Server::SocketHandler#call to
10
+ # be EventMachine-aware, and send calls offs asynchronously
11
+ # if the EM reactor is running, otherwise fallback to the
12
+ # synchronous connection.
13
+ #
9
14
 
10
- private
15
+ alias :orig_call :call
11
16
 
12
- #
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.
17
- #
18
-
19
- alias :orig_ask_the_socket :ask_the_socket
17
+ def call(*args)
18
+ defined?(EM) && EM.reactor_running? ? em_call(*args) : orig_call(*args)
19
+ end
20
20
 
21
- def ask_the_socket(*args)
22
- defined?(EM) && EM.reactor_running? ? em_ask_the_socket(*args) : orig_ask_the_socket(*args)
23
- end # ask_the_socket
21
+ def em_call(query, *args)
22
+ fiber = Fiber.current
23
+ EM::connect args[0], args[1], AsyncClient, query, fiber
24
+ Fiber.yield
25
+ end
24
26
 
25
- def em_ask_the_socket(query, *args)
26
- fiber = Fiber.current
27
- EM::connect args[0], args[1], AsyncClient, query, fiber
28
- Fiber.yield
29
- end # em_ask_the_socket
30
-
31
- end # Base
32
-
33
- class AsyncClient < EventMachine::Connection
27
+ end
34
28
 
35
- def initialize *args
36
- @query, @fiber = args[0..1]
37
- @data = ""
38
- super
39
- end
29
+ class AsyncClient < EventMachine::Connection
40
30
 
41
- def post_init
42
- send_data "#{@query}\r\n"
43
- end
31
+ def initialize *args
32
+ @query, @fiber = args[0..1]
33
+ @data = ""
34
+ super
35
+ end
44
36
 
45
- def receive_data(data)
46
- @data << data
47
- end
37
+ def post_init
38
+ send_data "#{@query}\r\n"
39
+ end
48
40
 
49
- def unbind
50
- @fiber.resume @data
51
- end
41
+ def receive_data(data)
42
+ @data << data
43
+ end
52
44
 
53
- end # AsyncClient
45
+ def unbind
46
+ @fiber.resume @data
47
+ end
54
48
 
55
49
  end
50
+
56
51
  end
57
52
  end
@@ -1,17 +1,31 @@
1
1
  require "spec/helper/all"
2
+ require 'whois-parser'
3
+
4
+ def throttle
5
+ sleep 5
6
+ yield
7
+ end
8
+
9
+ def properties_for(whois_record)
10
+ hash = {}
11
+ Whois::Parser::PROPERTIES.each do |p|
12
+ hash[p] = whois_record.parser.send(p)
13
+ end
14
+ hash
15
+ end
2
16
 
3
17
  describe "Asynchronous WHOIS" do
4
18
 
5
19
  it "should not use synchronous socket methods" do
6
-
20
+
7
21
  EM.synchrony do
8
- Whois::Server::Adapters::Base.any_instance.should_not_receive(:orig_ask_the_socket)
22
+ expect_any_instance_of(Whois::Server::SocketHandler).to_not receive(:orig_call)
9
23
 
10
- whois = Whois.whois("google.com")
11
- whois.should_not be_available # Sanity check
24
+ whois = throttle { Whois.whois("google.com") }
25
+ expect(whois.parser).to_not be_available # Sanity check
12
26
 
13
- whois = Whois.whois("#{rand(Time.now.to_i)}-alskdjflkasjd.com")
14
- whois.should be_available # Sanity check
27
+ whois = throttle { Whois.whois("#{rand(Time.now.to_i)}-alskdjflkasjd.com") }
28
+ expect(whois.parser).to be_available # Sanity check
15
29
 
16
30
  EM.stop
17
31
  end
@@ -23,13 +37,13 @@ describe "Asynchronous WHOIS" do
23
37
  sync_whois = nil
24
38
 
25
39
  EM.synchrony do
26
- async_whois = Whois.whois("github.com")
40
+ async_whois = throttle { Whois.whois("github.com") }
27
41
  EM.stop
28
42
  end
29
43
 
30
- sync_whois = Whois.whois("github.com")
44
+ sync_whois = throttle { Whois.whois("github.com") }
31
45
 
32
- async_whois.properties.should == sync_whois.properties
46
+ expect(properties_for(async_whois)).to eq(properties_for(sync_whois))
33
47
  end
34
48
 
35
49
  end
@@ -37,13 +51,13 @@ end
37
51
  describe "Synchronous WHOIS" do
38
52
 
39
53
  it "should not use asynchronous socket methods" do
40
- Whois::Server::Adapters::Base.any_instance.should_not_receive(:em_ask_the_socket)
54
+ expect_any_instance_of(Whois::Server::SocketHandler).to_not receive(:em_call)
41
55
 
42
- whois = Whois.whois("google.com")
43
- whois.should_not be_available # Sanity check
56
+ whois = throttle { Whois.whois("google.com") }
57
+ expect(whois.parser).to_not be_available # Sanity check
44
58
 
45
- whois = Whois.whois("#{rand(Time.now.to_i)}-alskdjflkasjd.com")
46
- whois.should be_available # Sanity check
59
+ whois = throttle { Whois.whois("#{rand(Time.now.to_i)}-alskdjflkasjd.com") }
60
+ expect(whois.parser).to be_available # Sanity check
47
61
  end
48
62
 
49
63
  end
metadata CHANGED
@@ -1,38 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-whois
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
5
- prerelease:
4
+ version: 0.4.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mike Jarema
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-27 00:00:00.000000000 Z
11
+ date: 2018-06-25 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: em-synchrony
16
- requirement: &70358519233500 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *70358519233500
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
25
27
  - !ruby/object:Gem::Dependency
26
28
  name: whois
27
- requirement: &70358519246440 !ruby/object:Gem::Requirement
28
- none: false
29
+ requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
- - - =
31
+ - - '='
31
32
  - !ruby/object:Gem::Version
32
- version: 2.7.0
33
+ version: 4.0.6
33
34
  type: :runtime
34
35
  prerelease: false
35
- version_requirements: *70358519246440
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: whois-parser
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.1.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.1.0
36
83
  description: Asynchronous WHOIS queries via EventMachine (based on synchronous whois
37
84
  gem)
38
85
  email: mike@jarema.com
@@ -40,42 +87,41 @@ executables: []
40
87
  extensions: []
41
88
  extra_rdoc_files: []
42
89
  files:
43
- - VERSION.yml
44
- - README.md
45
- - .rspec
90
+ - ".rspec"
46
91
  - Gemfile
47
- - Gemfile.lock
92
+ - README.md
48
93
  - Rakefile
49
- - examples/async_whois.rb
94
+ - VERSION.yml
95
+ - em-whois.gemspec
50
96
  - examples/async_parallel_whois.rb
97
+ - examples/async_whois.rb
51
98
  - examples/sync_whois.rb
52
99
  - lib/em-whois.rb
53
100
  - spec/em-whois_spec.rb
54
101
  - spec/helper/all.rb
55
102
  homepage: http://github.com/mikejarema/em-whois
56
103
  licenses: []
104
+ metadata: {}
57
105
  post_install_message:
58
106
  rdoc_options:
59
- - --charset=UTF-8
107
+ - "--charset=UTF-8"
60
108
  require_paths:
61
109
  - lib
62
110
  required_ruby_version: !ruby/object:Gem::Requirement
63
- none: false
64
111
  requirements:
65
- - - ! '>='
112
+ - - ">="
66
113
  - !ruby/object:Gem::Version
67
- version: '0'
114
+ version: 2.0.0
68
115
  required_rubygems_version: !ruby/object:Gem::Requirement
69
- none: false
70
116
  requirements:
71
- - - ! '>='
117
+ - - ">="
72
118
  - !ruby/object:Gem::Version
73
119
  version: '0'
74
120
  requirements: []
75
121
  rubyforge_project:
76
- rubygems_version: 1.8.11
122
+ rubygems_version: 2.6.13
77
123
  signing_key:
78
- specification_version: 3
124
+ specification_version: 4
79
125
  summary: Query WHOIS servers using native EventMachine connection classes.
80
126
  test_files:
81
127
  - spec/em-whois_spec.rb
@@ -1,26 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- diff-lcs (1.1.3)
5
- em-synchrony (1.0.2)
6
- eventmachine (>= 1.0.0.beta.1)
7
- eventmachine (1.0.0)
8
- rake (0.9.2.2)
9
- rspec (2.11.0)
10
- rspec-core (~> 2.11.0)
11
- rspec-expectations (~> 2.11.0)
12
- rspec-mocks (~> 2.11.0)
13
- rspec-core (2.11.1)
14
- rspec-expectations (2.11.3)
15
- diff-lcs (~> 1.1.3)
16
- rspec-mocks (2.11.3)
17
- whois (2.7.0)
18
-
19
- PLATFORMS
20
- ruby
21
-
22
- DEPENDENCIES
23
- em-synchrony
24
- rake
25
- rspec
26
- whois (= 2.7.0)