Class: CloudhouseGuardian::ScheduledJob

Inherits:
BaseObject
  • Object
show all
Defined in:
lib/cloudhouse_guardian/ScheduledJob.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) ⇒ ScheduledJob

Returns a new instance of ScheduledJob.



9
10
11
12
13
14
15
16
17
# File 'lib/cloudhouse_guardian/ScheduledJob.rb', line 9

def initialize(appliance_url, appliance_api_key, sec_key, insecure = false)
  super(appliance_url, appliance_api_key, sec_key, insecure)
  self.data = nil
  self.id = nil
  self.source_id = nil
  self.source_name = nil
  self.source_type = nil
  self.status = nil
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/cloudhouse_guardian/ScheduledJob.rb', line 3

def data
  @data
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/cloudhouse_guardian/ScheduledJob.rb', line 4

def id
  @id
end

#source_idObject

Returns the value of attribute source_id.



5
6
7
# File 'lib/cloudhouse_guardian/ScheduledJob.rb', line 5

def source_id
  @source_id
end

#source_nameObject

Returns the value of attribute source_name.



6
7
8
# File 'lib/cloudhouse_guardian/ScheduledJob.rb', line 6

def source_name
  @source_name
end

#source_typeObject

Returns the value of attribute source_type.



7
8
9
# File 'lib/cloudhouse_guardian/ScheduledJob.rb', line 7

def source_type
  @source_type
end

#statusObject

Returns the value of attribute status.



8
9
10
# File 'lib/cloudhouse_guardian/ScheduledJob.rb', line 8

def status
  @status
end

Instance Method Details

#cancel_jobsObject



73
74
75
76
77
# File 'lib/cloudhouse_guardian/ScheduledJob.rb', line 73

def cancel_jobs
  url = "/api/v2/scheduled_jobs/#{self.id}/cancel_jobs.json"
  obj = http_post(url, nil)
  return obj
end

#createObject



57
58
59
60
61
# File 'lib/cloudhouse_guardian/ScheduledJob.rb', line 57

def create
  h = to_hash
  out = http_post("/api/v2/scheduled_jobs.json", h)
  from_hash(out)
end

#deleteObject



69
70
71
# File 'lib/cloudhouse_guardian/ScheduledJob.rb', line 69

def delete
  http_delete("/api/v2/scheduled_jobs/#{self.id}.json")
end

#from_hash(h) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/cloudhouse_guardian/ScheduledJob.rb', line 19

def from_hash(h)
  self.data = h['data'] if h.include?('data')
  self.id = h['id'] if h.include?('id')
  self.source_id = h['source_id'] if h.include?('source_id')
  self.source_name = h['source_name'] if h.include?('source_name')
  self.source_type = h['source_type'] if h.include?('source_type')
  self.status = h['status'] if h.include?('status')
end

#loadObject



42
43
44
45
# File 'lib/cloudhouse_guardian/ScheduledJob.rb', line 42

def load
  obj = http_get("/api/v2/scheduled_jobs/#{self.id}.json")
  from_hash(obj)
end

#saveObject



48
49
50
51
52
53
54
# File 'lib/cloudhouse_guardian/ScheduledJob.rb', line 48

def save
  if self.id.to_i == 0
    return create
  else
    return update
  end
end

#to_hashObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/cloudhouse_guardian/ScheduledJob.rb', line 27

def to_hash
  h = {}
  h['data'] = self.data
  h['id'] = self.id
  h['source_id'] = self.source_id
  h['source_name'] = self.source_name
  h['source_type'] = self.source_type
  h['status'] = self.status
  return h
end

#to_json(options = nil) ⇒ Object



37
38
39
40
# File 'lib/cloudhouse_guardian/ScheduledJob.rb', line 37

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

#updateObject



64
65
66
67
# File 'lib/cloudhouse_guardian/ScheduledJob.rb', line 64

def update
  h = to_hash
  http_put("/api/v2/scheduled_jobs/#{self.id}.json", h)
end