Class: UpGuard::Event

Inherits:
BaseObject show all
Defined in:
lib/upguard/Event.rb

Instance Attribute Summary collapse

Attributes inherited from BaseObject

#appliance_api_key, #appliance_url, #insecure, #sec_key

Instance Method Summary collapse

Methods inherited from BaseObject

#http_delete, #http_get, #http_post, #http_put, #make_headers

Constructor Details

#initialize(appliance_url, appliance_api_key, sec_key, insecure = false) ⇒ Event

Returns a new instance of Event.



8
9
10
11
12
13
14
15
# File 'lib/upguard/Event.rb', line 8

def initialize(appliance_url, appliance_api_key, sec_key, insecure = false)
  super(appliance_url, appliance_api_key, sec_key, insecure)
  self.id = nil
  self.type_id = nil
  self.environment_id = nil
  self.created_at = nil
  self.variables = EventVariables.new(appliance_url, appliance_api_key, sec_key, insecure)
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



6
7
8
# File 'lib/upguard/Event.rb', line 6

def created_at
  @created_at
end

#environment_idObject

Returns the value of attribute environment_id.



5
6
7
# File 'lib/upguard/Event.rb', line 5

def environment_id
  @environment_id
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/upguard/Event.rb', line 3

def id
  @id
end

#type_idObject

Returns the value of attribute type_id.



4
5
6
# File 'lib/upguard/Event.rb', line 4

def type_id
  @type_id
end

#variablesObject

Returns the value of attribute variables.



7
8
9
# File 'lib/upguard/Event.rb', line 7

def variables
  @variables
end

Instance Method Details

#environmentObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/upguard/Event.rb', line 38

def environment
  obj = http_get("/api/v2/environments/#{self.environment_id}.json")
  elem = Environment.new(self.appliance_url, self.appliance_api_key, self.sec_key, self.insecure)
    elem.id = obj["id"]
    elem.name = obj["name"]
    elem.organisation_id = obj["organisation_id"]
    elem.short_description = obj["short_description"]
    elem.node_rules = obj["node_rules"]
  return elem
end

#from_hash(h) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/upguard/Event.rb', line 17

def from_hash(h)
  self.id = h['id'] if h.include?('id')
  self.type_id = h['type_id'] if h.include?('type_id')
  self.environment_id = h['environment_id'] if h.include?('environment_id')
  self.created_at = h['created_at'] if h.include?('created_at')
  self.variables = h['variables'] if h.include?('variables')
end

#to_hashObject



24
25
26
27
28
29
30
31
32
# File 'lib/upguard/Event.rb', line 24

def to_hash
  h = {}
  h['id'] = self.id
  h['type_id'] = self.type_id
  h['environment_id'] = self.environment_id
  h['created_at'] = self.created_at
  h['variables'] = self.variables
  return h
end

#to_json(options = nil) ⇒ Object



33
34
35
36
# File 'lib/upguard/Event.rb', line 33

def to_json(options = nil)
  h = to_hash
  return h.to_json(options)
end