|
|
@ -1,19 +1,21 @@ |
|
|
|
class JokeService { |
|
|
|
class JokeService { |
|
|
|
|
|
|
|
|
|
|
|
constructor(category = 'programming') { |
|
|
|
constructor(category = ['programming', 'coding', 'development'], lang = 'en') { |
|
|
|
this.category = category; |
|
|
|
this.category = Array.isArray(category) ? category : [category]; |
|
|
|
|
|
|
|
this.lang = lang; |
|
|
|
this.apiBaseUrl = 'https://v2.jokeapi.dev/joke/' |
|
|
|
this.apiBaseUrl = 'https://v2.jokeapi.dev/joke/' |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setCategory(category) { |
|
|
|
setCategory(category) { |
|
|
|
this.category = category; |
|
|
|
this.category = Array.isArray(category) ? category : [category]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
tell() { |
|
|
|
tell() { |
|
|
|
let service = this; |
|
|
|
let service = this; |
|
|
|
axios.get( |
|
|
|
|
|
|
|
service.apiBaseUrl + service.category |
|
|
|
axios.get(service.apiBaseUrl + getRandomItem(service.category), { |
|
|
|
).then((response) => { |
|
|
|
lang: service.lang |
|
|
|
|
|
|
|
}).then((response) => { |
|
|
|
if (response.data.error === false) { |
|
|
|
if (response.data.error === false) { |
|
|
|
service.show(response.data); |
|
|
|
service.show(response.data); |
|
|
|
} |
|
|
|
} |
|
|
@ -44,3 +46,7 @@ function showNotification(text) { |
|
|
|
// alert(text);
|
|
|
|
// alert(text);
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getRandomItem(items) { |
|
|
|
|
|
|
|
return items[Math.floor(Math.random()*items.length)]; |
|
|
|
|
|
|
|
} |