Class: Net::Text::Generic

Inherits:
Object
  • Object
show all
Defined in:
lib/net/text/generic.rb

Overview

Generic interface to be used by specific network protocol implementation.

Direct Known Subclasses

Finger, Gopher, Nex

Class Method Summary collapse

Class Method Details

.build_uri(string_or_uri, uri_class) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
# File 'lib/net/text/generic.rb', line 19

def self.build_uri(string_or_uri, uri_class)
  string_or_uri = URI(string_or_uri) if string_or_uri.is_a?(String)
  return string_or_uri if string_or_uri.is_a?(uri_class)

  raise ArgumentError, "uri is not a String, nor an #{uri_class.name}"
end

.request(uri, query) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/net/text/generic.rb', line 9

def self.request(uri, query)
  sock = TCPSocket.new(uri.host, uri.port)
  sock.puts query
  sock.read
ensure
  # Stop remaining connection, even if they should be already cut
  # by the server
  sock&.close
end