diplomat 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -0
- data/Gemfile.lock +17 -7
- data/README.md +5 -1
- data/Rakefile +5 -0
- data/diplomat.gemspec +1 -0
- data/lib/diplomat.rb +1 -4
- data/lib/diplomat/kv.rb +17 -1
- data/lib/diplomat/rest_client.rb +6 -4
- data/lib/diplomat/service.rb +4 -0
- data/lib/diplomat/version.rb +1 -1
- data/spec/kv_spec.rb +12 -11
- data/spec/spec_helper.rb +3 -0
- metadata +17 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b5924c554f204f0f00a71f77090169cbeb928a8
|
4
|
+
data.tar.gz: a9e9948fede1773e4ba478e2d0fee89bb0c7f458
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18294edda32703b3a028b8b13b643140523b994234c0ad4ae753d453ccdb48b78170c35033deb4747f8320361519cbd85e1191dd99f0d0c9ba33619450604ee6
|
7
|
+
data.tar.gz: e0a36c34a5669ff929fb6c6ca011bc8d40ccb535064be2dc16d311d5078aa60b070b251c08b6c27195c2a8a19b47b3ea0a47f27e64c1008612ab7b3fdc63f346
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
diplomat (0.
|
5
|
-
faraday (~> 0.9
|
4
|
+
diplomat (0.1.3)
|
5
|
+
faraday (~> 0.9)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
codeclimate-test-reporter (0.3.0)
|
11
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
10
12
|
coderay (1.1.0)
|
11
13
|
diff-lcs (1.2.5)
|
14
|
+
docile (1.1.3)
|
12
15
|
fakes (1.1.4)
|
13
16
|
fakes-rspec (1.0.5)
|
14
17
|
fakes
|
@@ -16,6 +19,7 @@ GEM
|
|
16
19
|
multipart-post (>= 1.2, < 3)
|
17
20
|
json (1.8.1)
|
18
21
|
method_source (0.8.2)
|
22
|
+
multi_json (1.9.2)
|
19
23
|
multipart-post (2.0.0)
|
20
24
|
pry (0.9.12.6)
|
21
25
|
coderay (~> 1.0)
|
@@ -30,6 +34,11 @@ GEM
|
|
30
34
|
rspec-expectations (2.14.5)
|
31
35
|
diff-lcs (>= 1.1.3, < 2.0)
|
32
36
|
rspec-mocks (2.14.6)
|
37
|
+
simplecov (0.8.2)
|
38
|
+
docile (~> 1.1.0)
|
39
|
+
multi_json
|
40
|
+
simplecov-html (~> 0.8.0)
|
41
|
+
simplecov-html (0.8.0)
|
33
42
|
slop (3.4.7)
|
34
43
|
|
35
44
|
PLATFORMS
|
@@ -37,9 +46,10 @@ PLATFORMS
|
|
37
46
|
|
38
47
|
DEPENDENCIES
|
39
48
|
bundler (~> 1.3)
|
49
|
+
codeclimate-test-reporter
|
40
50
|
diplomat!
|
41
|
-
fakes-rspec
|
42
|
-
json
|
43
|
-
pry
|
44
|
-
rake
|
45
|
-
rspec
|
51
|
+
fakes-rspec (~> 1.0)
|
52
|
+
json (~> 1.8)
|
53
|
+
pry (~> 0.9)
|
54
|
+
rake (~> 10.3)
|
55
|
+
rspec (~> 2.14)
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Diplomat
|
2
|
-
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/diplomat.svg)](http://badge.fury.io/rb/diplomat) [![Build Status](https://travis-ci.org/johnhamelink/diplomat.svg?branch=master)](https://travis-ci.org/johnhamelink/diplomat) [![Code Climate](https://codeclimate.com/github/johnhamelink/diplomat.png)](https://codeclimate.com/github/johnhamelink/diplomat)
|
3
3
|
### A HTTP Ruby API for [Consul](http://www.consul.io/)
|
4
4
|
|
5
5
|
![Diplomacy Boad Game](http://i.imgur.com/Nkuy4b7.jpg)
|
@@ -41,6 +41,10 @@ production:
|
|
41
41
|
|
42
42
|
## Usage
|
43
43
|
|
44
|
+
[The most up to date place to read about the API is here.](http://rubydoc.info/github/johnhamelink/diplomat)
|
45
|
+
|
46
|
+
Here's a few examples of how diplomat works:
|
47
|
+
|
44
48
|
### Key Values
|
45
49
|
|
46
50
|
#### Getting
|
data/Rakefile
ADDED
data/diplomat.gemspec
CHANGED
@@ -24,5 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "rspec", "~> 2.14"
|
25
25
|
spec.add_development_dependency "fakes-rspec", "~> 1.0"
|
26
26
|
spec.add_development_dependency "json", "~> 1.8"
|
27
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
27
28
|
spec.add_dependency "faraday", "~> 0.9"
|
28
29
|
end
|
data/lib/diplomat.rb
CHANGED
@@ -7,10 +7,7 @@ module Diplomat
|
|
7
7
|
attr_accessor :url
|
8
8
|
|
9
9
|
# Internal: Requires internal Faraday libraries.
|
10
|
-
#
|
11
|
-
# *libs - One or more relative String names to Faraday classes.
|
12
|
-
#
|
13
|
-
# Returns nothing.
|
10
|
+
# @param *libs One or more relative String names to Faraday classes.
|
14
11
|
def require_libs(*libs)
|
15
12
|
libs.each do |lib|
|
16
13
|
require "#{lib_path}/#{lib}"
|
data/lib/diplomat/kv.rb
CHANGED
@@ -6,6 +6,9 @@ module Diplomat
|
|
6
6
|
|
7
7
|
attr_reader :key, :value, :raw
|
8
8
|
|
9
|
+
# Get a value by it's key
|
10
|
+
# @param key [String] the key
|
11
|
+
# @return [String] The base64-decoded value associated with the key
|
9
12
|
def get key
|
10
13
|
@key = key
|
11
14
|
@raw = @conn.get "/v1/kv/#{@key}"
|
@@ -14,28 +17,41 @@ module Diplomat
|
|
14
17
|
return @value
|
15
18
|
end
|
16
19
|
|
20
|
+
# Get a value by it's key
|
21
|
+
# @param key [String] the key
|
22
|
+
# @param value [String] the value
|
23
|
+
# @return [String] The base64-decoded value associated with the key
|
17
24
|
def put key, value
|
18
|
-
@raw
|
25
|
+
@raw = @conn.put do |req|
|
26
|
+
req.url "/v1/kv/#{@key}"
|
27
|
+
req.body = @value
|
28
|
+
end
|
19
29
|
@raw = JSON.parse(@raw.body).first
|
20
30
|
@key = @raw["Key"]
|
21
31
|
@value = Base64.decode64(@raw["Value"])
|
22
32
|
return @value
|
23
33
|
end
|
24
34
|
|
35
|
+
# Delete a value by it's key
|
36
|
+
# @param key [String] the key
|
37
|
+
# @return [nil]
|
25
38
|
def delete key
|
26
39
|
@raw = @conn.delete "/v1/kv/#{@key}"
|
27
40
|
@key = nil
|
28
41
|
@value = nil
|
29
42
|
end
|
30
43
|
|
44
|
+
# @note This is sugar, see (#get)
|
31
45
|
def self.get *args
|
32
46
|
Diplomat::Kv.new.get *args
|
33
47
|
end
|
34
48
|
|
49
|
+
# @note This is sugar, see (#put)
|
35
50
|
def self.put *args
|
36
51
|
Diplomat::Kv.new.put *args
|
37
52
|
end
|
38
53
|
|
54
|
+
# @note This is sugar, see (#delete)
|
39
55
|
def self.delete *args
|
40
56
|
Diplomat::Kv.new.delete *args
|
41
57
|
end
|
data/lib/diplomat/rest_client.rb
CHANGED
@@ -4,14 +4,16 @@ require 'json'
|
|
4
4
|
module Diplomat
|
5
5
|
class RestClient
|
6
6
|
|
7
|
-
def initialize
|
8
|
-
start_connection
|
7
|
+
def initialize api_connection=nil
|
8
|
+
start_connection api_connection
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
# Build the API Client
|
14
|
+
# @param api_connection [Faraday::Connection,nil] supply mock API Connection
|
15
|
+
def start_connection api_connection=nil
|
16
|
+
@conn = api_connection ||= Faraday.new(:url => Diplomat::url) do |faraday|
|
15
17
|
faraday.request :url_encoded
|
16
18
|
faraday.response :logger
|
17
19
|
faraday.adapter Faraday.default_adapter
|
data/lib/diplomat/service.rb
CHANGED
@@ -4,11 +4,15 @@ require 'faraday'
|
|
4
4
|
module Diplomat
|
5
5
|
class Service < Diplomat::RestClient
|
6
6
|
|
7
|
+
# Get a service by it's key
|
8
|
+
# @param key [String] the key
|
9
|
+
# @return [OpenStruct] all data associated with the service
|
7
10
|
def get key
|
8
11
|
ret = @conn.get "/v1/catalog/service/#{key}"
|
9
12
|
return OpenStruct.new JSON.parse(ret.body).first
|
10
13
|
end
|
11
14
|
|
15
|
+
# @note This is sugar, see (#get)
|
12
16
|
def self.get *args
|
13
17
|
Diplomat::Service.new.get *args
|
14
18
|
end
|
data/lib/diplomat/version.rb
CHANGED
data/spec/kv_spec.rb
CHANGED
@@ -12,13 +12,14 @@ describe Diplomat::Kv do
|
|
12
12
|
let(:key_params) { "toast" }
|
13
13
|
|
14
14
|
it "GET" do
|
15
|
-
json = JSON.generate({
|
15
|
+
json = JSON.generate([{
|
16
16
|
"Key" => key,
|
17
17
|
"Value" => Base64.encode64(key_params),
|
18
18
|
"Flags" => 0
|
19
|
-
})
|
19
|
+
}])
|
20
|
+
|
21
|
+
faraday.stub(:get).and_return(OpenStruct.new({ body: json }))
|
20
22
|
|
21
|
-
faraday.stub(:get).and_return(json)
|
22
23
|
kv = Diplomat::Kv.new(faraday)
|
23
24
|
|
24
25
|
expect(kv.get("key")).to eq("toast")
|
@@ -26,28 +27,28 @@ describe Diplomat::Kv do
|
|
26
27
|
|
27
28
|
it "PUT" do
|
28
29
|
|
29
|
-
json = JSON.generate({
|
30
|
+
json = JSON.generate([{
|
30
31
|
"Key" => key,
|
31
32
|
"Value" => Base64.encode64(key_params),
|
32
33
|
"Flags" => 0
|
33
|
-
})
|
34
|
+
}])
|
34
35
|
|
35
|
-
faraday.stub(:get).and_return(json)
|
36
|
-
faraday.stub(:put).and_return(json)
|
36
|
+
faraday.stub(:get).and_return(OpenStruct.new({ body: json }))
|
37
|
+
faraday.stub(:put).and_return(OpenStruct.new({ body: json }))
|
37
38
|
kv = Diplomat::Kv.new(faraday)
|
38
39
|
|
39
40
|
expect(kv.put(key, key_params)).to eq(key_params)
|
40
41
|
end
|
41
42
|
|
42
43
|
it "namespaces" do
|
43
|
-
json = JSON.generate({
|
44
|
+
json = JSON.generate([{
|
44
45
|
"Key" => key,
|
45
46
|
"Value" => Base64.encode64(key_params),
|
46
47
|
"Flags" => 0
|
47
|
-
})
|
48
|
+
}])
|
48
49
|
|
49
|
-
faraday.stub(:get).and_return(json)
|
50
|
-
faraday.stub(:put).and_return(json)
|
50
|
+
faraday.stub(:get).and_return(OpenStruct.new({ body: json }))
|
51
|
+
faraday.stub(:put).and_return(OpenStruct.new({ body: json }))
|
51
52
|
kv = Diplomat::Kv.new(faraday)
|
52
53
|
|
53
54
|
expect(kv.put("toast/#{key}", key_params)).to eq(key_params)
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diplomat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hamelink
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '1.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: codeclimate-test-reporter
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: faraday
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -117,10 +131,12 @@ extra_rdoc_files: []
|
|
117
131
|
files:
|
118
132
|
- ".gitignore"
|
119
133
|
- ".rspec"
|
134
|
+
- ".travis.yml"
|
120
135
|
- Gemfile
|
121
136
|
- Gemfile.lock
|
122
137
|
- LICENSE
|
123
138
|
- README.md
|
139
|
+
- Rakefile
|
124
140
|
- diplomat.gemspec
|
125
141
|
- lib/diplomat.rb
|
126
142
|
- lib/diplomat/kv.rb
|