Class: Net::NNTP::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/net/nntp/request.rb

Overview

NNTP Request base clase. Do not instantiate, use subclasses.

Class Hierarchy

  • Net::NNTP::Request

    • Net::NNTP::Authinfo

    • Net::NNTP::Capabilities

    • Net::NNTP::Date

    • Net::NNTP::Group

    • Net::NNTP::Hdr

    • Net::NNTP::Help

    • Net::NNTP::List

    • Net::NNTP::Modereader

    • Net::NNTP::Newgroups

    • Net::NNTP::Newnews

    • Net::NNTP::Over

    • Net::NNTP::PostingRequest

      • Net::NNTP::Post

      • Net::NNTP::Ihave

    • Net::NNTP::Quit

    • Net::NNTP::RetrievalRequest

      • Net::NNTP::Article

      • Net::NNTP::Body

      • Net::NNTP::Head

      • Net::NNTP::Stat

    • Net::NNTP::SelectionRequest

      • Net::NNTP::Group

      • Net::NNTP::Listgroup

      • Net::NNTP::Last

      • Net::NNTP::Next

    • Net::NNTP::Xhdr

    • Net::NNTP::Xover

    • Net::NNTP::Xpat

Instance Method Summary collapse

Constructor Details

#initialize(command, rest = nil) ⇒ Request

Returns a new instance of Request.



39
40
41
# File 'lib/net/nntp/request.rb', line 39

def initialize(command, rest=nil)
  @command = ("%s %s" % [command.upcase, rest]).strip
end

Instance Method Details

#capabilityObject

Returns the capability that the server should mention on a Capability Request to notify the user that the server is capable to process the request. Older and broken NNTP servers do not respond to a Capability request, thus leaving it to trial-and-error.



95
96
97
# File 'lib/net/nntp/request.rb', line 95

def capability
  'mandatory'
end

#commandObject



43
44
45
# File 'lib/net/nntp/request.rb', line 43

def command
  return [@command, "\r\n"].join
end

#dotstuffObject

:nodoc:



47
48
49
50
51
# File 'lib/net/nntp/request.rb', line 47

def dotstuff # :nodoc:
  # dot-stuffing. Mail SHOULD be raw
  stuff_regex = /^\./m
  @body.to_s.gsub(stuff_regex, "..")
end

#msgid_or_range(rest) ⇒ Object

:nodoc:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/net/nntp/request.rb', line 53

def msgid_or_range(rest) # :nodoc:
  rval = ''
  if rest  
    case rest
    when String
      rval = rest
    when Hash
      if rest.has_key? :msgid
        rval = rest[:msgid].to_s
      else
        rval = range(rest)
      end
    end
  end
  rval
end

#range(rest) ⇒ Object

:nodoc:



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/net/nntp/request.rb', line 70

def range(rest) # :nodoc:
  return rest unless rest
  rval = ''
  if rest.has_key? :start
    rval = rest[:start].to_s << "-"
    if rest.has_key? :end
      rval << rest[:end].to_s
    end
  end
  rval
end

#valid_response?(response) ⇒ Boolean

Can be used to make sure that the response is valid (or a generic response) according to RFCs 3977 and 4643

Returns:

  • (Boolean)


88
89
90
# File 'lib/net/nntp/request.rb', line 88

def valid_response?(response)
  response.generic? || valid_responses().include?(response.class)
end