Skip to content
This repository has been archived by the owner on Feb 1, 2021. It is now read-only.

Commit

Permalink
reworked ombi commands to use new API Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
v0idp committed Jan 22, 2020
1 parent 40cb897 commit f95d0d0
Show file tree
Hide file tree
Showing 11 changed files with 318 additions and 288 deletions.
101 changes: 98 additions & 3 deletions src/api_handlers/ombi.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,102 @@
class Ombi {
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);
}
}

module.exports = Ombi;
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);
}
}
4 changes: 1 addition & 3 deletions src/api_handlers/radarr.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class Radarr {
module.exports = class Radarr {
constructor(config) {
this.config = config;
}
}

module.exports = Radarr;
4 changes: 1 addition & 3 deletions src/api_handlers/sonarr.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class Sonarr {
module.exports = class Sonarr {
constructor(config) {
this.config = config;
}
}

module.exports = Sonarr;
6 changes: 2 additions & 4 deletions src/api_handlers/tautulli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { get, getURL } = require('./../util.js');

class Tautulli {
module.exports = class Tautulli {
constructor(config) {
this.config = config;
this.endpoints = {
Expand All @@ -16,7 +16,7 @@ class Tautulli {
'User-Agent': `Mellow/${process.env.npm_package_version}`},
url: this.endpoints["libraries"]
}).then((response) => {
let jsonResponse = JSON.parse(response.body);
const jsonResponse = JSON.parse(response.body);
resolve(jsonResponse);
}).catch((err) => {
console.log(err);
Expand All @@ -40,5 +40,3 @@ class Tautulli {
});
}
}

module.exports = Tautulli;
Loading

0 comments on commit f95d0d0

Please sign in to comment.