Class: Imperium::KVPUTResponse

Inherits:
Response
  • Object
show all
Defined in:
lib/imperium/kv_put_response.rb

Overview

Note:

This class doesn’t really make sense to be instantiated outside of Imperium::KV#put

KVPUTResponse is a wrapper for the raw HTTP::Message response from the API

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Response

#known_leader?, #last_contact, #not_found?, #translate_addresses?

Constructor Details

#initialize(message, options: {}) ⇒ KVPUTResponse

Returns a new instance of KVPUTResponse.



18
19
20
21
# File 'lib/imperium/kv_put_response.rb', line 18

def initialize(message, options: {})
  super message
  @options = options
end

Instance Attribute Details

#optionsHash<Symbol, Object>

coerced from an array to hash.

Returns:

  • (Hash<Symbol, Object>)

    The options for the get request after being



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/imperium/kv_put_response.rb', line 15

class KVPUTResponse < Response
  attr_accessor :options

  def initialize(message, options: {})
    super message
    @options = options
  end

  if RUBY_VERSION < "2.4"
    def success?
      return @success if defined? @success
      @success = (body.chomp == "true")
    end
  else
    def success?
      return @success if defined? @success
      @success = JSON.parse(body)
    rescue JSON::ParserError
      body.empty? ? @success = false : raise
    end
  end
end

#prefixString

returned values from the API into their various shapes.

Returns:

  • (String)

    The key prefix requested from the api, used to coerce the



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/imperium/kv_put_response.rb', line 15

class KVPUTResponse < Response
  attr_accessor :options

  def initialize(message, options: {})
    super message
    @options = options
  end

  if RUBY_VERSION < "2.4"
    def success?
      return @success if defined? @success
      @success = (body.chomp == "true")
    end
  else
    def success?
      return @success if defined? @success
      @success = JSON.parse(body)
    rescue JSON::ParserError
      body.empty? ? @success = false : raise
    end
  end
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/imperium/kv_put_response.rb', line 24

def success?
  return @success if defined? @success
  @success = (body.chomp == "true")
end