Class: Nexpose::GlobalBlackout

Inherits:
APIObject show all
Includes:
JsonSerializer
Defined in:
lib/nexpose/global_blackout.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from JsonSerializer

#deserialize, #serialize, #to_hash

Methods inherited from APIObject

#object_from_hash

Constructor Details

#initialize(blackout) ⇒ GlobalBlackout

Returns a new instance of GlobalBlackout.



10
11
12
# File 'lib/nexpose/global_blackout.rb', line 10

def initialize(blackout)
  @blackout = Array(blackout)
end

Instance Attribute Details

#blackoutObject

Array

Blackout starting dates, times and duration for blackout periods.



8
9
10
# File 'lib/nexpose/global_blackout.rb', line 8

def blackout
  @blackout
end

Class Method Details

.json_initializer(data) ⇒ Object



29
30
31
# File 'lib/nexpose/global_blackout.rb', line 29

def self.json_initializer(data)
  new(blackout: data)
end

.load(nsc) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/nexpose/global_blackout.rb', line 33

def self.load(nsc)
  uri               = '/api/2.1/silo_blackout/'
  resp              = AJAX.get(nsc, uri, AJAX::CONTENT_TYPE::JSON)
  hash              = JSON.parse(resp, symbolize_names: true)
  blackout          = self.json_initializer(hash).deserialize(hash)
  blackout.blackout = (hash[:blackouts] || []).map { |bout| Nexpose::Blackout.from_hash(bout) }
  blackout
end

Instance Method Details

#save(nsc) ⇒ Object



14
15
16
17
# File 'lib/nexpose/global_blackout.rb', line 14

def save(nsc)
  params = to_json
  AJAX.post(nsc, '/api/2.1/silo_blackout/', params, AJAX::CONTENT_TYPE::JSON)
end

#to_hObject



19
20
21
22
23
# File 'lib/nexpose/global_blackout.rb', line 19

def to_h
  {
    blackouts: (@blackout || []).map(&:to_h)
  }
end

#to_jsonObject



25
26
27
# File 'lib/nexpose/global_blackout.rb', line 25

def to_json
  JSON.generate(to_h)
end