Class: Google::Cloud::Env::ComputeMetadata::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/env/compute_metadata.rb

Overview

Basic HTTP response object, returned by #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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, body, headers) ⇒ Response

Create a response object.

Parameters:

  • status (Integer)

    The HTTP status, normally 200

  • body (String)

    The HTTP body as a string

  • headers (Hash{String=>String})

    The HTTP response headers. Normally, the Metadata-Flavor header must be set to the value Google.



105
106
107
108
109
110
# 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

Instance Attribute Details

#bodyString (readonly)

The HTTP response body

Returns:

  • (String)


122
123
124
# File 'lib/google/cloud/env/compute_metadata.rb', line 122

def body
  @body
end

#headersHash{String=>String} (readonly)

The HTTP response headers

Returns:

  • (Hash{String=>String})


128
129
130
# File 'lib/google/cloud/env/compute_metadata.rb', line 128

def headers
  @headers
end

#retrieval_monotonic_timeNumeric (readonly)

The CLOCK_MONOTONIC time at which this response was retrieved.

Returns:

  • (Numeric)


133
134
135
# File 'lib/google/cloud/env/compute_metadata.rb', line 133

def retrieval_monotonic_time
  @retrieval_monotonic_time
end

#statusInteger (readonly)

The HTTP status code

Returns:

  • (Integer)


116
117
118
# File 'lib/google/cloud/env/compute_metadata.rb', line 116

def status
  @status
end

Instance Method Details

#google_flavor?boolean

Returns true if the metadata-flavor is correct for Google Cloud

Returns:

  • (boolean)


139
140
141
# File 'lib/google/cloud/env/compute_metadata.rb', line 139

def google_flavor?
  headers["Metadata-Flavor"] == "Google"
end