Class: Hyraft::Response

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

Constant Summary collapse

STATUS_CODES =
{
  ok: 200,
  created: 201,
  no_content: 204,
  bad_request: 400,
  unauthorized: 401,
  forbidden: 403,
  not_found: 404,
  method_not_allowed: 405,
  internal_server_error: 500
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body = "", status = 200) ⇒ Response

Returns a new instance of Response.



17
18
19
20
# File 'lib/hyraft/response.rb', line 17

def initialize(body = "", status = 200)
  @body = body
  @status = status
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



15
16
17
# File 'lib/hyraft/response.rb', line 15

def body
  @body
end

#statusObject (readonly)

Returns the value of attribute status.



15
16
17
# File 'lib/hyraft/response.rb', line 15

def status
  @status
end

Class Method Details

.bad_request(body = "Bad Request") ⇒ Object



34
35
36
# File 'lib/hyraft/response.rb', line 34

def self.bad_request(body = "Bad Request")
  new(body, STATUS_CODES[:bad_request])
end

.created(body = "") ⇒ Object



26
27
28
# File 'lib/hyraft/response.rb', line 26

def self.created(body = "")
  new(body, STATUS_CODES[:created])
end

.internal_server_error(body = "Internal Server Error") ⇒ Object



42
43
44
# File 'lib/hyraft/response.rb', line 42

def self.internal_server_error(body = "Internal Server Error")
  new(body, STATUS_CODES[:internal_server_error])
end

.no_contentObject



30
31
32
# File 'lib/hyraft/response.rb', line 30

def self.no_content
  new("", STATUS_CODES[:no_content])
end

.not_found(body = "Not Found") ⇒ Object



38
39
40
# File 'lib/hyraft/response.rb', line 38

def self.not_found(body = "Not Found")
  new(body, STATUS_CODES[:not_found])
end

.ok(body = "") ⇒ Object



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

def self.ok(body = "")
  new(body, STATUS_CODES[:ok])
end