mirror of
https://github.com/mjrode/WhatToWatch.git
synced 2025-12-31 02:29:49 -06:00
Extract format response to helper function.
This commit is contained in:
11
server/services/plexApi/helpers.js
Normal file
11
server/services/plexApi/helpers.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import parser from 'xml2json';
|
||||
|
||||
const formatResponse = response => {
|
||||
const xmlResponse = response.headers['content-type'].includes('xml');
|
||||
if (xmlResponse) {
|
||||
return JSON.parse(parser.toJson(response.data));
|
||||
}
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export default formatResponse;
|
||||
@@ -1,7 +1,7 @@
|
||||
import axios from 'axios';
|
||||
import buildUrl from 'build-url';
|
||||
import parser from 'xml2json';
|
||||
import config from '../../../config';
|
||||
import formatResponse from './helpers';
|
||||
|
||||
function PlexApiClient(options) {
|
||||
this.setOptions(options);
|
||||
@@ -53,15 +53,6 @@ PlexApiClient.prototype.buildUrl = function(urlParams) {
|
||||
return buildUrl(host, urlHash);
|
||||
};
|
||||
|
||||
// Move to helper function
|
||||
const formatResponse = response => {
|
||||
const xmlResponse = response.headers['content-type'].includes('xml');
|
||||
if (xmlResponse) {
|
||||
return JSON.parse(parser.toJson(response.data));
|
||||
}
|
||||
return response.data;
|
||||
};
|
||||
|
||||
PlexApiClient.prototype.request = async function(url) {
|
||||
console.log('Request URL', url);
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
Reference in New Issue
Block a user