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
80 81 82 |
# File 'lib/vra/http.rb', line 80 def initialize(response) @response = response end |
Instance Method Details
#body ⇒ Object
99 100 101 |
# File 'lib/vra/http.rb', line 99 def body @response.body end |
#code ⇒ Object
103 104 105 |
# File 'lib/vra/http.rb', line 103 def code @response.code.to_i end |
#final? ⇒ Boolean
131 132 133 |
# File 'lib/vra/http.rb', line 131 def final? !(redirect? || see_other?) end |
#forward(request) ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/vra/http.rb', line 84 def forward(request) if redirect? raise Http.error(self) unless request.redirectable? request.redirect_to(location) elsif see_other? request.see_other(location) else request end end |
#location ⇒ Object
95 96 97 |
# File 'lib/vra/http.rb', line 95 def location @response["location"] end |
#message ⇒ Object
107 108 109 |
# File 'lib/vra/http.rb', line 107 def @response. end |
#redirect? ⇒ Boolean
123 124 125 |
# File 'lib/vra/http.rb', line 123 def redirect? [301, 302, 307].include?(code) end |
#see_other? ⇒ Boolean
127 128 129 |
# File 'lib/vra/http.rb', line 127 def see_other? code == 303 end |
#success? ⇒ Boolean
119 120 121 |
# File 'lib/vra/http.rb', line 119 def success? (200..207).cover?(code) end |
#success_no_content? ⇒ Boolean
115 116 117 |
# File 'lib/vra/http.rb', line 115 def success_no_content? code == 204 end |
#success_ok? ⇒ Boolean
111 112 113 |
# File 'lib/vra/http.rb', line 111 def success_ok? code == 200 end |