-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquoteGenerator.js
More file actions
36 lines (31 loc) · 875 Bytes
/
quoteGenerator.js
File metadata and controls
36 lines (31 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const axios = require('axios');
const getURI = (random) => {
let uri = `https://6qme6dsq0i.execute-api.us-east-1.amazonaws.com/api/quotes`;
if (random)
uri = uri + '/random';
return uri;
}
//TODO: add query param for random
const request = async (random) => {
const url = getURI(random);
return axios.get(url)
.then(function (response) {
if (response.data && response.data.message)
return response.data.message;
else
return 'error'; //TODO add better error
})
.catch(function (error) {
console.log(error);
})
.finally(function () {
// always executed
});
};
const getQuote = () => {
return request(true);
};
const getAllQuotes = () => {
return request(false);
};
module.exports = {getQuote, getAllQuotes};