Class: Vra::Http::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/vra/http.rb

Instance Method Summary collapse

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

#bodyObject



98
99
100
# File 'lib/vra/http.rb', line 98

def body
  @response.body
end

#codeObject



102
103
104
# File 'lib/vra/http.rb', line 102

def code
  @response.code.to_i
end

#final?Boolean

Returns:

  • (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

#locationObject



94
95
96
# File 'lib/vra/http.rb', line 94

def location
  @response["location"]
end

#messageObject



106
107
108
# File 'lib/vra/http.rb', line 106

def message
  @response.message
end

#redirect?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/vra/http.rb', line 122

def redirect?
  [301, 302, 307].include?(code)
end

#see_other?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/vra/http.rb', line 126

def see_other?
  code == 303
end

#success?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/vra/http.rb', line 118

def success?
  (200..207).cover?(code)
end

#success_no_content?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/vra/http.rb', line 114

def success_no_content?
  code == 204
end

#success_ok?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/vra/http.rb', line 110

def success_ok?
  code == 200
end