rdap 0.1.1 → 0.1.2

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +4 -2
  4. data/lib/rdap.rb +11 -7
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37097088b19ddfd4d65ce6d2968da8b6096920134246a8c9ec9277167f80e1be
4
- data.tar.gz: 48422426b1fbd15c7a69c6f4b72cda5588a6983e737b9a687311154e6475f1ca
3
+ metadata.gz: 4e69ad7a89e29236bafe929483ee9301df0aa0c0006fb155aaf535c14546a0f7
4
+ data.tar.gz: 9d39d5c313e4f60866d450304a45db8567f90e447c65745577e5ae4d5ca6b1f9
5
5
  SHA512:
6
- metadata.gz: b2952f430513e86e4b35d48c4b90246ba53ff279053043caa15822513a462079e468d09872c4db42fe3ad3e79383f22db550301b758b09af0ec86a2577700bf3
7
- data.tar.gz: 8b5a306cccb1972ad7d530d8b53ea97c6656f455e80436559a46460b1634d177f3706a4f9bd7ae7f545fea0ece6c7345fe7148803848e37997a4a74577589990
6
+ metadata.gz: 1070aa7fc4fbabdc4b23d1464fd951a9cd1acb24c43daf1f3e155ce05dd9d56a4ad94a62e6c765a78c6c9adef9b7a6adb7f02ea70210d3eeb994d2c9e9ce1275
7
+ data.tar.gz: 57a7fd13c4bdd7c07d881b0815fd6126aaefca9422f464d8293107a399f84793bd94a93c55cc04d671fcb609ff3c3a8375a4ac8f17985a1e86b8b314951029b3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rdap (0.1.0)
4
+ rdap (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -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,8 +84,9 @@ 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.1** (2021-12-19) - Added TooManyRequests expection in case of 429
87
- **0.1.0** (2021-12-17) - Initial version
87
+ - **0.1.2** (2022-01-07) - Added HTTP headers customization
88
+ - **0.1.1** (2021-12-19) - Added TooManyRequests expection in case of 429
89
+ - **0.1.0** (2021-12-17) - Initial version
88
90
 
89
91
  ## Contributing
90
92
 
data/lib/rdap.rb CHANGED
@@ -2,9 +2,13 @@ require 'json'
2
2
  require 'net/http'
3
3
 
4
4
  module RDAP
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
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
@@ -23,15 +27,15 @@ module RDAP
23
27
  query name, type: :autnum, **opts
24
28
  end
25
29
 
26
- def self.query name, type:, timeout: 5, server: BOOTSTRAP
30
+ def self.query name, type:, timeout: 5, server: BOOTSTRAP, headers: {}
27
31
  TYPES.include?(type) or raise ArgumentError.new("RDAP: Invalid query type: #{type}, supported types: #{TYPES}")
28
32
  uri = URI("#{server.chomp('/')}/#{type}/#{name}")
29
- get_follow_redirects(uri, timeout: timeout)
33
+ get_follow_redirects(uri, timeout: timeout, headers: headers)
30
34
  end
31
35
 
32
36
  private
33
37
 
34
- def self.get_follow_redirects uri, timeout: 5, redirection_limit: 5
38
+ def self.get_follow_redirects uri, timeout: 5, headers: {}, redirection_limit: 5
35
39
  raise ServerError.new("Too many redirections (> #{redirection_limit}) at #{uri}") if redirection_limit == 0
36
40
 
37
41
  http = Net::HTTP.new(uri.host, uri.port)
@@ -40,7 +44,7 @@ module RDAP
40
44
  http.use_ssl = true
41
45
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
42
46
 
43
- response = http.get(uri.path, "Accept" => "application/rdap+json")
47
+ response = http.get(uri.path, HEADERS.merge(headers))
44
48
  case response
45
49
  when Net::HTTPSuccess
46
50
  document = JSON.parse(response.body)
@@ -58,7 +62,7 @@ module RDAP
58
62
  when Net::HTTPTooManyRequests
59
63
  raise TooManyRequests.new("[#{response.code}] #{response.message}")
60
64
  when Net::HTTPRedirection
61
- get_follow_redirects(URI(response["location"]), timeout: timeout, redirection_limit: redirection_limit - 1)
65
+ get_follow_redirects(URI(response["location"]), timeout: timeout, headers: headers, redirection_limit: redirection_limit - 1)
62
66
  else
63
67
  raise ServerError.new("[#{response.code}] #{response.message}")
64
68
  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.1
4
+ version: 0.1.2
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: 2021-12-19 00:00:00.000000000 Z
11
+ date: 2022-01-07 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.1.2
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