Module: NNTP

Defined in:
lib/nntp.rb,
lib/nntp/group.rb,
lib/nntp/status.rb,
lib/nntp/article.rb,
lib/nntp/session.rb,
lib/nntp/version.rb,
lib/nntp/connection.rb,
lib/nntp/ssl_connection.rb

Overview

The main entry point for this module is the open method.

::open returns an object that is an active NNTP session. If a block is passed to it, the session object is made available therein.

Defined Under Namespace

Classes: Article, Connection, Group, SSLConnection, Session, Status

Constant Summary collapse

VERSION =
"0.0.6"

Class Method Summary collapse

Class Method Details

.open(options) ⇒ NNTP::Session

The main entrypoint to the module.

Examples:

Basic connection

nntp = NNTP.open(
  :url => 'nntp.example.org',
  :auth => {:user => 'mike', :pass => 'soopersecret'}
)
nntp.quit

Pass a block

# Automatically closes connection
NNTP.open(:url => 'nntp.example.org') do |nntp|
  nntp.group = 'alt.bin.foo'
end

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • :url (Object)

    The URL of the NNTP server.

  • :port (Object) — default: 119/563

    The port number of the server.

  • :ssl (Boolean) — default: false

    Connect via SSL?

  • :auth (Hash)

    Authentication credentials and style.

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/nntp.rb', line 31

def self.open(options)
  if options[:ssl]
    connection = SSLConnection.new(options)
  else
    connection = Connection.new(options)
  end

  session = Session.new(:connection => connection)

  session.auth(options[:auth]) if options[:auth]

  if block_given?
    yield session
    session.quit
  else
    session
  end
end