diplomat 0.8.3 → 0.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbf402f2ee123f9bd5695a8faa1d1419cf504c7e
4
- data.tar.gz: 183ea346004b5658c96dfdd9c7a023bd4a39a685
3
+ metadata.gz: 4b30733457f28024a240e54b598c45a2ef02d258
4
+ data.tar.gz: 50e43ddee795ae3418d2b5e05e71f05e2f803a5e
5
5
  SHA512:
6
- metadata.gz: 7dfd0b88b712187fe1ad8f025b410e687c6b655c60ded8e448f43d0a586ce0ea030387355f3c45f9b569b15956bc595843ca63a90c2a9fb67d0352aad245b6cf
7
- data.tar.gz: e92caa5c03cf316657b98b3c431077e456326d574715f183ba91c084cfcc542dc81cc260b2532193e5c419b522b87facb3dc4cf1c3cd55dac92efe77a871a917
6
+ metadata.gz: d4e10a411987256743fc86bf7c95e812ecc2b1f785469bb07f441488426505b0d4c125bbc615c991fd76c6bec916369bca7fa1a07b4c6a8446cff6bcf0054479
7
+ data.tar.gz: ad2d634dda086ab217f7c67165ac8cce6afc4928fd95765334b77f94fcf78facdbea3e7f1e0b6ce2d4c6be05a7a1dec277f673e1a2a09447c2a0185f40b0dea8
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Diplomat
2
- [![Gem Version](https://badge.fury.io/rb/diplomat.svg)](http://badge.fury.io/rb/diplomat) [![Build Status](https://travis-ci.org/WeAreFarmGeek/diplomat.svg?branch=master)](https://travis-ci.org/WeAreFarmGeek/diplomat) [![Code Climate](https://codeclimate.com/github/johnhamelink/diplomat.png)](https://codeclimate.com/github/WeAreFarmGeek/diplomat) [![Dependency Status](https://gemnasium.com/WeAreFarmGeek/diplomat.svg)](https://gemnasium.com/WeAreFarmGeek/diplomat)
2
+ [![Gem Version](https://badge.fury.io/rb/diplomat.svg)](http://badge.fury.io/rb/diplomat) [![Build Status](https://travis-ci.org/WeAreFarmGeek/diplomat.svg?branch=master)](https://travis-ci.org/WeAreFarmGeek/diplomat) [![Code Climate](https://codeclimate.com/github/johnhamelink/diplomat.png)](https://codeclimate.com/github/WeAreFarmGeek/diplomat) [![Dependency Status](https://gemnasium.com/WeAreFarmGeek/diplomat.svg)](https://gemnasium.com/WeAreFarmGeek/diplomat) [![Inline docs](http://inch-ci.org/github/wearefarmgeek/diplomat.svg?branch=master)](http://inch-ci.org/github/wearefarmgeek/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)
@@ -4,6 +4,9 @@ require 'faraday'
4
4
  module Diplomat
5
5
  class Check < Diplomat::RestClient
6
6
 
7
+ @access_methods = [ :checks, :register_script, :register_ttl,
8
+ :deregister, :pass, :warn, :fail ]
9
+
7
10
  # Get registered checks
8
11
  # @return [OpenStruct] all data associated with the service
9
12
  def checks
@@ -88,40 +91,5 @@ module Diplomat
88
91
  return ret.status == 200
89
92
  end
90
93
 
91
- # @note This is sugar, see (#checks)
92
- def self.checks
93
- Diplomat::Check.new.checks
94
- end
95
-
96
- # @note This is sugar, see (#register_script)
97
- def self.register_script *args
98
- Diplomat::Check.new.register_script *args
99
- end
100
-
101
- # @note This is sugar, see (#register_ttl)
102
- def self.register_ttl *args
103
- Diplomat::Check.new.register_ttl *args
104
- end
105
-
106
- # @note This is sugar, see (#deregister)
107
- def self.deregister *args
108
- Diplomat::Check.new.deregister *args
109
- end
110
-
111
- # @note This is sugar, see (#pass)
112
- def self.pass *args
113
- Diplomat::Check.new.pass *args
114
- end
115
-
116
- # @note This is sugar, see (#warn)
117
- def self.warn *args
118
- Diplomat::Check.new.warn *args
119
- end
120
-
121
- # @note This is sugar, see (#fail)
122
- def self.fail *args
123
- Diplomat::Check.new.fail *args
124
- end
125
-
126
94
  end
127
95
  end
@@ -2,6 +2,7 @@ require 'faraday'
2
2
 
3
3
  module Diplomat
4
4
  class Event < Diplomat::RestClient
5
+ @access_methods = [ :fire, :get_all, :get ]
5
6
 
6
7
  # Send an event
7
8
  # @param name [String] the event name
@@ -11,7 +12,7 @@ module Diplomat
11
12
  # @param tag [String] the target tag name, must only be used with service
12
13
  # @return [nil]
13
14
  def fire name, value=nil, service=nil, node=nil, tag=nil
14
- raw = @conn.put do |req|
15
+ @conn.put do |req|
15
16
  url = [ "/v1/event/fire/#{name}" ]
16
17
  url += use_named_parameter("service", service)
17
18
  url += use_named_parameter("node", node)
@@ -140,21 +141,6 @@ module Diplomat
140
141
  end
141
142
 
142
143
 
143
- # @note This is sugar, see (#fire)
144
- def self.fire *args
145
- Diplomat::Event.new.fire *args
146
- end
147
-
148
- # @note This is sugar, see (#get_all)
149
- def self.get_all *args
150
- Diplomat::Event.new.get_all *args
151
- end
152
-
153
- # @note This is sugar, see (#get)
154
- def self.get *args
155
- Diplomat::Event.new.get *args
156
- end
157
-
158
144
  private
159
145
 
160
146
  def wait_for_next_event url
@@ -3,6 +3,8 @@ require 'faraday'
3
3
 
4
4
  module Diplomat
5
5
  class Health < Diplomat::RestClient
6
+ @access_methods = [ :node, :checks, :service, :state,
7
+ :unknown, :passing, :warning, :critical ]
6
8
 
7
9
  # Get node health
8
10
  # @param n [String] the node
@@ -55,47 +57,5 @@ module Diplomat
55
57
  def critical
56
58
  state("critical")
57
59
  end
58
-
59
-
60
- # @note This is sugar, see (#node)
61
- def self.node *args
62
- Diplomat::Health.new.node *args
63
- end
64
-
65
- # @note This is sugar, see (#checks)
66
- def self.checks *args
67
- Diplomat::Health.new.checks *args
68
- end
69
-
70
- # @note This is sugar, see (#service)
71
- def self.service *args
72
- Diplomat::Health.new.service *args
73
- end
74
-
75
- # @note This is sugar, see (#state)
76
- def self.state *args
77
- Diplomat::Health.new.state *args
78
- end
79
-
80
- # @note This is sugar, see (#unknown)
81
- def self.unknown
82
- Diplomat::Health.new.unknown
83
- end
84
-
85
- # @note This is sugar, see (#passing)
86
- def self.passing
87
- Diplomat::Health.new.passing
88
- end
89
-
90
- # @note This is sugar, see (#warning)
91
- def self.warning
92
- Diplomat::Health.new.warning
93
- end
94
-
95
- # @note This is sugar, see (#critical)
96
- def self.critical
97
- Diplomat::Health.new.critical
98
- end
99
-
100
60
  end
101
61
  end
@@ -3,7 +3,7 @@ require 'faraday'
3
3
 
4
4
  module Diplomat
5
5
  class Kv < Diplomat::RestClient
6
-
6
+ @access_methods = [ :get, :put, :delete ]
7
7
  attr_reader :key, :value, :raw
8
8
 
9
9
  # Get a value by its key, potentially blocking for the first or next value
@@ -102,21 +102,6 @@ module Diplomat
102
102
  @raw = @conn.delete concat_url url
103
103
  end
104
104
 
105
- # @note This is sugar, see (#get)
106
- def self.get *args
107
- Diplomat::Kv.new.get *args
108
- end
109
-
110
- # @note This is sugar, see (#put)
111
- def self.put *args
112
- Diplomat::Kv.new.put *args
113
- end
114
-
115
- # @note This is sugar, see (#delete)
116
- def self.delete *args
117
- Diplomat::Kv.new.delete *args
118
- end
119
-
120
105
  private
121
106
 
122
107
  def check_acl_token
@@ -3,6 +3,8 @@ require 'faraday'
3
3
  module Diplomat
4
4
  class Lock < Diplomat::RestClient
5
5
 
6
+ @access_methods = [ :acquire, :wait_to_acquire, :release ]
7
+
6
8
  # Acquire a lock
7
9
  # @param key [String] the key
8
10
  # @param session [String] the session, generated from Diplomat::Session.create
@@ -42,20 +44,5 @@ module Diplomat
42
44
  end
43
45
  return raw.body
44
46
  end
45
-
46
- # @note This is sugar, see (#acquire)
47
- def self.acquire *args
48
- Diplomat::Lock.new.acquire *args
49
- end
50
-
51
- # @note This is sugar, see (#wait_to_acquire)
52
- def self.wait_to_acquire *args
53
- Diplomat::Lock.new.wait_to_acquire *args
54
- end
55
-
56
- # @note This is sugar, see (#release)
57
- def self.release *args
58
- Diplomat::Lock.new.release *args
59
- end
60
47
  end
61
48
  end
@@ -3,6 +3,7 @@ require 'faraday'
3
3
 
4
4
  module Diplomat
5
5
  class Members < Diplomat::RestClient
6
+ @access_methods = [ :get ]
6
7
 
7
8
  # Get all members
8
9
  # @return [OpenStruct] all data associated with the service
@@ -10,11 +11,5 @@ module Diplomat
10
11
  ret = @conn.get "/v1/agent/members"
11
12
  return JSON.parse(ret.body)
12
13
  end
13
-
14
- # @note This is sugar, see (#get)
15
- def self.get
16
- Diplomat::Members.new.get
17
- end
18
-
19
14
  end
20
15
  end
@@ -4,6 +4,8 @@ require 'json'
4
4
  module Diplomat
5
5
  class RestClient
6
6
 
7
+ @access_methods = []
8
+
7
9
  def initialize api_connection=nil
8
10
  start_connection api_connection
9
11
  end
@@ -20,6 +22,18 @@ module Diplomat
20
22
  end
21
23
  end
22
24
 
25
+ class << self
26
+
27
+ def access_method? methId
28
+ @access_methods.include? methId
29
+ end
30
+
31
+ def method_missing(methId, *args)
32
+ access_method?(methId) ? new.send(methId, *args) : super
33
+ end
34
+
35
+ end
36
+
23
37
  private
24
38
 
25
39
  # Build the API Client
@@ -3,6 +3,8 @@ require 'faraday'
3
3
 
4
4
  module Diplomat
5
5
  class Service < Diplomat::RestClient
6
+
7
+ @access_methods = [ :get, :register, :deregister ]
6
8
 
7
9
  # Get a service by it's key
8
10
  # @param key [String] the key
@@ -48,21 +50,5 @@ module Diplomat
48
50
  deregister = @conn.get "/v1/agent/service/deregister/#{service_name}"
49
51
  return deregister.status == 200
50
52
  end
51
-
52
- # @note This is sugar, see (#get)
53
- def self.get *args
54
- Diplomat::Service.new(*args).get
55
- end
56
-
57
- # @note This is sugar, see (#register)
58
- def self.register definition
59
- Diplomat::Service.new.register definition
60
- end
61
-
62
- # @note This is sugar, see (#deregister)
63
- def self.deregister service_name
64
- Diplomat::Service.new.deregister service_name
65
- end
66
-
67
53
  end
68
54
  end
@@ -3,6 +3,8 @@ require 'faraday'
3
3
  module Diplomat
4
4
  class Session < Diplomat::RestClient
5
5
 
6
+ @access_methods = [ :create, :destroy ]
7
+
6
8
  # Create a new session
7
9
  # @param value [Object] hash or json representation of the session arguments
8
10
  # @return [String] The sesssion id
@@ -26,15 +28,5 @@ module Diplomat
26
28
  end
27
29
  return raw.body
28
30
  end
29
-
30
- # @note This is sugar, see (#create)
31
- def self.create *args
32
- Diplomat::Session.new.create *args
33
- end
34
-
35
- # @note This is sugar, see (#destroy)
36
- def self.destroy *args
37
- Diplomat::Session.new.destroy *args
38
- end
39
31
  end
40
32
  end
@@ -1,3 +1,3 @@
1
1
  module Diplomat
2
- VERSION = "0.8.3"
2
+ VERSION = "0.8.4"
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.8.3
4
+ version: 0.8.4
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-05-07 00:00:00.000000000 Z
11
+ date: 2015-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler