-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuoteManager.js
More file actions
28 lines (25 loc) · 844 Bytes
/
Copy pathQuoteManager.js
File metadata and controls
28 lines (25 loc) · 844 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
export default class QuoteManager {
constructor() {
this.quote = "";
}
// this API may be deprecated as well, looks like everything
// is returning 401 unauth errors now despite being a public api
// even on their website their swagger docs return 401
// maybe it needs a key now, but it looks like they may only have a few paid tiers
async getQuote() {
const url = "http://quotes.rest/qod.json";
const request = await fetch(url);
const data = await request.json();
this.quote = data.contents.quotes[0];
}
generateQuoteHTML() {
return `
<p class="quote__content">${this.quote.quote}</p>
<p class="quote__author">${this.quote.author}</p>
`
}
appendQuoteToDOM(element) {
const generatedQuoteHTML = this.generateQuoteHTML()
element.innerHTML = `${generatedQuoteHTML}`
}
}