class Google::Cloud::Env::ComputeMetadata::Response

Basic HTTP response object, returned by {ComputeMetadata#lookup_response}.

This object duck-types the ‘status`, `body`, and `headers` fields of `Faraday::Response`. It also includes the CLOCK_MONOTONIC time when the data was retrieved.

Attributes

body[R]

The HTTP response body @return [String]

headers[R]

The HTTP response headers @return [Hash{String=>String}]

retrieval_monotonic_time[R]

The CLOCK_MONOTONIC time at which this response was retrieved. @return [Numeric]

status[R]

The HTTP status code @return [Integer]

Public Class Methods

new(status, body, headers) click to toggle source

Create a response object.

@param status [Integer] The HTTP status, normally 200 @param body [String] The HTTP body as a string @param headers [Hash{String=>String}] The HTTP response headers.

Normally, the `Metadata-Flavor` header must be set to the value
`Google`.
# File lib/google/cloud/env/compute_metadata.rb, line 105
def initialize status, body, headers
  @status = status
  @body = body
  @headers = headers
  @retrieval_monotonic_time = Process.clock_gettime Process::CLOCK_MONOTONIC
end

Public Instance Methods

google_flavor?() click to toggle source

Returns true if the metadata-flavor is correct for Google Cloud @return [boolean]

# File lib/google/cloud/env/compute_metadata.rb, line 139
def google_flavor?
  headers["Metadata-Flavor"] == "Google"
end