-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
31 lines (25 loc) · 877 Bytes
/
index.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
'use strict'
const request = require('./lib/request')
class TVDB {
constructor(apiKey) {
this.apiKey = apiKey
}
find(query, language = 'en') {
if (typeof query === 'undefined') {
return Promise.reject(new Error('The name or the ID of the serie is required'))
}
if (isNaN(query)) {
// Try to fetch the ID of the serie
return request(`http://thetvdb.com/api/GetSeries.php?seriesname=${query}`)
.then(serie => {
// Now that we have the ID, we can make the request to get the full serie episodes
return request(`http://thetvdb.com/api/${this.apiKey}/series/${serie.id}/all/${language}.xml`)
})
}
return request(`http://thetvdb.com/api/${this.apiKey}/series/${query}/all/${language}.xml`)
}
}
module.exports = apiKey => {
const tv = new TVDB(apiKey)
return {apiKey: tv.apiKey, find: tv.find}
}