rdap 0.1.0 → 0.1.4
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.
- checksums.yaml +4 -4
- data/.travis.yml +4 -2
- data/Gemfile +1 -0
- data/Gemfile.lock +13 -1
- data/README.md +7 -2
- data/lib/rdap.rb +24 -7
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e381820dc8920d506d751cf7c1d562dd4f7bcaac07aeec9c735bad6777a41019
|
4
|
+
data.tar.gz: 2a5c7562f80f162d88b24a999e67e9ae3cba5b677ff84aab48adfc5ae1c3df7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff41ec54dd637813e4120feeb21048b179d617554da50e02db122da69a37aa066bb44eae785e1840d01b9afb19bd08182c3b8dd364e2b433ad4d89a5b1403968
|
7
|
+
data.tar.gz: 59d8e5dc3ba89b4f22025081710658b248ea062357451fd4952468cb06aba605a2123f3ce8deb0d1fea91d5690a60f4fe9f28812c4b2acaaef1ffa9289b32774
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,20 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rdap (0.1.
|
4
|
+
rdap (0.1.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
addressable (2.8.0)
|
10
|
+
public_suffix (>= 2.0.2, < 5.0)
|
11
|
+
crack (0.4.5)
|
12
|
+
rexml
|
9
13
|
diff-lcs (1.4.4)
|
14
|
+
hashdiff (1.0.1)
|
15
|
+
public_suffix (4.0.6)
|
10
16
|
rake (13.0.6)
|
17
|
+
rexml (3.2.5)
|
11
18
|
rspec (3.10.0)
|
12
19
|
rspec-core (~> 3.10.0)
|
13
20
|
rspec-expectations (~> 3.10.0)
|
@@ -22,6 +29,10 @@ GEM
|
|
22
29
|
rspec-support (~> 3.10.0)
|
23
30
|
rspec-support (3.10.3)
|
24
31
|
vcr (6.0.0)
|
32
|
+
webmock (3.14.0)
|
33
|
+
addressable (>= 2.8.0)
|
34
|
+
crack (>= 0.3.2)
|
35
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
25
36
|
|
26
37
|
PLATFORMS
|
27
38
|
ruby
|
@@ -31,6 +42,7 @@ DEPENDENCIES
|
|
31
42
|
rdap!
|
32
43
|
rspec (~> 3.0)
|
33
44
|
vcr (~> 6.0)
|
45
|
+
webmock
|
34
46
|
|
35
47
|
BUNDLED WITH
|
36
48
|
2.1.4
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# RDAP
|
1
|
+
# RDAP [](https://app.travis-ci.com/github/jarthod/rdap)
|
2
2
|
|
3
3
|
A minimal Ruby client to query RDAP APIs though a bootstrap server.
|
4
4
|
No dependencies, no caching or bootstrap file (the query is routed through a bootstrap server first).
|
@@ -63,6 +63,7 @@ RDAP.query("16276", type: :autnum)
|
|
63
63
|
RDAP.domain("google.com", server: "https://rdap-bootstrap.arin.net/bootstrap") # Specify an alternative bootstrap server
|
64
64
|
RDAP.domain("google.com", server: "https://rdap.verisign.com/com/v1") # Or directly the target RDAP server if you know it
|
65
65
|
RDAP.domain("google.com", timeout: 20) # Customize open and read timeouts (default = 5 sec each)
|
66
|
+
RDAP.domain("google.com", headers: {'User-Agent' => 'My application name'}) # Override some HTTP request headers. Default headers are in RDAP::HEADERS
|
66
67
|
|
67
68
|
# Error handling
|
68
69
|
RDAP.domain("test.fr") # TLD not supported yet
|
@@ -83,7 +84,11 @@ The gem make a query to one of the publicly available RDAP bootstrap server (the
|
|
83
84
|
|
84
85
|
## Changelog
|
85
86
|
|
86
|
-
**0.1.
|
87
|
+
- **0.1.4** (2022-02-01) - Wrap JSON parser errors as RDAP::InvalidReponse and also raise RDAP::EmptyResponse when body is missing
|
88
|
+
- **0.1.3** (2022-01-10) - Wrap SSL errors as RDAP::SSLError < ServerError < Error
|
89
|
+
- **0.1.2** (2022-01-07) - Added HTTP headers customization
|
90
|
+
- **0.1.1** (2021-12-19) - Added TooManyRequests expection in case of 429
|
91
|
+
- **0.1.0** (2021-12-17) - Initial version
|
87
92
|
|
88
93
|
## Contributing
|
89
94
|
|
data/lib/rdap.rb
CHANGED
@@ -2,13 +2,21 @@ require 'json'
|
|
2
2
|
require 'net/http'
|
3
3
|
|
4
4
|
module RDAP
|
5
|
-
VERSION = "0.1.
|
5
|
+
VERSION = "0.1.4"
|
6
6
|
BOOTSTRAP = "https://rdap.org/"
|
7
|
-
TYPES = [:domain, :ip, :autnum]
|
7
|
+
TYPES = [:domain, :ip, :autnum].freeze
|
8
|
+
HEADERS = {
|
9
|
+
"User-Agent" => "RDAP ruby gem (#{VERSION})",
|
10
|
+
"Accept" => "application/rdap+json"
|
11
|
+
}
|
8
12
|
|
9
13
|
class Error < StandardError; end
|
10
14
|
class ServerError < Error; end
|
15
|
+
class SSLError < ServerError; end
|
16
|
+
class EmptyResponse < ServerError; end
|
17
|
+
class InvalidResponse < ServerError; end
|
11
18
|
class NotFound < Error; end
|
19
|
+
class TooManyRequests < Error; end
|
12
20
|
|
13
21
|
def self.domain name, **opts
|
14
22
|
query name, type: :domain, **opts
|
@@ -22,15 +30,15 @@ module RDAP
|
|
22
30
|
query name, type: :autnum, **opts
|
23
31
|
end
|
24
32
|
|
25
|
-
def self.query name, type:, timeout: 5, server: BOOTSTRAP
|
33
|
+
def self.query name, type:, timeout: 5, server: BOOTSTRAP, headers: {}
|
26
34
|
TYPES.include?(type) or raise ArgumentError.new("RDAP: Invalid query type: #{type}, supported types: #{TYPES}")
|
27
35
|
uri = URI("#{server.chomp('/')}/#{type}/#{name}")
|
28
|
-
get_follow_redirects(uri, timeout: timeout)
|
36
|
+
get_follow_redirects(uri, timeout: timeout, headers: headers)
|
29
37
|
end
|
30
38
|
|
31
39
|
private
|
32
40
|
|
33
|
-
def self.get_follow_redirects uri, timeout: 5, redirection_limit: 5
|
41
|
+
def self.get_follow_redirects uri, timeout: 5, headers: {}, redirection_limit: 5
|
34
42
|
raise ServerError.new("Too many redirections (> #{redirection_limit}) at #{uri}") if redirection_limit == 0
|
35
43
|
|
36
44
|
http = Net::HTTP.new(uri.host, uri.port)
|
@@ -39,9 +47,12 @@ module RDAP
|
|
39
47
|
http.use_ssl = true
|
40
48
|
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
41
49
|
|
42
|
-
response = http.get(uri.path,
|
50
|
+
response = http.get(uri.path, HEADERS.merge(headers))
|
43
51
|
case response
|
44
52
|
when Net::HTTPSuccess
|
53
|
+
if !response.body
|
54
|
+
raise EmptyResponse.new("[#{response.code}] #{response.message}")
|
55
|
+
end
|
45
56
|
document = JSON.parse(response.body)
|
46
57
|
if document["errorCode"]
|
47
58
|
raise ServerError.new("[#{document["errorCode"]}] #{document["title"]} (#{uri})")
|
@@ -54,10 +65,16 @@ module RDAP
|
|
54
65
|
else
|
55
66
|
raise NotFound.new("[#{response.code}] #{response.message}")
|
56
67
|
end
|
68
|
+
when Net::HTTPTooManyRequests
|
69
|
+
raise TooManyRequests.new("[#{response.code}] #{response.message}")
|
57
70
|
when Net::HTTPRedirection
|
58
|
-
get_follow_redirects(URI(response["location"]), timeout: timeout, redirection_limit: redirection_limit - 1)
|
71
|
+
get_follow_redirects(URI(response["location"]), timeout: timeout, headers: headers, redirection_limit: redirection_limit - 1)
|
59
72
|
else
|
60
73
|
raise ServerError.new("[#{response.code}] #{response.message}")
|
61
74
|
end
|
75
|
+
rescue OpenSSL::SSL::SSLError => e
|
76
|
+
raise SSLError.new("#{e.message} (#{uri.host})")
|
77
|
+
rescue JSON::ParserError => e
|
78
|
+
raise InvalidResponse.new("JSON parser error: #{e.message}")
|
62
79
|
end
|
63
80
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrien Rey-Jarthon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -44,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
requirements: []
|
47
|
-
rubygems_version: 3.
|
47
|
+
rubygems_version: 3.3.0
|
48
48
|
signing_key:
|
49
49
|
specification_version: 4
|
50
50
|
summary: A minimal Ruby client to query RDAP APIs though a bootstrap server
|