Class: Net::NNTP::Response
- Inherits:
-
Object
- Object
- Net::NNTP::Response
- Defined in:
- lib/net/nntp/response.rb,
lib/net/nntp/response.rb
Overview
Base response class. Parent of all responses. DO NOT instantiate directly unless you’re ready to handle the nitty gritty yourself.
Class Tree:
-
Net::NNTP::Response
-
InformationResponse
-
HelpResponse
-
CapabilityList
-
DateResponse
-
-
OKResponse
-
PostingAllowed
-
PostingProhibited
-
ConnectionClosing
-
GroupSelected
-
ListInformationFollows
-
ArticleResponse
-
HeaderResponse
-
BodyResponse
-
ArticleSelected
-
OverviewInformation
-
HdrResponse
-
NewnewsResponse
-
NewgroupsResponse
-
TransferOK
-
ArticleReceived
-
AuthenticationAccepted
-
-
Direct Known Subclasses
ContinueResponse, FailResponse, InformationResponse, OKResponse, RetryResponse, UnknownResponse
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#request ⇒ Object
Returns the value of attribute request.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#body ⇒ Object
Returns the body in subclasses; returns nil in Response.
- #force_close? ⇒ Boolean
-
#generic? ⇒ Boolean
Returns the value of the generic attribute, set by the generic parameter to new.
-
#has_body? ⇒ Boolean
Returns true if the response is a multiline response and has a body set.
-
#initialize(request, code, message, generic = false, multiline = false) ⇒ Response
constructor
-
Parameter
code
is the code returned from the server, should be a string representing the first three bytes (digits).
-
-
#multiline? ⇒ Boolean
Returns the value of the multiline attribute, set by the multiline parameter to new.
- #needs_article? ⇒ Boolean
Constructor Details
#initialize(request, code, message, generic = false, multiline = false) ⇒ Response
-
Parameter
code
is the code returned from the server, should be a string representing the first three bytes (digits). -
Parameter
message
is the message following the code on the status line without the separating whitespace. -
Parameter
generic
gives the subclasses the opportunity to denote if the response is a generic response according to the RFC, and therefor valid following any request, or if the response is a response that MUST follow a certain request. See Request for validating responses. -
Parameter
multiline
gives the subclasses the opportunity to denote if the response is a multiline response according to RFC, and if a body is to be expected.
97 98 99 100 101 102 103 |
# File 'lib/net/nntp/response.rb', line 97 def initialize(request, code, , generic=false, multiline=false) @code = code @message = @generic=generic @multiline = multiline @request = request end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
88 89 90 |
# File 'lib/net/nntp/response.rb', line 88 def code @code end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
88 89 90 |
# File 'lib/net/nntp/response.rb', line 88 def @message end |
#request ⇒ Object
Returns the value of attribute request.
711 712 713 |
# File 'lib/net/nntp/response.rb', line 711 def request @request end |
Class Method Details
.class_from_code(code) ⇒ Object
720 721 722 723 724 |
# File 'lib/net/nntp/response.rb', line 720 def class_from_code(code) Net::NNTP::RESPONSES[code] or Net::NNTP::CLASSES[code[0,1]] or Net::NNTP::UnknownResponse end |
.create(request, statusline) ⇒ Object
713 714 715 716 717 718 719 |
# File 'lib/net/nntp/response.rb', line 713 def create(request, statusline) match = statusline.strip.match(/\A(\d{3})\s?(.*)\z/) or raise ProtocolError, "Unknown Response" Net::NNTP.logger.debug("Response#create: request = #{request}") klass = class_from_code(match[1]) Net::NNTP.logger.debug("Response#create: class = #{klass}") this = klass.new(request, *match.captures) end |
Instance Method Details
#==(other) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/net/nntp/response.rb', line 125 def ==(other) if other.is_a? Response self.class == other.class && self.code == other.code && self. == other. && self.multiline? == other.multiline? && self.generic? == other.generic? && self.body == other.body else return false end end |
#body ⇒ Object
Returns the body in subclasses; returns nil in Response.
121 122 123 |
# File 'lib/net/nntp/response.rb', line 121 def body nil end |
#force_close? ⇒ Boolean
137 138 139 |
# File 'lib/net/nntp/response.rb', line 137 def force_close? false end |
#generic? ⇒ Boolean
Returns the value of the generic attribute, set by the generic parameter to new.
106 107 108 |
# File 'lib/net/nntp/response.rb', line 106 def generic? @generic end |
#has_body? ⇒ Boolean
Returns true if the response is a multiline response and has a body set.
116 117 118 |
# File 'lib/net/nntp/response.rb', line 116 def has_body? multiline? && body end |
#multiline? ⇒ Boolean
Returns the value of the multiline attribute, set by the multiline parameter to new.
111 112 113 |
# File 'lib/net/nntp/response.rb', line 111 def multiline? @multiline end |
#needs_article? ⇒ Boolean
133 134 135 |
# File 'lib/net/nntp/response.rb', line 133 def needs_article? false end |