Class: MonoVM::Whois::Endpoint
- Inherits:
-
Object
- Object
- MonoVM::Whois::Endpoint
- Defined in:
- lib/monovm/whois/endpoint.rb
Overview
Where a query gets sent, and over which protocol.
Server definitions describe two very different things with one string:
socket://whois.nic.uk is a host to open a TCP connection to, while
https://rdap.verisign.com/com/v1/domain/ is a URL prefix. This object
normalises both so Transport::Factory can pick a transport by asking
#kind rather than by re-parsing strings all over the codebase.
Constant Summary collapse
- SOCKET_SCHEME =
"socket"- DEFAULT_WHOIS_PORT =
43- PLACEHOLDER =
Substituted with the queried name when present, so an unusual endpoint can put the domain somewhere other than the end of the URL.
"{domain}"
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#scheme ⇒ Object
readonly
Returns the value of attribute scheme.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#http? ⇒ Boolean
True for RDAP or any other HTTP-delivered service.
-
#initialize(uri) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #inspect ⇒ Object
-
#kind ⇒ Object
A coarse label used to select a transport and to tag a Response.
-
#socket? ⇒ Boolean
True for port 43 WHOIS.
- #tls? ⇒ Boolean
- #to_s ⇒ Object
-
#url_for(name) ⇒ Object
The URL to fetch for
name.
Constructor Details
#initialize(uri) ⇒ Endpoint
Returns a new instance of Endpoint.
37 38 39 40 41 42 |
# File 'lib/monovm/whois/endpoint.rb', line 37 def initialize(uri) @uri = uri @scheme = uri.split("://", 2).first.to_s.downcase parse_target! freeze end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
23 24 25 |
# File 'lib/monovm/whois/endpoint.rb', line 23 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
23 24 25 |
# File 'lib/monovm/whois/endpoint.rb', line 23 def port @port end |
#scheme ⇒ Object (readonly)
Returns the value of attribute scheme.
23 24 25 |
# File 'lib/monovm/whois/endpoint.rb', line 23 def scheme @scheme end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
23 24 25 |
# File 'lib/monovm/whois/endpoint.rb', line 23 def uri @uri end |
Class Method Details
.parse(uri) ⇒ Endpoint
30 31 32 33 34 |
# File 'lib/monovm/whois/endpoint.rb', line 30 def parse(uri) raise DefinitionsError, "endpoint is empty" if uri.nil? || uri.to_s.strip.empty? new(uri.to_s.strip) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
78 79 80 |
# File 'lib/monovm/whois/endpoint.rb', line 78 def ==(other) other.is_a?(Endpoint) && other.uri == uri end |
#hash ⇒ Object
83 84 85 |
# File 'lib/monovm/whois/endpoint.rb', line 83 def hash [self.class, uri].hash end |
#http? ⇒ Boolean
True for RDAP or any other HTTP-delivered service.
50 51 52 |
# File 'lib/monovm/whois/endpoint.rb', line 50 def http? %w[http https].include?(scheme) end |
#inspect ⇒ Object
87 88 89 |
# File 'lib/monovm/whois/endpoint.rb', line 87 def inspect "#<#{self.class.name} #{uri}>" end |
#kind ⇒ Object
A coarse label used to select a transport and to tag a Response.
59 60 61 |
# File 'lib/monovm/whois/endpoint.rb', line 59 def kind socket? ? :whois : :rdap end |
#socket? ⇒ Boolean
True for port 43 WHOIS.
45 46 47 |
# File 'lib/monovm/whois/endpoint.rb', line 45 def socket? scheme == SOCKET_SCHEME end |
#tls? ⇒ Boolean
54 55 56 |
# File 'lib/monovm/whois/endpoint.rb', line 54 def tls? scheme == "https" end |
#to_s ⇒ Object
74 75 76 |
# File 'lib/monovm/whois/endpoint.rb', line 74 def to_s uri end |
#url_for(name) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/monovm/whois/endpoint.rb', line 67 def url_for(name) raise DefinitionsError, "#{uri} is not an HTTP endpoint" unless http? return uri.sub(PLACEHOLDER, name) if uri.include?(PLACEHOLDER) "#{uri}#{name}" end |