Class: Floe::ServiceNow::Incident
- Defined in:
- lib/floe/servicenow/incident.rb
Class Method Summary collapse
- .close_incident(params, secrets, context) ⇒ Object
-
.create_incident(params, secrets, _context) ⇒ Object
Create a new incident in ServiceNow.
-
.get_incident(params, secrets, _context) ⇒ Object
Get an incident by sys_id.
-
.query_incidents(params, secrets, _context) ⇒ Object
Query incidents with optional filters.
- .resolve_incident(params, secrets, context) ⇒ Object
-
.update_incident(params, secrets, _context) ⇒ Object
Update an existing incident.
Class Method Details
.close_incident(params, secrets, context) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/floe/servicenow/incident.rb', line 71 def self.close_incident(params, secrets, context) params['attributes'] ||= {} params['attributes']['state'] = '7' # state enum 7 is closed params['attributes']['resolution_code'] = params.delete('close_code') if params['close_code'] params['attributes']['resolution_notes'] = params.delete('close_notes') if params['close_notes'] update_incident(params, secrets, context) end |
.create_incident(params, secrets, _context) ⇒ Object
Create a new incident in ServiceNow
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/floe/servicenow/incident.rb', line 9 def self.create_incident(params, secrets, _context) error = verify_credentials(secrets) error ||= verify_create_params(params) return ServiceNow.error!({}, :cause => error) if error http_params = build_http_params( "POST", "/api/now/table/incident", params, secrets, :body => params.except("instance_id") ) http_request(http_params, {}, {}) end |
.get_incident(params, secrets, _context) ⇒ Object
Get an incident by sys_id
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/floe/servicenow/incident.rb', line 26 def self.get_incident(params, secrets, _context) error = verify_credentials(secrets) error ||= verify_get_params(params) return ServiceNow.error!({}, :cause => error) if error sys_id = params["sys_id"] http_params = build_http_params( "GET", "/api/now/table/incident/#{sys_id}", params, secrets ) http_request(http_params, {}, {}) end |
.query_incidents(params, secrets, _context) ⇒ Object
Query incidents with optional filters
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/floe/servicenow/incident.rb', line 81 def self.query_incidents(params, secrets, _context) error = verify_credentials(secrets) error ||= verify_instance_id(params) return ServiceNow.error!({}, :cause => error) if error query_params = {} query_params["sysparm_query"] = params["query"] if params["query"] query_params["sysparm_limit"] = params["limit"] if params["limit"] query_params["sysparm_offset"] = params["offset"] if params["offset"] query_params["sysparm_fields"] = params["fields"] if params["fields"] http_params = build_http_params( "GET", "/api/now/table/incident", params, secrets, :query => query_params ) http_request(http_params, {}, {}) end |
.resolve_incident(params, secrets, context) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/floe/servicenow/incident.rb', line 62 def self.resolve_incident(params, secrets, context) params['attributes'] ||= {} params['attributes']['state'] = '6' # state enum 6 is resolved params['attributes']['resolution_code'] = params.delete('close_code') if params['close_code'] params['attributes']['resolution_notes'] = params.delete('close_notes') if params['close_notes'] update_incident(params, secrets, context) end |
.update_incident(params, secrets, _context) ⇒ Object
Update an existing incident
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/floe/servicenow/incident.rb', line 44 def self.update_incident(params, secrets, _context) error = verify_credentials(secrets) error ||= verify_update_params(params) return ServiceNow.error!({}, :cause => error) if error sys_id = params["sys_id"] http_params = build_http_params( "PATCH", "/api/now/table/incident/#{sys_id}", params, secrets, :body => params.except("sys_id", "instance_id") ) http_request(http_params, {}, {}) end |