51 lines
1.0 KiB
JavaScript
51 lines
1.0 KiB
JavaScript
/**
|
|
* Created by Martin on 31/03/2016.
|
|
*/
|
|
const https = require('https');
|
|
|
|
const STRING = require('string');
|
|
const logger = require('log4js').getLogger('quotes');
|
|
|
|
const options = {
|
|
'host': 'quotes.rest',
|
|
'path': '/qod.json',
|
|
|
|
/* ,
|
|
'headers': {
|
|
'accept': 'application/json',
|
|
'X-Mashape-Key': '5A0H980jK6mshSFL24ZmfiRrNHV2p1d1fhQjsngtx8QWuO9oe4',
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
}*/
|
|
'method': 'GET'
|
|
};
|
|
|
|
module.exports = {
|
|
'GetQuotes': function() {
|
|
'use strict';
|
|
|
|
return new Promise(function(resolve, reject) {
|
|
https.request(options).on('response', function (response) {
|
|
let data = '';
|
|
response.on('data', function (chunk) {
|
|
data += chunk;
|
|
});
|
|
response.on('end', function () {
|
|
// console.log(data);
|
|
// callback(JSON.parse(data));
|
|
|
|
const rawJSON = JSON.parse(data);
|
|
|
|
const rv = rawJSON.contents.quotes[0];
|
|
resolve(rv);
|
|
});
|
|
}).end();
|
|
});
|
|
}
|
|
|
|
};
|
|
|
|
/*
|
|
|
|
*/
|