Class: SFML::Network::Http::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/sfml/network/http.rb

Overview

Read-only view onto a CSFML sfHttpResponse. Wraps the C pointer in a Ruby object that destroys the response when GC’d.

Constant Summary collapse

STATUS_NAMES =

Status mappings — most map onto standard HTTP codes; the four at the bottom are SFML-side transport errors above the standard range (≥ 1000).

{
  200 => :ok, 201 => :created, 202 => :accepted, 204 => :no_content,
  205 => :reset_content, 206 => :partial_content,
  301 => :multiple_choices, 302 => :moved_permanently, 303 => :moved_temporarily,
  304 => :not_modified,
  400 => :bad_request, 401 => :unauthorized, 403 => :forbidden, 404 => :not_found,
  405 => :range_not_satisfiable,
  500 => :internal_server_error, 501 => :not_implemented, 502 => :bad_gateway,
  503 => :service_not_available, 504 => :gateway_timeout, 505 => :version_not_supported,
  1000 => :invalid_response, 1001 => :connection_failed,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResponse

Returns a new instance of Response.

Raises:

  • (NoMethodError)


81
82
83
# File 'lib/sfml/network/http.rb', line 81

def initialize
  raise NoMethodError, "use SFML::Network::Http#send_request to create a Response"
end

Instance Attribute Details

#handleObject (readonly)

:nodoc:



105
106
107
# File 'lib/sfml/network/http.rb', line 105

def handle
  @handle
end

Instance Method Details

#bodyObject



95
# File 'lib/sfml/network/http.rb', line 95

def body  = C::Network.sfHttpResponse_getBody(@handle).to_s

#field(name) ⇒ Object



96
# File 'lib/sfml/network/http.rb', line 96

def field(name) = C::Network.sfHttpResponse_getField(@handle, name.to_s)

#http_versionObject



98
99
100
101
102
103
# File 'lib/sfml/network/http.rb', line 98

def http_version
  [
    C::Network.sfHttpResponse_getMajorVersion(@handle),
    C::Network.sfHttpResponse_getMinorVersion(@handle),
  ]
end

#statusObject



85
86
87
# File 'lib/sfml/network/http.rb', line 85

def status
  C::Network.sfHttpResponse_getStatus(@handle)
end

#status_symbolObject

The status as a symbol when CSFML maps it, otherwise the raw integer. Useful for ‘case resp.status_symbol in :ok`.



91
92
93
# File 'lib/sfml/network/http.rb', line 91

def status_symbol
  STATUS_NAMES[status] || status
end