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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6993773f2f540cc308337c3a47845e08201dcd93
4
- data.tar.gz: 238df4c5465672f23f182c68d1e5a87ecc1b7928
3
+ metadata.gz: 0b5924c554f204f0f00a71f77090169cbeb928a8
4
+ data.tar.gz: a9e9948fede1773e4ba478e2d0fee89bb0c7f458
5
5
  SHA512:
6
- metadata.gz: a1f2fd67dcdc5feb723c3ad660c2a971f5587726744007a10f7990d0682a4fbb33a6ce7f1ff1780798ad3b8254364e185ab500c8b9c603003468d9fa33fad4e9
7
- data.tar.gz: 8619604f40bda32375f708a2b994c9a4f3590f480305f563ec376dc36b6ab84a90633511616234fb4789cfd6f0dccd386b46618e52e61a61542e0f0119db19f3
6
+ metadata.gz: 18294edda32703b3a028b8b13b643140523b994234c0ad4ae753d453ccdb48b78170c35033deb4747f8320361519cbd85e1191dd99f0d0c9ba33619450604ee6
7
+ data.tar.gz: e0a36c34a5669ff929fb6c6ca011bc8d40ccb535064be2dc16d311d5078aa60b070b251c08b6c27195c2a8a19b47b3ea0a47f27e64c1008612ab7b3fdc63f346
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ - "2.0.0"
5
+ - "2.1.0"
6
+ addons:
7
+ code_climate:
8
+ repo_token: 17481039ac7b5ef8779ab644b28a4d95dd7523c3c1fee560311eb4af63de006f
data/Gemfile.lock CHANGED
@@ -1,14 +1,17 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- diplomat (0.0.3)
5
- faraday (~> 0.9.0)
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
@@ -0,0 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task :default => :spec
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 = @conn.put "/v1/kv/#{@key}", @value
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
@@ -4,14 +4,16 @@ require 'json'
4
4
  module Diplomat
5
5
  class RestClient
6
6
 
7
- def initialize api_client=nil
8
- start_connection api_client
7
+ def initialize api_connection=nil
8
+ start_connection api_connection
9
9
  end
10
10
 
11
11
  private
12
12
 
13
- def start_connection api_client=nil
14
- @conn = api_client ||= Faraday.new(:url => Diplomat::url) do |faraday|
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Diplomat
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
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
@@ -1,6 +1,9 @@
1
1
  require "bundler/setup"
2
2
  Bundler.setup
3
3
 
4
+ require "codeclimate-test-reporter"
5
+ CodeClimate::TestReporter.start
6
+
4
7
  require 'diplomat'
5
8
  require 'fakes-rspec'
6
9
 
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.3
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