Class: Kitchen::Driver::Azure::Http::Response

Inherits:
Struct
  • Object
show all
Defined in:
lib/kitchen/driver/azure/http.rb

Overview

One HTTP response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyString (readonly)

Returns:

  • (String)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/kitchen/driver/azure/http.rb', line 51

Response = Struct.new(:status, :body) do
  # @return [Boolean] whether the status is in the 2xx range.
  def success?
    status.between?(200, 299)
  end

  # The response body parsed as JSON.
  #
  # @return [Hash, Array, nil] nil when the body is empty or not JSON.
  def json
    return nil if body.nil? || body.empty?

    JSON.parse(body)
  rescue JSON::ParserError
    nil
  end
end

#statusInteger (readonly)

Returns:

  • (Integer)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/kitchen/driver/azure/http.rb', line 51

Response = Struct.new(:status, :body) do
  # @return [Boolean] whether the status is in the 2xx range.
  def success?
    status.between?(200, 299)
  end

  # The response body parsed as JSON.
  #
  # @return [Hash, Array, nil] nil when the body is empty or not JSON.
  def json
    return nil if body.nil? || body.empty?

    JSON.parse(body)
  rescue JSON::ParserError
    nil
  end
end

Instance Method Details

#jsonHash, ...

The response body parsed as JSON.

Returns:

  • (Hash, Array, nil)

    nil when the body is empty or not JSON.



60
61
62
63
64
65
66
# File 'lib/kitchen/driver/azure/http.rb', line 60

def json
  return nil if body.nil? || body.empty?

  JSON.parse(body)
rescue JSON::ParserError
  nil
end

#success?Boolean

Returns whether the status is in the 2xx range.

Returns:

  • (Boolean)

    whether the status is in the 2xx range.



53
54
55
# File 'lib/kitchen/driver/azure/http.rb', line 53

def success?
  status.between?(200, 299)
end