Class: HTTPalooza::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/httpalooza/response.rb

Overview

Response represents a unified interface for the various Player’s responses.

Constant Summary collapse

AwesomeResponseCodes =
200..299

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, body) ⇒ Response

Create a new Response.

Parameters:

  • code (Fixnum)

    the HTTP status code. Should be between 100 and 599.

  • body (String)

    the HTTP response body.



16
17
18
19
# File 'lib/httpalooza/response.rb', line 16

def initialize(code, body)
  @code = code.to_i
  @body = body
end

Instance Attribute Details

#bodyString

Returns the HTTP response body.

Returns:

  • (String)

    the HTTP response body



10
# File 'lib/httpalooza/response.rb', line 10

attr_accessor :code, :body

#codeFixnum

Returns the HTTP status code.

Returns:

  • (Fixnum)

    the HTTP status code



10
11
12
# File 'lib/httpalooza/response.rb', line 10

def code
  @code
end

Instance Method Details

#awesome?Boolean

Returns whether or not the response code was awesome.

Returns:

  • (Boolean)

    whether or not the response code was awesome.



22
23
24
# File 'lib/httpalooza/response.rb', line 22

def awesome?
  AwesomeResponseCodes.include?(code)
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


35
36
37
# File 'lib/httpalooza/response.rb', line 35

def eql?(other)
  self.class == other.class && code == other.code && body == other.body
end

#hashObject



41
42
43
# File 'lib/httpalooza/response.rb', line 41

def hash
  body.hash ^ code.hash
end

#inspectObject



31
32
33
# File 'lib/httpalooza/response.rb', line 31

def inspect
  "<HTTPalooza::Response:#{object_id} code=#{code} body=#{body.to_s.inspect.truncate(30)}"
end

#not_awesome?Boolean

Returns whether or not the response code was not awesome.

Returns:

  • (Boolean)

    whether or not the response code was not awesome.



27
28
29
# File 'lib/httpalooza/response.rb', line 27

def not_awesome?
  !awesome?
end