Class: Imperium::Response

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/imperium/response.rb

Overview

A Response is a decorator around the HTTP::Message object returned when a request is made.

It exposes, through a convenient API, headers common to all interactions with the Consul HTTP API

Direct Known Subclasses

KVGETResponse, KVPUTResponse

Instance Method Summary collapse

Instance Method Details

#known_leader?TrueClass, ...

Indicates if the contacted server has a known leader.

Returns:

  • (TrueClass)

    When the response indicates there is a known leader

  • (FalseClass)

    When the response indicates there is not a known leader

  • (NilClass)

    When the X-Consul-KnownLeader header is not present.



16
17
18
19
# File 'lib/imperium/response.rb', line 16

def known_leader?
  return unless headers.key?('X-Consul-KnownLeader')
  headers['X-Consul-KnownLeader'] == 'true'
end

#last_contactNilClass, Integer

The time in miliseconds since the contacted server has been in contact with the leader.

Returns:

  • (NilClass)

    When the X-Consul-LastContact header is not present.

  • (Integer)


26
27
28
29
# File 'lib/imperium/response.rb', line 26

def last_contact
  return unless headers.key?('X-Consul-LastContact')
  Integer(headers['X-Consul-LastContact'])
end

#not_found?Boolean

A convenience method for checking if the response had a 404 status code.

Returns:

  • (Boolean)


32
33
34
# File 'lib/imperium/response.rb', line 32

def not_found?
  status == 404
end

#translate_addresses?TrueClass, FalseClass

Indicate status of translate_wan_addrs setting on the server.

Returns:

  • (TrueClass)

    When X-Consul-Translate-Addresses is set

  • (FalseClass)

    When X-Consul-Translate-Addresses is unset



40
41
42
# File 'lib/imperium/response.rb', line 40

def translate_addresses?
  headers.key?('X-Consul-Translate-Addresses')
end