Class: Azure::Core::Http::HttpResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/azure/storage/core/http/http_response.rb

Overview

A small proxy to clean up the API of Net::HTTPResponse.

Defined Under Namespace

Classes: MockResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response, uri = '') ⇒ HttpResponse

Public: Initialize a new response.

http_response - A Net::HTTPResponse.


26
27
28
29
# File 'lib/azure/storage/core/http/http_response.rb', line 26

def initialize(http_response, uri='')
  @http_response = http_response
  @uri = uri
end

Instance Attribute Details

#uriObject

Returns the value of attribute uri


31
32
33
# File 'lib/azure/storage/core/http/http_response.rb', line 31

def uri
  @uri
end

Instance Method Details

#bodyObject

Public: Get the response body.

Returns a String.


36
37
38
# File 'lib/azure/storage/core/http/http_response.rb', line 36

def body
  @http_response.body
end

#exceptionObject Also known as: error

Public: Get an error that wraps this HTTP response, as long as this response was unsuccessful. This method will return nil if the response was successful.

Returns an Azure::Core::Http::HTTPError.


67
68
69
# File 'lib/azure/storage/core/http/http_response.rb', line 67

def exception
  HTTPError.new(self) unless success?
end

#headersObject

Public: Get all the response headers as a Hash.

Returns a Hash.


58
59
60
# File 'lib/azure/storage/core/http/http_response.rb', line 58

def headers
  @http_response.headers
end

#status_codeObject

Public: Get the response status code.

Returns a Fixnum.


43
44
45
# File 'lib/azure/storage/core/http/http_response.rb', line 43

def status_code
  @http_response.status
end

#success?Boolean

Public: Check if this response was successful. A request is considered successful if the response is in the 200 - 399 range.

Returns nil|false.

Returns:

  • (Boolean)

51
52
53
# File 'lib/azure/storage/core/http/http_response.rb', line 51

def success?
  @http_response.success?
end