This repository has been archived by the owner on Feb 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from v0idp/api_rework
Api rework
- Loading branch information
Showing
19 changed files
with
425 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const Ombi = require('./ombi.js'); | ||
const Radarr = require('./radarr.js'); | ||
const Sonarr = require('./sonarr.js'); | ||
const Tautulli = require('./tautulli.js'); | ||
|
||
class APIHandler { | ||
constructor (config) { | ||
this.ombi = new Ombi(config.ombi); | ||
this.radarr = new Radarr(config.radarr); | ||
this.sonarr = new Sonarr(config.sonarr); | ||
this.tautulli = new Tautulli(config.tautulli); | ||
} | ||
} | ||
|
||
module.exports = APIHandler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
const { get, post, getURL, replacePlaceholders } = require('./../util.js'); | ||
|
||
module.exports = class Ombi { | ||
constructor (config) { | ||
this.config = config; | ||
this.endpoints = { | ||
"searchContent" : getURL(config.host, config.port, config.ssl, config.baseurl + '/api/v1/Search/%TYPE%/%NAME%'), | ||
"getContentInformation" : getURL(config.host, config.port, config.ssl, config.baseurl + '/api/v1/Search/%TYPE%/info/%DBID%'), | ||
"requestContent" : getURL(config.host, config.port, config.ssl, config.baseurl + '/api/v1/Request/%TYPE%/') | ||
}; | ||
} | ||
|
||
searchContent(type, name) { | ||
return new Promise((resolve, reject) => { | ||
get({ | ||
headers: {'accept' : 'application/json', | ||
'ApiKey': this.config.apikey, | ||
'User-Agent': `Mellow/${process.env.npm_package_version}`}, | ||
url: replacePlaceholders(this.endpoints['searchContent'], { "%TYPE%":type, "%NAME%":name }) | ||
}).then(({response, body}) => { | ||
if (response.statusCode === 200) { | ||
const data = JSON.parse(body); | ||
resolve(data); | ||
} | ||
else { | ||
console.log(response); | ||
reject() | ||
} | ||
}).catch((err) => { | ||
console.log(err); | ||
reject(); | ||
}); | ||
}); | ||
} | ||
|
||
getContentInformation(type, dbid) { | ||
return new Promise((resolve, reject) => { | ||
get({ | ||
headers: {'accept' : 'application/json', | ||
'ApiKey': this.config.apikey, | ||
'User-Agent': `Mellow/${process.env.npm_package_version}`}, | ||
url: replacePlaceholders(this.endpoints['getContentInformation'], { "%TYPE%":type, "%DBID%":dbid }) | ||
}).then(({response, body}) => { | ||
if (response.statusCode === 200) { | ||
const data = JSON.parse(body); | ||
resolve(data); | ||
} | ||
else { | ||
console.log(response); | ||
reject() | ||
} | ||
}).catch((err) => { | ||
console.log(err); | ||
reject(); | ||
}); | ||
}); | ||
} | ||
|
||
requestContent(type, body, name) { | ||
return new Promise((resolve, reject) => { | ||
post({ | ||
headers: {'accept' : 'application/json', | ||
'Content-Type' : 'application/json', | ||
'ApiKey': this.config.apikey, | ||
'ApiAlias' : name, | ||
'UserName' : this.config.username ? this.config.username : '', | ||
'User-Agent': `Mellow/${process.env.npm_package_version}`}, | ||
url: replacePlaceholders(this.endpoints['requestContent'], { "%TYPE%":type }), | ||
body: JSON.stringify(body) | ||
}).then(() => { | ||
resolve(); | ||
}).catch((err) => { | ||
console.log(err); | ||
reject(); | ||
}); | ||
}); | ||
} | ||
|
||
searchMovie(name) { | ||
return this.searchContent('movie', name); | ||
} | ||
|
||
getMovieInformation(tmdbid) { | ||
return this.getContentInformation('movie', tmdbid); | ||
} | ||
|
||
requestMovie(tmdbid, name) { | ||
return this.requestContent('movie', { 'theMovieDbId': tmdbid }, name); | ||
} | ||
|
||
searchTVShow(name) { | ||
return this.searchContent('tv', name); | ||
} | ||
|
||
getTVShowInformation(tvdbid) { | ||
return this.getContentInformation('tv', tvdbid); | ||
} | ||
|
||
requestTVShow(tvdbid, name) { | ||
return this.requestContent('tv', { 'tvDbId': tvdbid, "requestAll": true}, name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = class Radarr { | ||
constructor(config) { | ||
this.config = config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = class Sonarr { | ||
constructor(config) { | ||
this.config = config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const { get, getURL } = require('./../util.js'); | ||
|
||
module.exports = class Tautulli { | ||
constructor(config) { | ||
this.config = config; | ||
this.endpoints = { | ||
"libraries": getURL(config.host, config.port, config.ssl, config.baseurl + '/api/v2?apikey=' + config.apikey + '&cmd=get_libraries'), | ||
"refresh": getURL(config.host, config.port, config.ssl, config.baseurl + '/api/v2?apikey=' + config.apikey + '&cmd=refresh_libraries_list') | ||
}; | ||
} | ||
|
||
getLibraries() { | ||
return new Promise((resolve, reject) => { | ||
get({ | ||
headers: {'accept' : 'application/json', | ||
'User-Agent': `Mellow/${process.env.npm_package_version}`}, | ||
url: this.endpoints["libraries"] | ||
}).then((response) => { | ||
const jsonResponse = JSON.parse(response.body); | ||
resolve(jsonResponse); | ||
}).catch((err) => { | ||
console.log(err); | ||
reject(); | ||
}); | ||
}); | ||
} | ||
|
||
refreshLibraries() { | ||
return new Promise((resolve, reject) => { | ||
get({ | ||
headers: {'accept' : 'application/json', | ||
'User-Agent': `Mellow/${process.env.npm_package_version}`}, | ||
url: this.endpoints["refresh"] | ||
}).then(() => { | ||
resolve(); | ||
}).catch((err) => { | ||
console.log(err); | ||
reject(); | ||
}); | ||
}); | ||
} | ||
} |
Oops, something went wrong.