Skip to content

Commit

Permalink
Merge pull request #36 from opsgenie/ISSUE-16
Browse files Browse the repository at this point in the history
Issue 16: Add support for User V2 Api
  • Loading branch information
prakhar-mudaiya authored Jun 24, 2021
2 parents f337468 + 3588c43 commit 2851d37
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion lib/opsgenie.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')()
};
};
54 changes: 54 additions & 0 deletions lib/userV2/UserV2.js
Original file line number Diff line number Diff line change
@@ -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;
19 changes: 19 additions & 0 deletions samples/userV2/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use strict";

var opsgenie = require('../../');
require('../configure');

var create_user_json = {
"username": "[email protected]",
"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);
}
});
17 changes: 17 additions & 0 deletions samples/userV2/delete.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
16 changes: 16 additions & 0 deletions samples/userV2/get.js
Original file line number Diff line number Diff line change
@@ -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);
}
});
15 changes: 15 additions & 0 deletions samples/userV2/list.js
Original file line number Diff line number Diff line change
@@ -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);
}
});

0 comments on commit 2851d37

Please sign in to comment.