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
79 80 81 |
# File 'lib/vra/http.rb', line 79 def initialize(response) @response = response end |
Instance Method Details
#body ⇒ Object
98 99 100 |
# File 'lib/vra/http.rb', line 98 def body @response.body end |
#code ⇒ Object
102 103 104 |
# File 'lib/vra/http.rb', line 102 def code @response.code.to_i end |
#final? ⇒ Boolean
130 131 132 |
# File 'lib/vra/http.rb', line 130 def final? !(redirect? || see_other?) end |
#forward(request) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/vra/http.rb', line 83 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
94 95 96 |
# File 'lib/vra/http.rb', line 94 def location @response["location"] end |
#message ⇒ Object
106 107 108 |
# File 'lib/vra/http.rb', line 106 def @response. end |
#redirect? ⇒ Boolean
122 123 124 |
# File 'lib/vra/http.rb', line 122 def redirect? [301, 302, 307].include?(code) end |
#see_other? ⇒ Boolean
126 127 128 |
# File 'lib/vra/http.rb', line 126 def see_other? code == 303 end |
#success? ⇒ Boolean
118 119 120 |
# File 'lib/vra/http.rb', line 118 def success? (200..207).cover?(code) end |
#success_no_content? ⇒ Boolean
114 115 116 |
# File 'lib/vra/http.rb', line 114 def success_no_content? code == 204 end |
#success_ok? ⇒ Boolean
110 111 112 |
# File 'lib/vra/http.rb', line 110 def success_ok? code == 200 end |