diplomat 0.2.1 → 0.2.2

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: 0b0b78c3defb59f640674929aa84736f259b301d
4
- data.tar.gz: 57dc6f99df3cb29304ac35a3c0154cdc3476bb25
3
+ metadata.gz: 16afe93a848c61faa819d4e4a30cf6ff7ba25047
4
+ data.tar.gz: 49389f757e990d27619c4c5863c00d3691e0fdad
5
5
  SHA512:
6
- metadata.gz: 5622c913dcec5213b2fb595ab1e9f9fc4d869502f9b95d7e1794980203511c000a16966e98d6a32abe7e77852f8308b4bf52031e8b19651518a832dc785dae3a
7
- data.tar.gz: 0f2e7d0534fa3fd79a497a01b126b3b1251c3fb4a949d447c949bb8968c5e626e8963df0a70c8afd0864491e463e370fa3dd51d72c3ac7728970994e95ae86f6
6
+ metadata.gz: 5bcd8d4eb6b4675bcc99d0bb2aba4240d3e710c316403529bca27f898fb6597721f654ef0dfeda98e4c1ded9f4ef1f2526eb1b52ce0968c554d943f2536e05cb
7
+ data.tar.gz: 9488168bcc6a5f9527a42f9f5d4e1806696a63e9cb8403aaa9ec5ea38e694e3e6e11b07e58d435def608836bf4fb839d03ca5663697884136b1f1494df1aa38f
data/README.md CHANGED
@@ -82,6 +82,21 @@ foo_service = Diplomat::Service.get('foo', :all)
82
82
  # => [#<OpenStruct Node="hotel", Address="1.2.3.4", ServiceID="hotel_foo", ServiceName="foo", ServiceTags=["foo"], ServicePort=5432>,#<OpenStruct Node="indigo", Address="1.2.3.5", ServiceID="indigo_foo", ServiceName="foo", ServiceTags=["foo"], ServicePort=5432>]
83
83
  ```
84
84
 
85
+ ### Custom configuration
86
+
87
+ You can create a custom configuration using the following syntax:
88
+
89
+ ```ruby
90
+ Diplomat.configure do |config|
91
+ # Set up a custom Consul URL
92
+ config.url = "localhost:8888"
93
+ # Set up a custom Faraday Middleware
94
+ config.middleware = MyCustomMiddleware
95
+ end
96
+ ```
97
+
98
+ This is traditionally kept inside the `config/initializers` directory if you're using rails. The middleware allows you to customise what happens when faraday sends and receives data. This can be useful if you want to instrument your use of diplomat, for example. You can read more about Faraday's custom middleware [here](http://stackoverflow.com/a/20973008).
99
+
85
100
  ### Todo
86
101
 
87
102
  - Updating docs with latest changes
@@ -7,9 +7,29 @@ module Diplomat
7
7
  # Get a service by it's key
8
8
  # @param key [String] the key
9
9
  # @param scope [Symbol] :first or :all results
10
+ # @param options [Hash] :wait string for wait time and :index for index of last query
11
+ # @param meta [Hash] output structure containing header information about the request (index)
10
12
  # @return [OpenStruct] all data associated with the service
11
- def get key, scope=:first
12
- ret = @conn.get "/v1/catalog/service/#{key}"
13
+ def get key, scope=:first, options=nil, meta=nil
14
+
15
+ qs = ""
16
+ sep = "?"
17
+ if options and options[:wait]
18
+ qs = "#{qs}#{sep}wait=#{options[:wait]}"
19
+ sep = "&"
20
+ end
21
+ if options and options[:index]
22
+ qs = "#{qs}#{sep}index=#{options[:index]}"
23
+ sep = "&"
24
+ end
25
+
26
+ ret = @conn.get "/v1/catalog/service/#{key}#{qs}"
27
+
28
+ if meta and ret.headers
29
+ meta[:index] = ret.headers["x-consul-index"]
30
+ meta[:knownleader] = ret.headers["x-consul-knownleader"]
31
+ meta[:lastcontact] = ret.headers["x-consul-lastcontact"]
32
+ end
13
33
 
14
34
  if scope == :all
15
35
  return JSON.parse(ret.body).map { |service| OpenStruct.new service }
@@ -1,3 +1,3 @@
1
1
  module Diplomat
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
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.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hamelink
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-20 00:00:00.000000000 Z
11
+ date: 2015-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -205,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
205
  version: '0'
206
206
  requirements: []
207
207
  rubyforge_project:
208
- rubygems_version: 2.2.2
208
+ rubygems_version: 2.4.5
209
209
  signing_key:
210
210
  specification_version: 4
211
211
  summary: Diplomat is a simple wrapper for Consul