class Diplomat::Kv

Attributes

key[R]
raw[R]
value[R]

Public Class Methods

delete(*args) click to toggle source

@note This is sugar, see (delete)

# File lib/diplomat/kv.rb, line 56
def self.delete *args
  Diplomat::Kv.new.delete *args
end
get(*args) click to toggle source

@note This is sugar, see (get)

# File lib/diplomat/kv.rb, line 46
def self.get *args
  Diplomat::Kv.new.get *args
end
put(*args) click to toggle source

@note This is sugar, see (put)

# File lib/diplomat/kv.rb, line 51
def self.put *args
  Diplomat::Kv.new.put *args
end

Public Instance Methods

delete(key) click to toggle source

Delete a value by it's key @param key [String] the key @return [nil]

# File lib/diplomat/kv.rb, line 38
def delete key
  @key = key
  @raw = @conn.delete "/v1/kv/#{@key}"
  return_key
  return_value
end
get(key) click to toggle source

Get a value by it's key @param key [String] the key @return [String] The base64-decoded value associated with the key

# File lib/diplomat/kv.rb, line 12
def get key
  @key = key
  @raw = @conn.get "/v1/kv/#{@key}"
  parse_body
  return_value
end
put(key, value) click to toggle source

Get a value by it's key @param key [String] the key @param value [String] the value @return [String] The base64-decoded value associated with the key

# File lib/diplomat/kv.rb, line 23
def put key, value
  @raw = @conn.put do |req|
    req.url "/v1/kv/#{key}"
    req.body = value
  end
  if @raw.body == "true\n"
    @key   = key
    @value = value
  end
  return @value
end

Private Instance Methods

parse_body() click to toggle source

Parse the body, apply it to the raw attribute

# File lib/diplomat/kv.rb, line 63
def parse_body
  @raw = JSON.parse(@raw.body).first
end
return_key() click to toggle source

Get the key from the raw output

# File lib/diplomat/kv.rb, line 68
def return_key
  @key = @raw["Key"]
end
return_value() click to toggle source

Get the value from the raw output

# File lib/diplomat/kv.rb, line 73
def return_value
  @value = @raw["Value"]
  @value = Base64.decode64(@value) unless @value.nil?
end