0.1.6 • Published 5 years ago
@rainmakerdigital/switch-hmac v0.1.6
Installation
npm install --save @rainmakerdigital/switch-hmac-js
Usage
Get Request
const request = require("request");
const generateRequestHeaders = require("switch-hmac");
const vistaId = "< your supplied Vista ID >";
const secretKey = "< the supplied access key >";
const url = "< the supplied URL to VISTA.switch>";
const method = "GET";
const httpVersion = "HTTP/1.1"; // default "HTTP/1.1"
const params = {
vistaId: vistaId,
secretKey: secretKey,
url: url,
method: method,
httpVersion: httpVersion
};
let headers = generateRequestHeaders(params);
let options = {
url: url,
method: method,
headers: headers
};
request(options, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(JSON.parse(body));
} else {
console.log("error:" + response.statusCode);
console.log(body);
}
});
Post Request
const request = require("request");
const generateRequestHeaders = require("switch-hmac");
const vistaId = "< your supplied Vista ID >";
const secretKey = "< the supplied access key >";
const url = "< the supplied URL to VISTA.switch>";
const method = "POST";
const httpVersion = "HTTP/1.1"; // default "HTTP/1.1"
const data = {
"name" : "X"
};
const contentType = "application/json";
const params = {
vistaId: vistaId,
secretKey: secretKey,
url: url,
method: method,
httpVersion: httpVersion
data: JSON.stringify(data),
contentType: contentType,
}
let headers = generateRequestHeaders(params);
let options = {
url: url,
method: method,
headers: headers,
json: data
}
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
} else {
console.log("error:" + response.statusCode);
console.log(body);
}
});
UPDATE Request
const request = require("request");
const generateRequestHeaders = require("switch-hmac");
const vistaId = "< your supplied Vista ID >";
const secretKey = "< the supplied access key >";
const url = "< the supplied URL to VISTA.switch>";
const method = "UPDATE";
const httpVersion = "HTTP/1.1"; // default "HTTP/1.1"
const data = {
"name" : "Y"
};
const contentType = "application/json";
const params = {
vistaId: vistaId,
secretKey: secretKey,
url: url,
method: method,
httpVersion: httpVersion
data: JSON.stringify(data),
contentType: contentType,
}
let headers = generateRequestHeaders(params);
let options = {
url: url,
method: method,
headers: headers,
json: data
}
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
} else {
console.log("error:" + response.statusCode);
console.log(body);
}
});
DELETE Request
const request = require("request");
const generateRequestHeaders = require("switch-hmac");
const vistaId = "< your supplied Vista ID >";
const secretKey = "< the supplied access key >";
const url = "< the supplied URL to VISTA.switch>";
const method = "GET";
const httpVersion = "HTTP/1.1"; // default "HTTP/1.1"
const params = {
vistaId: vistaId,
secretKey: secretKey,
url: url,
method: method,
httpVersion: httpVersion
};
let headers = generateRequestHeaders(params);
let options = {
url: url,
method: method,
headers: headers
};
request(options, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(JSON.parse(body));
} else {
console.log("error:" + response.statusCode);
console.log(body);
}
});