Skip to content

Commit

Permalink
Added query parameters support
Browse files Browse the repository at this point in the history
  • Loading branch information
Feramance committed Jun 5, 2024
1 parent df0cc89 commit d244afa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
7 changes: 4 additions & 3 deletions Scripts/Flow/Applications/Radarr/Radarr - Rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Radarr } from 'Shared/Radarr';
* This script will send a rename command to Radarr
* @author Shaun Agius
* @version 1.0.0
* @revision 3
* @revision 4
* @param {string} URI Radarr root URI and port (e.g. http://radarr:1234)
* @param {string} ApiKey API Key
* @output Item renamed
Expand All @@ -15,8 +15,9 @@ function Script(URI, ApiKey) {
if (!movie)
return 2;
Logger.ILog(`Renaming ${movie.title}`);
let endpoint = `rename?movieId=${movie.id}`;
let response = radarr.fetchJson(endpoint);
let endpoint = `rename`;
let queryParmeters = `movieId=${movie.id}`
let response = radarr.fetchJson(endpoint, queryParmeters);
Logger.ILog(`Response ${response}`);
return 1;
}
7 changes: 4 additions & 3 deletions Scripts/Flow/Applications/Sonarr/Sonarr - Rename.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Sonarr } from 'Shared/Sonarr';
* This script will send a rename command to Sonarr
* @author Shaun Agius
* @version 1.0.0
* @revision 3
* @revision 4
* @param {string} URI Sonarr root URI and port (e.g. http://sonarr:1234)
* @param {string} ApiKey API Key
* @output Item renamed
Expand Down Expand Up @@ -33,8 +33,9 @@ function Script(URI, ApiKey) {
if (!series)
return 2;
Logger.ILog(`Renaming ${series.title}`);
let endpoint = `rename?seriesId=${series.id}`;
let response = sonarr.fetchJson(endpoint);
let endpoint = `rename`;
let queryParmeters = `seriesId=${series.id}`
let response = sonarr.fetchJson(endpoint, queryParmeters);
Logger.ILog(`Response ${response}`);
return 1;
}
15 changes: 9 additions & 6 deletions Scripts/Shared/Radarr.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Class that interacts with Radarr
* @name Radarr
* @revision 4
* @revision 5
* @minimumVersion 1.0.0.0
*/
export class Radarr
Expand All @@ -21,22 +21,25 @@ export class Radarr
MissingVariable('Radarr.ApiKey');
}

getUrl(endpoint)
getUrl(endpoint, queryParmeters)
{
let url = '' + this.URL;
if (url.endsWith('/') === false)
url += '/';
return `${url}api/v3/${endpoint}?apikey=${this.ApiKey}`;
url = `${url}api/v3/${endpoint}?apikey=${this.ApiKey}`;
if(queryParmeters)
url += '&' + queryParmeters;
return url;
}

fetchJson(endpoint)
fetchJson(endpoint, queryParmeters)
{
let url = this.getUrl(endpoint);
let url = this.getUrl(endpoint, queryParmeters);
let response = http.GetAsync(url).Result;
let body = response.Content.ReadAsStringAsync().Result;
if (!response.IsSuccessStatusCode)
{
Logger.WLog('Unable to fetch: ' + endpoint + '\n' + body);
Logger.WLog('Unable to fetch: ' + url + '\n' + body);
return null;
}
return JSON.parse(body);
Expand Down

0 comments on commit d244afa

Please sign in to comment.