Class: Net::Tofu::Response

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Response

Constructor for the response type.

Parameters:

  • data (String)

    A raw Gemini server response.



56
57
58
59
# File 'lib/net/tofu/response.rb', line 56

def initialize(data)
  @data = data
  parse
end

Instance Attribute Details

#bodyString (readonly)

Returns The message body.

Returns:

  • (String)

    The message body.



52
53
54
# File 'lib/net/tofu/response.rb', line 52

def body
  @body
end

#headerString (readonly)

Returns The full response header from the server.

Returns:

  • (String)

    The full response header from the server.



25
26
27
# File 'lib/net/tofu/response.rb', line 25

def header
  @header
end

#metaString (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.

Returns:

  • (String)

    The UTF-8 encoded message from the response header.



49
50
51
# File 'lib/net/tofu/response.rb', line 49

def meta
  @meta
end

#statusInteger (readonly)

Returns The 2-digit, server response status.

Returns:

  • (Integer)

    The 2-digit, server response status.



28
29
30
# File 'lib/net/tofu/response.rb', line 28

def status
  @status
end

#status_majInteger (readonly)

Returns The first digit of the server response status.

Returns:

  • (Integer)

    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_minInteger (readonly)

Returns The second digit of the server response status.

Returns:

  • (Integer)

    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

Returns:

  • (Boolean)


75
# File 'lib/net/tofu/response.rb', line 75

def input?; return true if @status_maj == INPUT; false; end

#permanent_failure?Boolean

Returns:

  • (Boolean)


79
# File 'lib/net/tofu/response.rb', line 79

def permanent_failure?; return true if @status_maj == PERMANENT_FAILURE; false; end

#redirect?Boolean

Returns:

  • (Boolean)


77
# File 'lib/net/tofu/response.rb', line 77

def redirect?; return true if @status_maj == REDIRECT; false; end

#request_certificate?Boolean

Returns:

  • (Boolean)


80
# File 'lib/net/tofu/response.rb', line 80

def request_certificate?; return true if @status_maj == REQUEST_CERTIFICATE; false; end

#success?Boolean

Returns:

  • (Boolean)


76
# File 'lib/net/tofu/response.rb', line 76

def success?; return true if @status_maj == SUCCESS; false; end

#temporary_failure?Boolean

Returns:

  • (Boolean)


78
# File 'lib/net/tofu/response.rb', line 78

def temporary_failure?; return true if @status_maj == TEMPORARY_FAILURE; false; end

#typeString

Get a human readable response type.

Returns:

  • (String)

    The response type as a human readable string.



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