-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from opsgenie/ISSUE-16
Issue 16: Add support for User V2 Api
- Loading branch information
Showing
7 changed files
with
125 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |