Class: ForemanPatch::Ticket::ChangeRequest

Inherits:
Object
  • Object
show all
Includes:
API
Defined in:
app/services/foreman_patch/ticket/change_request.rb

Defined Under Namespace

Classes: Jail

Instance Attribute Summary collapse

Attributes included from API

#request

Instance Method Summary collapse

Methods included from API

#delete, #get, #host, #post, #proxy, #put

Constructor Details

#initialize(window) ⇒ ChangeRequest

Returns a new instance of ChangeRequest.



8
9
10
11
12
# File 'app/services/foreman_patch/ticket/change_request.rb', line 8

def initialize(window)
  @window = window
  @ticket = {}
  reload
end

Instance Attribute Details

#affected_itemsObject (readonly)

Returns the value of attribute affected_items.



6
7
8
# File 'app/services/foreman_patch/ticket/change_request.rb', line 6

def affected_items
  @affected_items
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'app/services/foreman_patch/ticket/change_request.rb', line 6

def response
  @response
end

#windowObject (readonly)

Returns the value of attribute window.



6
7
8
# File 'app/services/foreman_patch/ticket/change_request.rb', line 6

def window
  @window
end

Instance Method Details

#[](key) ⇒ Object



69
70
71
# File 'app/services/foreman_patch/ticket/change_request.rb', line 69

def [](key)
  @ticket[key]
end

#idObject



51
52
53
# File 'app/services/foreman_patch/ticket/change_request.rb', line 51

def id
  @ticket.fetch(Setting[:ticket_id_field], window.ticket_id)
end

#keysObject



65
66
67
# File 'app/services/foreman_patch/ticket/change_request.rb', line 65

def keys
  @ticket.keys
end

#labelObject



55
56
57
# File 'app/services/foreman_patch/ticket/change_request.rb', line 55

def label
  @ticket.fetch(Setting[:ticket_label_field], window.name)
end


59
60
61
62
63
# File 'app/services/foreman_patch/ticket/change_request.rb', line 59

def link
  return "#" if id.blank?

  Setting[:ticket_api_host] + Setting[:ticket_web_ui_path].gsub(':id', id)
end

#payloadObject



47
48
49
# File 'app/services/foreman_patch/ticket/change_request.rb', line 47

def payload
  @payload ||= Payload.new(window)
end

#reloadObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/foreman_patch/ticket/change_request.rb', line 14

def reload
  return if window.ticket_id.blank?

  response = get(path)
  unless response.empty?
    @ticket = response['result']
  
    @affected_items = AffectedItems.new(self)
  end

  @ticket
end

#saveObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/services/foreman_patch/ticket/change_request.rb', line 27

def save
  response = {}
  if window.ticket_id.blank?
    response = post(path, payload)
  else
    response = put(path, payload)
  end

  unless response.empty?
    @ticket = response['result']

    window.update(ticket_id: id) if id != window.ticket_id

    @affected_items = AffectedItems.new(self)
    @affected_items.set(window.hosts)
  end

  @ticket
end

#to_hObject



73
74
75
# File 'app/services/foreman_patch/ticket/change_request.rb', line 73

def to_h
  @ticket
end