41 lines
965 B
JavaScript
41 lines
965 B
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': 'andruxnet-random-famous-quotes.p.mashape.com',
|
|
'path': '/?cat=famous',
|
|
'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));
|
|
resolve(JSON.parse(data));
|
|
});
|
|
}).end();
|
|
});
|
|
}
|
|
|
|
};
|