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 = nil) ⇒ String
Create a new session.
-
#destroy(id, options = nil) ⇒ String
Destroy a session.
-
#info(id, options = nil) ⇒ OpenStruct
Session information.
-
#list(options = nil) ⇒ OpenStruct
List sessions.
-
#node(name, options = nil) ⇒ OpenStruct
Session information for a given node.
-
#renew(id, options = nil) ⇒ OpenStruct
Renew session.
Methods inherited from RestClient
access_method?, #concat_url, #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 = nil) ⇒ String
Create a new session
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/diplomat/session.rb', line 11 def create(value = nil, = nil) # TODO: only certain keys are recognised in a session create request, # should raise an error on others. raw = @conn.put do |req| url = ['/v1/session/create'] url += use_named_parameter('dc', [:dc]) if && [:dc] req.url concat_url url req.body = (value.is_a?(String) ? value : JSON.generate(value)) unless value.nil? end body = JSON.parse(raw.body) body['ID'] end |
#destroy(id, options = nil) ⇒ String
Destroy a session
30 31 32 33 34 35 36 37 38 |
# File 'lib/diplomat/session.rb', line 30 def destroy(id, = nil) raw = @conn.put do |req| url = ["/v1/session/destroy/#{id}"] url += use_named_parameter('dc', [:dc]) if && [:dc] req.url concat_url url end raw.body end |
#info(id, options = nil) ⇒ OpenStruct
Session information
74 75 76 77 78 79 80 81 82 |
# File 'lib/diplomat/session.rb', line 74 def info(id, = nil) raw = @conn.get do |req| url = ["/v1/session/info/#{id}"] url += use_named_parameter('dc', [:dc]) if && [:dc] req.url concat_url url end JSON.parse(raw.body).map { |session| OpenStruct.new session } end |
#list(options = nil) ⇒ OpenStruct
List sessions
44 45 46 47 48 49 50 51 52 |
# File 'lib/diplomat/session.rb', line 44 def list( = nil) raw = @conn.get do |req| url = ['/v1/session/list'] url += use_named_parameter('dc', [:dc]) if && [:dc] req.url concat_url url end JSON.parse(raw.body).map { |session| OpenStruct.new session } end |
#node(name, options = nil) ⇒ OpenStruct
Session information for a given node
89 90 91 92 93 94 95 96 97 |
# File 'lib/diplomat/session.rb', line 89 def node(name, = nil) raw = @conn.get do |req| url = ["/v1/session/node/#{name}"] url += use_named_parameter('dc', [:dc]) if && [:dc] req.url concat_url url end JSON.parse(raw.body).map { |session| OpenStruct.new session } end |
#renew(id, options = nil) ⇒ OpenStruct
Renew session
59 60 61 62 63 64 65 66 67 |
# File 'lib/diplomat/session.rb', line 59 def renew(id, = nil) raw = @conn.put do |req| url = ["/v1/session/renew/#{id}"] url += use_named_parameter('dc', [:dc]) if && [:dc] req.url concat_url url end JSON.parse(raw.body).map { |session| OpenStruct.new session } end |