Class: NNTP::Connection
- Inherits:
-
Object
- Object
- NNTP::Connection
- Defined in:
- lib/nntp/connection.rb
Overview
Handles communication with the NNTP server.
Most communication with an NNTP server happens in a back-and-forth
style.
The client sends a article to the server. The server will respond with a status response, and sometimes with extra data. See {https://tools.ietf.org/html/rfc3977 RFC 3977} for more details.
This class handles this communication by providing two methods,
one for use when additional data is expected, and one for when it is not.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#socket ⇒ Object
readonly
The object upon which all IO takes place.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#command(command, *args) ⇒ NNTP::Status
Sends a message to the server and collects the status response.
-
#get_status ⇒ NNTP::Status
Fetch a status line from the server.
- #initialize(options) ⇒ Object constructor
-
#query(query, *args) {|status, data| ... } ⇒ Hash
Sends a message to the server, collects the the status and additional data, if successful.
-
#quit ⇒ void
Sends “QUIT\r\n” to the server, disconnects the socket.
Constructor Details
#initialize(options) ⇒ Object
25 26 27 |
# File 'lib/nntp/connection.rb', line 25 def initialize() @socket = build_socket() end |
Instance Attribute Details
#socket ⇒ Object (readonly)
The object upon which all IO takes place.
22 23 24 |
# File 'lib/nntp/connection.rb', line 22 def socket @socket end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
22 |
# File 'lib/nntp/connection.rb', line 22 attr_reader :socket, :status |
Instance Method Details
#command(command, *args) ⇒ NNTP::Status
Sends a message to the server and collects the status response.
66 67 68 69 70 |
# File 'lib/nntp/connection.rb', line 66 def command(command, *args) command = (command, args) (command) get_status end |
#get_status ⇒ NNTP::Status
Fetch a status line from the server.
74 75 76 77 |
# File 'lib/nntp/connection.rb', line 74 def get_status code, = get_line.split(' ', 2) @status = status_factory(code.to_i, ) end |
#query(query, *args) {|status, data| ... } ⇒ Hash
Sends a message to the server, collects the the status and additional data, if successful. A Hash is returned containing two keys: :status and :data. :status is an Status, and :data is an array containing the lines from the response See example for details.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/nntp/connection.rb', line 50 def query(query, *args) command = (query, args) (command) status = get_status data = if (400..599).include? status.code nil else get_block_data end yield status, data if block_given? {:status => status, :data => data} end |
#quit ⇒ void
This method returns an undefined value.
Sends “QUIT\r\n” to the server, disconnects the socket.
81 82 83 84 |
# File 'lib/nntp/connection.rb', line 81 def quit command(:quit) socket.close end |