From 791e1d580c6c377efcbdf3587d0a8491a66e05ce Mon Sep 17 00:00:00 2001 From: Dan Carlyon Date: Fri, 27 Mar 2020 09:50:11 +0000 Subject: [PATCH 1/2] Add support for V2 user API --- lib/opsgenie.js | 3 ++- lib/userV2/UserV2.js | 54 ++++++++++++++++++++++++++++++++++++++++ samples/userV2/create.js | 19 ++++++++++++++ samples/userV2/delete.js | 17 +++++++++++++ samples/userV2/get.js | 16 ++++++++++++ samples/userV2/list.js | 15 +++++++++++ 6 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 lib/userV2/UserV2.js create mode 100755 samples/userV2/create.js create mode 100755 samples/userV2/delete.js create mode 100644 samples/userV2/get.js create mode 100644 samples/userV2/list.js diff --git a/lib/opsgenie.js b/lib/opsgenie.js index ec160ff..d96e417 100644 --- a/lib/opsgenie.js +++ b/lib/opsgenie.js @@ -22,6 +22,7 @@ module.exports = function () { group: require('./resources/Group')(), team: require('./resources/Team')(), incident: require('./incident/Incident')(), - heartbeat: require('./heartbeat/Heartbeat')() + heartbeat: require('./heartbeat/Heartbeat')(), + userV2: require('./userV2/UserV2')() }; }; diff --git a/lib/userV2/UserV2.js b/lib/userV2/UserV2.js new file mode 100644 index 0000000..889688f --- /dev/null +++ b/lib/userV2/UserV2.js @@ -0,0 +1,54 @@ +"use strict"; + +var api = require('./../restApi'); + +/** + * User API v2. For more information: https://www.opsgenie.com/docs/rest-api/user-api + * To see mandatory and optional parameter checkout the alert api web page + * + * Also, you can check samples under /samples/userV2 for examples. + * + * @return {Object} order functions + */ + +function userV2() { + var baseURL = '/v2/users/'; + + return { + /** + * Gets a specific user from opsgenie based on id or email address + */ + get: function (identifier, config, cb) { + var path = api.getPath(baseURL, identifier, null); + api.get(path, config, cb); + }, + + list: function (params, config, cb) { + var path = api.getPathWithListParams(baseURL, params); + api.get(path, config, cb) + }, + + /* + * This request is to create Users in Opsgenie. + * Please check new alert api documentation for available fields here: + * https://www.opsgenie.com/docs/rest-api/user-api#section-create-user + * + * Also, you can check /samples/userV2/create.js for a complete example. + * + * */ + create: function (data, config, cb) { + api.post(baseURL, data, config, cb) + }, + + /* + * This request is to delete a User in Opsgenie. + * identifier parameter should be specified + * */ + delete: function (identifier, config, cb) { + var path = api.getPath(baseURL, identifier, null); + api.delete(path, config, cb) + }, + }; +} + +module.exports = userV2; diff --git a/samples/userV2/create.js b/samples/userV2/create.js new file mode 100755 index 0000000..fe393de --- /dev/null +++ b/samples/userV2/create.js @@ -0,0 +1,19 @@ +"use strict"; + +var opsgenie = require('../../'); +require('../configure'); + +var create_user_json = { + "username": "test@space48.com", + "fullName": "Test McTestFace", + "role": { id: 'test' } +}; + +opsgenie.userV2.create(create_user_json, function (error, user) { + if (error) { + console.error(error); + } else { + console.log("Create User Response"); + console.log(user); + } +}); diff --git a/samples/userV2/delete.js b/samples/userV2/delete.js new file mode 100755 index 0000000..0a6c04e --- /dev/null +++ b/samples/userV2/delete.js @@ -0,0 +1,17 @@ +"use strict"; + +var opsgenie = require('../../'); +require('../configure'); + +var delete_user_json = { + identifier: "4f594840-6c25-4cfa-b0b5-b2450bff7f50" +}; + +opsgenie.userV2.delete(delete_user_json, function (error, user) { + if (error) { + console.error(error); + } else { + console.log("Delete User Response"); + console.log(user); + } +}); diff --git a/samples/userV2/get.js b/samples/userV2/get.js new file mode 100644 index 0000000..83ae10a --- /dev/null +++ b/samples/userV2/get.js @@ -0,0 +1,16 @@ +"use strict"; + +var opsgenie = require('../../'); +require('../configure'); + +var get_user_json = { + identifier: "eb387227-4d7c-4ceb-b970-c4ba728af5d0" +}; + +opsgenie.userV2.get(get_user_json, function (error, user) { + if (error) { + console.error(error); + } else { + console.log(user); + } +}); diff --git a/samples/userV2/list.js b/samples/userV2/list.js new file mode 100644 index 0000000..24922bc --- /dev/null +++ b/samples/userV2/list.js @@ -0,0 +1,15 @@ +"use strict"; + +var opsgenie = require('../../'); +require('../configure'); + + +var list_params = {}; + +opsgenie.userV2.list(list_params, function (error, users) { + if (error) { + console.error(error); + } else { + console.log(users); + } +}); From 3588c435e0f1cc5da089006b67f6b31144b1357b Mon Sep 17 00:00:00 2001 From: Dan Carlyon Date: Fri, 27 Mar 2020 10:56:07 +0000 Subject: [PATCH 2/2] Update Readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eb389c1..307c6ee 100755 --- a/README.md +++ b/README.md @@ -13,10 +13,11 @@ OpsGenie Node.js SDK covers: - Alert API v2 - User API +- User API v2 - Group API - Team API - Heartbeat API -- Incident API +- Incident API - Escalation API (TODO: will be available soon) - Schedule API (TODO: will be available soon) - Schedule Override API (TODO: will be available soon)