Skip to content

Commit

Permalink
remove mode support use only configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhat Can committed Jun 21, 2016
1 parent 2a82e11 commit a0bf2a4
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 66 deletions.
2 changes: 1 addition & 1 deletion lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function setRetryPolicy() {
}

function getHost() {
return utils.getDefaultApiEndpoint(configuration.default_options.mode);
return configuration.default_options.host;
}

function getBasicHttpOptions(http_options) {
Expand Down
68 changes: 68 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"use strict";

var isArray = Array.isArray;
var hasOwn = Object.prototype.hasOwnProperty;

/**
* Recursively copies given object into a new object. Helper method for merge
*/
function clone(v) {
if (v === null || typeof v !== "object") {
return v;
}

if (isArray(v)) {
var arr = v.slice();
for (var i = 0; i < v.length; i++) {
arr[i] = clone(arr[i]);
}
return arr;
}
else {
var obj = {};
for (var k in v) {
obj[k] = clone(v[k]);
}
return obj;
}
}

/**
* Merges two Objects recursively, setting property of obj1 to those of obj2
* and creating property as necessary.
*/
var merge = exports.merge = function merge(obj1, obj2, appendOnly) {

if (obj1 === null || typeof obj1 !== "object") {
throw new TypeError("merge() - first parameter has to be an object, not " + typeof obj1 + ".");
}

if (obj2 === null || typeof obj2 !== "object") {
throw new TypeError("merge() - first parameter has to be an object, not " + typeof obj2 + ".");
}

if (isArray(obj1) || isArray(obj2)) {
throw new TypeError("merge() - Unsupported for arrays.");
}

for (var k in obj2) {
var obj1Val, obj2Val = obj2[k];
if (hasOwn.call(obj1, k)) {
if (!appendOnly) {
obj1Val = obj1[k];
if (obj1Val !== null && typeof obj1Val === "object" &&
obj2Val !== null && typeof obj2Val === "object") {
merge(obj1Val, obj2Val);
}
else {
obj1[k] = clone(obj2Val);
}
}
}
else {
obj1[k] = clone(obj2Val);
}
}
return obj1;
};

13 changes: 2 additions & 11 deletions samples/configure.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
"use strict";

var opsgenie = require('../');
// var api_key = require('./config').api_key;

opsgenie.configure({
'mode': 'lab',
'host': 'http://localhost:9000',
'api_key': "91e58022-8be4-4590-a4f0-0d4030bd9b0d"
});

// sample conf for localhost
/*
{
'mode': 'localhost',
'host': 'localhost:9000',
'api_key': 'local_key'
}*/
});
4 changes: 2 additions & 2 deletions samples/general/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
var opsgenie = require('../../');

opsgenie.configure({
'api_key': 'd1871497-38bc-4222-9063-32062fc6f2f4'
'api_key': 'your_api_key'
});

// optional for dev purposes
/*opsgenie.headers({
});*/

opsgenie.alert.get({id: "41fbe997-03cc-40ff-a4c4-7674b86b1490"}, function (error, alert) {
opsgenie.alert.get({id: "your_alert_id"}, function (error, alert) {
if (error) {
console.error(error);
} else {
Expand Down
Loading

0 comments on commit a0bf2a4

Please sign in to comment.