Module: Legion::Extensions::ServiceNow::Incident::Runners::Incident

Includes:
Helpers::Lex, Helpers::Client
Included in:
Client
Defined in:
lib/legion/extensions/service_now/incident/runners/incident.rb

Instance Method Summary collapse

Methods included from Helpers::Client

#connection, #fetch_oauth2_token, #handle_response

Instance Method Details

#create_incident(short_description:, urgency: nil, impact: nil, category: nil, subcategory: nil, assignment_group: nil, assigned_to: nil, description: nil, caller_id: nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/legion/extensions/service_now/incident/runners/incident.rb', line 27

def create_incident(short_description:, urgency: nil, impact: nil, category: nil,
                    subcategory: nil, assignment_group: nil, assigned_to: nil,
                    description: nil, caller_id: nil, **)
  body = { short_description: short_description }
  body[:urgency]          = urgency if urgency
  body[:impact]           = impact if impact
  body[:category]         = category if category
  body[:subcategory]      = subcategory if subcategory
  body[:assignment_group] = assignment_group if assignment_group
  body[:assigned_to]      = assigned_to if assigned_to
  body[:description]      = description if description
  body[:caller_id]        = caller_id if caller_id
  resp = connection(**).post('/api/now/table/incident', body)
  { incident: resp.body['result'] }
end

#delete_incident(sys_id:) ⇒ Object



65
66
67
68
# File 'lib/legion/extensions/service_now/incident/runners/incident.rb', line 65

def delete_incident(sys_id:, **)
  resp = connection(**).delete("/api/now/table/incident/#{sys_id}")
  { deleted: resp.status == 204, sys_id: sys_id }
end

#get_incident(sys_id:, sysparm_fields: nil) ⇒ Object



20
21
22
23
24
25
# File 'lib/legion/extensions/service_now/incident/runners/incident.rb', line 20

def get_incident(sys_id:, sysparm_fields: nil, **)
  params = {}
  params[:sysparm_fields] = sysparm_fields if sysparm_fields
  resp = connection(**).get("/api/now/table/incident/#{sys_id}", params)
  { incident: resp.body['result'] }
end

#list_incidents(sysparm_limit: 100, sysparm_offset: 0, sysparm_query: nil, sysparm_fields: nil) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/legion/extensions/service_now/incident/runners/incident.rb', line 11

def list_incidents(sysparm_limit: 100, sysparm_offset: 0, sysparm_query: nil,
                   sysparm_fields: nil, **)
  params = { sysparm_limit: sysparm_limit, sysparm_offset: sysparm_offset }
  params[:sysparm_query]  = sysparm_query if sysparm_query
  params[:sysparm_fields] = sysparm_fields if sysparm_fields
  resp = connection(**).get('/api/now/table/incident', params)
  { incidents: resp.body['result'] }
end

#resolve_incident(sys_id:, close_code:, close_notes:) ⇒ Object



59
60
61
62
63
# File 'lib/legion/extensions/service_now/incident/runners/incident.rb', line 59

def resolve_incident(sys_id:, close_code:, close_notes:, **)
  body = { state: '6', close_code: close_code, close_notes: close_notes }
  resp = connection(**).patch("/api/now/table/incident/#{sys_id}", body)
  { incident: resp.body['result'] }
end

#update_incident(sys_id:, short_description: nil, urgency: nil, impact: nil, state: nil, close_code: nil, close_notes: nil, assignment_group: nil, assigned_to: nil) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/legion/extensions/service_now/incident/runners/incident.rb', line 43

def update_incident(sys_id:, short_description: nil, urgency: nil, impact: nil,
                    state: nil, close_code: nil, close_notes: nil,
                    assignment_group: nil, assigned_to: nil, **)
  body = {}
  body[:short_description] = short_description if short_description
  body[:urgency]           = urgency if urgency
  body[:impact]            = impact if impact
  body[:state]             = state if state
  body[:close_code]        = close_code if close_code
  body[:close_notes]       = close_notes if close_notes
  body[:assignment_group]  = assignment_group if assignment_group
  body[:assigned_to]       = assigned_to if assigned_to
  resp = connection(**).patch("/api/now/table/incident/#{sys_id}", body)
  { incident: resp.body['result'] }
end