ring-websites-sdk
Version:
Ring Websites SDK
49 lines (40 loc) • 1.46 kB
JavaScript
const AwsSign = require('aws-sign');
const aws4 = require('aws4');
const request = require('request');
class RingWebsitesSDK {
constructor(spaceUuid, accessKey, secretKey, options) {
this.accessKey = accessKey;
this.secretKey = secretKey;
this.spaceUuid = spaceUuid;
this.options = options || {};
this.signer = new AwsSign({
accessKeyId: accessKey, secretAccessKey: secretKey,
});
}
async call(query) {
return new Promise((resolve, reject) => {
const opts = {
method: 'POST',
region: 'eu-central-1',
host: 'api.ringpublishing.com',
path: '/websites/v2/' + this.spaceUuid,
body: JSON.stringify(query),
service: 'execute-api',
headers: {
'content-type': 'application/json',
},
proto: 'https',
url: 'https://api.ringpublishing.com/websites/v2/' + this.spaceUuid,
timeout: this.options.timeout || 4000
};
aws4.sign(opts, {accessKeyId: this.accessKey, secretAccessKey: this.secretKey});
let req = request(opts, (error, response, body) => {
if (error) {
return reject(error)
}
resolve(body);
});
});
}
}
module.exports = RingWebsitesSDK;