diplomat 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2244d84cc7a0fe952223ad6001d8f473be47a024
4
- data.tar.gz: b86af2a9b85baadf3d45382a55ad25a12c1e70d5
3
+ metadata.gz: 2c7efb343599818bf0533dcb8695aa0283ab59aa
4
+ data.tar.gz: 000d4c18b30c36c3739ad0d1deda567eebe00cb2
5
5
  SHA512:
6
- metadata.gz: e176ec9e8b1e1eebb570c8c0698d38eadab706654ceaba1d8d0f981cd8c046aad6f70cbb9772a8562e2ece337ff02c11417829425af2b142d16d4445d6147ec1
7
- data.tar.gz: 3faa78e2307bb3c0bb00e4722adfc8eb3bedd1e2afd5f5f98d0ae4efd6f919ec03f3e5d59087e17ade656b762c06b273416f2a44fc096343802754545a263f14
6
+ metadata.gz: f6aaea91e904df541b9f5a275e2450072411a488522c8748705a826f8d0725ac15c1c2d6d16cb9c037e963853801eb25ff4bf70363bf56dbf9d97069c0ac76b4
7
+ data.tar.gz: f2e2c8d09390bb45c9fbd4f3779516edefb8921962e3a7f01944c7fbd1037be738bde86d0bdef3d4262c79c52b7a46ad80ccca25ebe42d5ab66a2d8183a0b3f5
data/lib/diplomat/kv.rb CHANGED
@@ -6,52 +6,48 @@ module Diplomat
6
6
 
7
7
  attr_reader :key, :value, :raw
8
8
 
9
- # Get a value by it's key
9
+ # Get a value by its key
10
10
  # @param key [String] the key
11
11
  # @return [String] The base64-decoded value associated with the key
12
12
  def get key
13
13
  @key = key
14
- args = ["/v1/kv/#{@key}"]
15
- args += check_acl_token unless check_acl_token.nil?
16
- @raw = @conn.get args.join
14
+ url = ["/v1/kv/#{@key}"]
15
+ url += check_acl_token unless check_acl_token.nil?
16
+ @raw = @conn.get concat_url url
17
17
  parse_body
18
18
  return_value
19
19
  end
20
20
 
21
- # Get a value by it's key
21
+ # Associate a value with a key
22
22
  # @param key [String] the key
23
23
  # @param value [String] the value
24
24
  # @param options [Hash] the query params
25
25
  # @option options [Integer] :cas The modify index
26
- # @return [String] The base64-decoded value associated with the key
26
+ # @return [Bool] Success or failure of the write (can fail in c-a-s mode)
27
27
  def put key, value, options=nil
28
- qs = ""
29
28
  @options = options
30
29
  @raw = @conn.put do |req|
31
- args = ["/v1/kv/#{key}"]
32
- args += check_acl_token unless check_acl_token.nil?
33
- args += use_cas(@options) unless use_cas(@options).nil?
34
- req.url args.join
30
+ url = ["/v1/kv/#{key}"]
31
+ url += check_acl_token unless check_acl_token.nil?
32
+ url += use_cas(@options) unless use_cas(@options).nil?
33
+ req.url concat_url url
35
34
  req.body = value
36
35
  end
37
- if @raw.body == "true\n"
36
+ if @raw.body == "true"
38
37
  @key = key
39
38
  @value = value
40
- else
41
- @raw.body
42
39
  end
40
+ @raw.body == "true"
43
41
  end
44
42
 
45
- # Delete a value by it's key
43
+ # Delete a value by its key
46
44
  # @param key [String] the key
47
- # @return [nil]
45
+ # @return [OpenStruct]
48
46
  def delete key
49
47
  @key = key
50
- args = ["/v1/kv/#{@key}"]
51
- args += check_acl_token unless check_acl_token.nil?
52
- @raw = @conn.delete args.join
53
- # return_key
54
- # return_value
48
+ url = ["/v1/kv/#{@key}"]
49
+ url += check_acl_token unless check_acl_token.nil?
50
+ @raw = @conn.delete concat_url url
55
51
  end
56
52
 
57
53
  # @note This is sugar, see (#get)
@@ -88,11 +84,11 @@ module Diplomat
88
84
  end
89
85
 
90
86
  def check_acl_token
91
- ["?token=#{Diplomat.configuration.acl_token}"] if Diplomat.configuration.acl_token
87
+ ["token=#{Diplomat.configuration.acl_token}"] if Diplomat.configuration.acl_token
92
88
  end
93
89
 
94
90
  def use_cas(options)
95
- ["&cas=#{options[:cas]}"] if options && options[:cas]
91
+ ["cas=#{options[:cas]}"] if options && options[:cas]
96
92
  end
97
93
  end
98
94
  end
@@ -8,6 +8,14 @@ module Diplomat
8
8
  start_connection api_connection
9
9
  end
10
10
 
11
+ def concat_url parts
12
+ if parts.length > 1 then
13
+ parts.first << '?' << parts.drop(1).join('&')
14
+ else
15
+ parts.first
16
+ end
17
+ end
18
+
11
19
  private
12
20
 
13
21
  # Build the API Client
@@ -1,3 +1,3 @@
1
1
  module Diplomat
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diplomat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hamelink
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-24 00:00:00.000000000 Z
11
+ date: 2015-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler