Class: Rapidoc::HttpResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/rapidoc/http_response.rb

Overview

Represent http status code with code and description. Also include bootstrap label for code.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code) ⇒ HttpResponse

Returns a new instance of HttpResponse.



13
14
15
16
17
# File 'lib/rapidoc/http_response.rb', line 13

def initialize( code )
  @code = code
  @description = get_description
  @label = get_label
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



11
12
13
# File 'lib/rapidoc/http_response.rb', line 11

def code
  @code
end

#descriptionObject (readonly)

Returns the value of attribute description.



11
12
13
# File 'lib/rapidoc/http_response.rb', line 11

def description
  @description
end

#labelObject (readonly)

Returns the value of attribute label.



11
12
13
# File 'lib/rapidoc/http_response.rb', line 11

def label
  @label
end

Instance Method Details

#get_descriptionObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rapidoc/http_response.rb', line 19

def get_description
  case @code
    when 200
      'OK'
    when 201
      'Created'
    when 204
      'No content'
    when 401
      'Access Denied'
    when 403
      'Forbidden'
    when 404
      'Not found'
    when 422
      'Unprocessable Entity'
    when 400
      'Bad Request'
    else
      ''
  end
end

#get_labelObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rapidoc/http_response.rb', line 42

def get_label
  case @code
    when 200
      'label label-info'
    when 201
      'label label-success'
    when 204
      'label label-info2'
    when 401
      'label label-warning'
    when 403
      'label label-warning2'
    when 422
      'label label-important'
    when 404
      'label label-inverse'
    else
      'label'
  end
end