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



80
81
82
# File 'lib/vra/http.rb', line 80

def initialize(response)
  @response = response
end

Instance Method Details

#bodyObject



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

def body
  @response.body
end

#codeObject



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

def code
  @response.code.to_i
end

#final?Boolean

Returns:

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

#locationObject



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

def location
  @response["location"]
end

#messageObject



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

def message
  @response.message
end

#redirect?Boolean

Returns:

  • (Boolean)


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

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

#see_other?Boolean

Returns:

  • (Boolean)


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

def see_other?
  code == 303
end

#success?Boolean

Returns:

  • (Boolean)


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

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

#success_no_content?Boolean

Returns:

  • (Boolean)


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

def success_no_content?
  code == 204
end

#success_ok?Boolean

Returns:

  • (Boolean)


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

def success_ok?
  code == 200
end