Class: Vra::Http::Response
- Inherits:
-
Object
- Object
- Vra::Http::Response
- Defined in:
- lib/vra/http.rb
Instance Method Summary collapse
- #body ⇒ Object
- #code ⇒ Object
- #final? ⇒ Boolean
- #forward(request) ⇒ Object
-
#initialize(response) ⇒ Response
constructor
For hiding the details of the HTTP response class so it can be swapped out easily.
- #location ⇒ Object
- #message ⇒ Object
- #redirect? ⇒ Boolean
- #see_other? ⇒ Boolean
- #success? ⇒ Boolean
- #success_no_content? ⇒ Boolean
- #success_ok? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Response
For hiding the details of the HTTP response class so it can be swapped out easily
78 79 80 |
# File 'lib/vra/http.rb', line 78 def initialize(response) @response = response end |
Instance Method Details
#body ⇒ Object
97 98 99 |
# File 'lib/vra/http.rb', line 97 def body @response.body end |
#code ⇒ Object
101 102 103 |
# File 'lib/vra/http.rb', line 101 def code @response.code.to_i end |
#final? ⇒ Boolean
129 130 131 |
# File 'lib/vra/http.rb', line 129 def final? !(redirect? || see_other?) end |
#forward(request) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/vra/http.rb', line 82 def forward(request) if redirect? fail Http.error(self) unless request.redirectable? request.redirect_to(location) elsif see_other? request.see_other(location) else request end end |
#location ⇒ Object
93 94 95 |
# File 'lib/vra/http.rb', line 93 def location @response['location'] end |
#message ⇒ Object
105 106 107 |
# File 'lib/vra/http.rb', line 105 def @response. end |
#redirect? ⇒ Boolean
121 122 123 |
# File 'lib/vra/http.rb', line 121 def redirect? [301, 302, 307].include?(code) end |
#see_other? ⇒ Boolean
125 126 127 |
# File 'lib/vra/http.rb', line 125 def see_other? code == 303 end |
#success? ⇒ Boolean
117 118 119 |
# File 'lib/vra/http.rb', line 117 def success? (200..207).cover?(code) end |
#success_no_content? ⇒ Boolean
113 114 115 |
# File 'lib/vra/http.rb', line 113 def success_no_content? code == 204 end |
#success_ok? ⇒ Boolean
109 110 111 |
# File 'lib/vra/http.rb', line 109 def success_ok? code == 200 end |