Module: Legion::Extensions::ServiceNow::Notification::Runners::Notification

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

Instance Method Summary collapse

Methods included from Helpers::Client

#connection, #fetch_oauth2_token, #handle_response

Instance Method Details

#create_notification(name:, event_name:, recipient: nil, subject: nil, message_html: nil, active: true) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/legion/extensions/service_now/notification/runners/notification.rb', line 23

def create_notification(name:, event_name:, recipient: nil, subject: nil,
                        message_html: nil, active: true, **)
  body = { name: name, event_name: event_name, active: active }
  body[:recipient]     = recipient if recipient
  body[:subject]       = subject if subject
  body[:message_html]  = message_html if message_html
  resp = connection(**).post('/api/now/table/sysevent_email_action', body)
  { notification: resp.body['result'] }
end

#delete_notification(sys_id:) ⇒ Object



44
45
46
47
# File 'lib/legion/extensions/service_now/notification/runners/notification.rb', line 44

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

#get_notification(sys_id:) ⇒ Object



18
19
20
21
# File 'lib/legion/extensions/service_now/notification/runners/notification.rb', line 18

def get_notification(sys_id:, **)
  resp = connection(**).get("/api/now/table/sysevent_email_action/#{sys_id}")
  { notification: resp.body['result'] }
end

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



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

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

#update_notification(sys_id:, name: nil, active: nil, subject: nil, message_html: nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/legion/extensions/service_now/notification/runners/notification.rb', line 33

def update_notification(sys_id:, name: nil, active: nil, subject: nil,
                        message_html: nil, **)
  body = {}
  body[:name]         = name if name
  body[:active]       = active unless active.nil?
  body[:subject]      = subject if subject
  body[:message_html] = message_html if message_html
  resp = connection(**).patch("/api/now/table/sysevent_email_action/#{sys_id}", body)
  { notification: resp.body['result'] }
end