Class: Diplomat::Session
- Inherits:
-
RestClient
- Object
- RestClient
- Diplomat::Session
- Defined in:
- lib/diplomat/session.rb
Overview
Methods for interacting with the Consul session API endpoint
Instance Method Summary collapse
-
#create(value = nil, options = {}) ⇒ String
Create a new session.
-
#destroy(id, options = {}) ⇒ String
Destroy a session.
-
#info(id, options = {}) ⇒ OpenStruct
Session information.
-
#list(options = {}) ⇒ OpenStruct
List sessions.
-
#node(name, options = {}) ⇒ OpenStruct
Session information for a given node.
-
#renew(id, options = {}) ⇒ OpenStruct
Renew session.
Methods inherited from RestClient
access_method?, #concat_url, #configuration, #initialize, method_missing, respond_to?, respond_to_missing?, #use_named_parameter
Constructor Details
This class inherits a constructor from Diplomat::RestClient
Instance Method Details
#create(value = nil, options = {}) ⇒ String
Create a new session
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/diplomat/session.rb', line 12 def create(value = nil, = {}) # TODO: only certain keys are recognised in a session create request, # should raise an error on others. custom_params = [] custom_params << use_named_parameter('dc', [:dc]) if [:dc] data = value.is_a?(String) ? value : JSON.generate(value) unless value.nil? raw = send_put_request(@conn, ['/v1/session/create'], , data, custom_params) body = JSON.parse(raw.body) body['ID'] end |
#destroy(id, options = {}) ⇒ String
Destroy a session
27 28 29 30 31 32 |
# File 'lib/diplomat/session.rb', line 27 def destroy(id, = {}) custom_params = [] custom_params << use_named_parameter('dc', [:dc]) if [:dc] raw = send_put_request(@conn, ["/v1/session/destroy/#{id}"], , nil, custom_params) raw.body end |
#info(id, options = {}) ⇒ OpenStruct
Session information
59 60 61 62 63 64 |
# File 'lib/diplomat/session.rb', line 59 def info(id, = {}) custom_params = [] custom_params << use_named_parameter('dc', [:dc]) if [:dc] raw = send_get_request(@conn, ["/v1/session/info/#{id}"], , custom_params) JSON.parse(raw.body).map { |session| OpenStruct.new session } end |
#list(options = {}) ⇒ OpenStruct
List sessions
37 38 39 40 41 42 |
# File 'lib/diplomat/session.rb', line 37 def list( = {}) custom_params = [] custom_params << use_named_parameter('dc', [:dc]) if [:dc] raw = send_get_request(@conn, ['/v1/session/list'], , custom_params) JSON.parse(raw.body).map { |session| OpenStruct.new session } end |
#node(name, options = {}) ⇒ OpenStruct
Session information for a given node
70 71 72 73 74 75 |
# File 'lib/diplomat/session.rb', line 70 def node(name, = {}) custom_params = [] custom_params << use_named_parameter('dc', [:dc]) if [:dc] raw = send_get_request(@conn, ["/v1/session/node/#{name}"], , custom_params) JSON.parse(raw.body).map { |session| OpenStruct.new session } end |
#renew(id, options = {}) ⇒ OpenStruct
Renew session
48 49 50 51 52 53 |
# File 'lib/diplomat/session.rb', line 48 def renew(id, = {}) custom_params = [] custom_params << use_named_parameter('dc', [:dc]) if [:dc] raw = send_put_request(@conn, ["/v1/session/renew/#{id}"], , nil, custom_params) JSON.parse(raw.body).map { |session| OpenStruct.new session } end |