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



78
79
80
# File 'lib/vra/http.rb', line 78

def initialize(response)
  @response = response
end

Instance Method Details

#bodyObject



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

def body
  @response.body
end

#codeObject



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

def code
  @response.code.to_i
end

#final?Boolean

Returns:

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

#locationObject



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

def location
  @response['location']
end

#messageObject



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

def message
  @response.message
end

#redirect?Boolean

Returns:

  • (Boolean)


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

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

#see_other?Boolean

Returns:

  • (Boolean)


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

def see_other?
  code == 303
end

#success?Boolean

Returns:

  • (Boolean)


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

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

#success_no_content?Boolean

Returns:

  • (Boolean)


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

def success_no_content?
  code == 204
end

#success_ok?Boolean

Returns:

  • (Boolean)


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

def success_ok?
  code == 200
end