-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.js
67 lines (49 loc) · 1.88 KB
/
fetch.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import fetch from 'node-fetch';
//import { fetch } from "node-fetch";
export default class Fetcher {
constructor(name) {
this.API_KEY = process.env.API_KEY;
this.lastMessage;
this.name = name;
this.hasNewMessage = false;
}
async getLatest() {
//Get JSON from API
const response = await fetch('https://www.jemelibere.be/wp-json/wp/v2/story?api_key=9$XA5DqD@tpI');
//const response = await fetch(`https://www.jemelibere.be/wp-json/wp/v2/story?api_key=${this.API_KEY}`)
const data = await response.json();
//Set hasNewMessage bool to false by default before checking
this.hasNewMessage = false;
//Get the message out of the JSON
const message = data[0].content.rendered;
const result = {
lastMessage: this.lastMessage,
hasNewMessage: this.hasNewMessage
}
if (message != this.lastMessage) {
// Replace the last message for check
this.lastMessage = message;
//Update result object
result.lastMessage = message;
result.hasNewMessage = true;
return result;
} else {
return result;
}
}
async getSome(amount){
const response = await fetch(`https://www.jemelibere.be/wp-json/wp/v2/story?api_key=9$XA5DqD@tpI&per_page=${amount}`);
const data = await response.json();
return data;
}
async getAll() {
const response = await fetch('https://www.jemelibere.be/wp-json/wp/v2/story?api_key=9$XA5DqD@tpI');
const data = await response.json();
return data;
}
async getAllTimeFiltered(time){
const response = await fetch('https://www.jemelibere.be/wp-json/wp/v2/story?api_key=9$XA5DqD@tpI');
const data = await response.json();
return data;
}
}