Class: StackAgent::Instance
- Inherits:
-
Object
- Object
- StackAgent::Instance
- Defined in:
- lib/stack-agent/instance.rb
Instance Attribute Summary collapse
-
#instance_token ⇒ Object
Returns the value of attribute instance_token.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(instance_token = nil) ⇒ Instance
constructor
A new instance of Instance.
- #register ⇒ Object
- #registered? ⇒ Boolean
- #unregister ⇒ Object
Constructor Details
#initialize(instance_token = nil) ⇒ Instance
Returns a new instance of Instance.
8 9 10 |
# File 'lib/stack-agent/instance.rb', line 8 def initialize(instance_token = nil) self.instance_token = instance_token end |
Instance Attribute Details
#instance_token ⇒ Object
Returns the value of attribute instance_token.
6 7 8 |
# File 'lib/stack-agent/instance.rb', line 6 def instance_token @instance_token end |
Class Method Details
.stacks ⇒ Object
51 52 53 54 55 56 |
# File 'lib/stack-agent/instance.rb', line 51 def self.stacks config = StackAgent.configuration url = "#{config.api_host}/v1/apps/#{config.app_token}/stacks" response = RestClient::Resource.new(url, verify_ssl: OpenSSL::SSL::VERIFY_NONE).get JSON.parse(response.body) end |
Instance Method Details
#register ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/stack-agent/instance.rb', line 12 def register config = StackAgent.configuration return false unless config.app_token && config.name && config.uri url = "#{config.api_host}/v1/apps/#{config.app_token}/stacks" data = { group: config.group, name: config.name, uri: config.uri } begin response = RestClient::Resource.new(url, verify_ssl: OpenSSL::SSL::VERIFY_NONE).post(data) return self.instance_token = JSON.parse(response.body)['id'] rescue RestClient::BadRequest => ex false end end |
#registered? ⇒ Boolean
47 48 49 |
# File 'lib/stack-agent/instance.rb', line 47 def registered? instance_token != nil end |
#unregister ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/stack-agent/instance.rb', line 33 def unregister return false unless registered? config = StackAgent.configuration url = "#{config.api_host}/v1/apps/#{config.app_token}/stacks/#{instance_token}" begin RestClient::Resource.new(url, verify_ssl: OpenSSL::SSL::VERIFY_NONE).delete true rescue RestClient::BadRequest => ex false end end |