Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/5_forwardingApi' into 0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
DanCarlyon committed Feb 11, 2021
2 parents 13b8fcf + cf90d23 commit 30ddc71
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 0 deletions.
84 changes: 84 additions & 0 deletions lib/forwardingV2/ForwardingV2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"use strict";

const api = require('./../restApi');

/**
* https://docs.opsgenie.com/docs/forwarding-rule-api
*
* @returns {{get: get, create: create, list: list, delete: delete, updateRule: updateRule}}
*/
function forwardingV2() {
let baseURL = '/v2/forwarding-rules/';

return {
/**
* https://docs.opsgenie.com/docs/forwarding-rule-api
* Also, you can check /samples/forwardingV2/create.js for a complete example.
*
* @param data
* @param config
* @param cb
*/
create: function (data, config, cb) {
api.post(baseURL, data, config, cb)
},

/**
* Get forwarding rule by identifier
* https://docs.opsgenie.com/docs/forwarding-rule-api#section--get-forwarding-rule-
* One of id, tinyId or alias parameters should be specified with get alert request as identifier.
* Alias option can only be used for open alerts
* example identifier objects:
* {identifier : "123", identifierType : "tiny"}
* {identifier : "123-23-123", identifierType : "id"}
* {identifier : "alertAlias", identifierType : "alias"}
*
* @param identifier
* @param config
* @param cb
*/
get: function (identifier, config, cb) {
let path = api.getPath(baseURL, identifier, null);
api.get(path, config, cb)
},

/**
* Delete a forwarding rule
* https://docs.opsgenie.com/docs/forwarding-rule-api#section--delete-forwarding-rule-
*
* @param identifier
* @param config
* @param cb
*/
delete: function (identifier, config, cb) {
let path = api.getPath(baseURL, identifier, null);
api.delete(path, config, cb)
},

/**
* https://docs.opsgenie.com/docs/forwarding-rule-api#section--list-forwarding-rules-
*
* @param params
* @param config
* @param cb
*/
list: function (params, config, cb) {
let path = api.getPathWithListParams(baseURL, params);
api.get(path, config, cb)
},

/**
* https://docs.opsgenie.com/docs/forwarding-rule-api#section--delete-forwarding-rule-
* @param identifier
* @param data
* @param config
* @param cb
*/
updateRule: function (identifier, data, config, cb) {
let path = api.getPath(baseURL, identifier, null);
api.put(path, data, config, cb);
},
};
}

module.exports = forwardingV2;
1 change: 1 addition & 0 deletions lib/opsgenie.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ module.exports = function () {
incident: require('./resources/Indicent')(),
escalationV2: require('./escalationV2/EscalationV2')(),
scheduleV2: require('./scheduleV2/ScheduleV2')(),
forwardingV2: require('./forwardingV2/ForwardingV2')(),
};
};
4 changes: 4 additions & 0 deletions lib/restApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ exports.post = function executePostRequest(path, data, http_options, cb) {
execute('POST', path, data, http_options, cb);
};

exports.put = function executePutRequest(path, data, http_options, cb) {
execute('PUT', path, data, http_options, cb);
};

exports.delete = function executeDeleteRequest(path, http_options, cb) {
execute('DELETE', path, null, http_options, cb);
};
Expand Down
30 changes: 30 additions & 0 deletions samples/forwardingV2/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use strict";

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

let todaysDate = new Date();
todaysDate.setDate(todaysDate.getDate() + 1);
let startDate = todaysDate.toISOString();
todaysDate.setDate(todaysDate.getDate() + 5);
let endDate = todaysDate.toISOString();

let create_rule_json = {
fromUser: {
id: 'c1754eea-7f80-4126-8a64-a55c42439947'
},
toUser: {
id: '830e4738-fc50-4bd0-b789-00fc0db76418'
},
startDate: startDate,
endDate: endDate
};

opsgenie.forwardingV2.create(create_rule_json, function (error, alert) {
if (error) {
console.error(error);
} else {
console.log("Create Forwarding Rule Response:");
console.log(alert);
}
});
18 changes: 18 additions & 0 deletions samples/forwardingV2/delete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict";

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

let delete_rule_identifier = {
identifier: "7b55b16e-3de7-44b1-8c04-31e5966a7a31",
identifierType : "id"
};

opsgenie.forwardingV2.delete(delete_rule_identifier, function (error, result) {
if (error) {
console.error(error);
} else {
console.log("Delete Forwarding Rule Response:");
console.log(result);
}
});
18 changes: 18 additions & 0 deletions samples/forwardingV2/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict";

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

let get_rule_identifier = {
identifier: "ebb3c4e0-b9b9-4b6d-89d8-6b10032719db",
identifierType : "id"
};

opsgenie.forwardingV2.get(get_rule_identifier, function (error, rule) {
if (error) {
console.error(error);
} else {
console.log("Get Rule Response for id: ");
console.log(rule);
}
});
17 changes: 17 additions & 0 deletions samples/forwardingV2/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";

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

let list_params = {
order : "desc"
};

opsgenie.forwardingV2.list(list_params, function (error, rules) {
if (error) {
console.error(error);
} else {
console.log("List Rules Response");
console.log(rules);
}
});
30 changes: 30 additions & 0 deletions samples/forwardingV2/update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use strict";

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

let todaysDate = new Date();
todaysDate.setDate(todaysDate.getDate() + 1);
let startDate = todaysDate.toISOString();
todaysDate.setDate(todaysDate.getDate() + 14);
let endDate = todaysDate.toISOString();

let update_rule_json = {
fromUser: {
id: 'c1754eea-7f80-4126-8a64-a55c42439947'
},
toUser: {
id: '830e4738-fc50-4bd0-b789-00fc0db76418'
},
startDate: startDate,
endDate: endDate
};

opsgenie.forwardingV2.updateRule("ebb3c4e0-b9b9-4b6d-89d8-6b10032719db", update_rule_json, function (error, rule) {
if (error) {
console.error(error);
} else {
console.log("Update Rule Response");
console.log(rule);
}
});

0 comments on commit 30ddc71

Please sign in to comment.