Class: Net::Tofu::Response
- Inherits:
-
Object
- Object
- Net::Tofu::Response
- Defined in:
- lib/net/tofu/response.rb,
lib/net/tofu/error.rb
Overview
Stores a response from a Gemini server.
Defined Under Namespace
Classes: InvalidHeaderError, InvalidMetaError, InvalidRedirectError, InvalidStatusCodeError, NoServerResponseError
Constant Summary collapse
- INPUT =
Response types
1
- SUCCESS =
2
- REDIRECT =
3
- TEMPORARY_FAILURE =
4
- PERMANENT_FAILURE =
5
- REQUEST_CERTIFICATE =
6
- MAX_META_BYTESIZE =
Limits
1024
Instance Attribute Summary collapse
-
#body ⇒ String
readonly
The message body.
-
#header ⇒ String
readonly
The full response header from the server.
-
#meta ⇒ String
readonly
Dependent on the ##status -> => 1x: (INPUT) A prompt line that should be displayed to the user.
-
#status ⇒ Integer
readonly
The 2-digit, server response status.
-
#status_maj ⇒ Integer
readonly
The first digit of the server response status.
-
#status_min ⇒ Integer
readonly
The second digit of the server response status.
Instance Method Summary collapse
-
#initialize(data) ⇒ Response
constructor
Constructor for the response type.
- #input? ⇒ Boolean
- #permanent_failure? ⇒ Boolean
- #redirect? ⇒ Boolean
- #request_certificate? ⇒ Boolean
- #success? ⇒ Boolean
- #temporary_failure? ⇒ Boolean
-
#type ⇒ String
Get a human readable response type.
Constructor Details
#initialize(data) ⇒ Response
Constructor for the response type.
56 57 58 59 |
# File 'lib/net/tofu/response.rb', line 56 def initialize(data) @data = data parse end |
Instance Attribute Details
#body ⇒ String (readonly)
Returns The message body.
52 53 54 |
# File 'lib/net/tofu/response.rb', line 52 def body @body end |
#header ⇒ String (readonly)
Returns The full response header from the server.
25 26 27 |
# File 'lib/net/tofu/response.rb', line 25 def header @header end |
#meta ⇒ String (readonly)
Dependent on the ##status ->
> 1x: (INPUT) A prompt line that should be displayed to the user.
> 2x: (SUCCESS) A MIME media type.
> 3x: (REDIRECT) A new URL for the requested resource.
> 4x: (TEMP FAIL) Additional information regarding the temporary failure.
> 5x: (PERM FAIL) Additional information regarding the temporary failure.
> 6x: (RQST CERT) Additional information regarding the client certificate requirements.
According to the specification for the Gemini Protocol, clients SHOULD close a connection to servers which send a meta over 1024 bytes. This library complies with this specification, although, it is conceivable that meta could be an arbitrarily long string.
49 50 51 |
# File 'lib/net/tofu/response.rb', line 49 def @meta end |
#status ⇒ Integer (readonly)
Returns The 2-digit, server response status.
28 29 30 |
# File 'lib/net/tofu/response.rb', line 28 def status @status end |
#status_maj ⇒ Integer (readonly)
Returns The first digit of the server response status.
31 32 33 |
# File 'lib/net/tofu/response.rb', line 31 def status_maj @status_maj end |
#status_min ⇒ Integer (readonly)
Returns The second digit of the server response status.
34 35 36 |
# File 'lib/net/tofu/response.rb', line 34 def status_min @status_min end |
Instance Method Details
#input? ⇒ Boolean
75 |
# File 'lib/net/tofu/response.rb', line 75 def input?; return true if @status_maj == INPUT; false; end |
#permanent_failure? ⇒ Boolean
79 |
# File 'lib/net/tofu/response.rb', line 79 def permanent_failure?; return true if @status_maj == PERMANENT_FAILURE; false; end |
#redirect? ⇒ Boolean
77 |
# File 'lib/net/tofu/response.rb', line 77 def redirect?; return true if @status_maj == REDIRECT; false; end |
#request_certificate? ⇒ Boolean
80 |
# File 'lib/net/tofu/response.rb', line 80 def request_certificate?; return true if @status_maj == REQUEST_CERTIFICATE; false; end |
#success? ⇒ Boolean
76 |
# File 'lib/net/tofu/response.rb', line 76 def success?; return true if @status_maj == SUCCESS; false; end |
#temporary_failure? ⇒ Boolean
78 |
# File 'lib/net/tofu/response.rb', line 78 def temporary_failure?; return true if @status_maj == TEMPORARY_FAILURE; false; end |
#type ⇒ String
Get a human readable response type.
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/net/tofu/response.rb', line 63 def type case @status_maj when INPUT then return "Input" when SUCCESS then return "Success" when REDIRECT then return "Redirect" when TEMPORARY_FAILURE then return "Temporary failure" when PERMANENT_FAILURE then return "Permanent failure" when REQUEST_CERTIFICATE then return "Request certificate" end "Unknown" end |