Extract format response to helper function.

This commit is contained in:
mike.rode
2019-02-13 18:03:43 -06:00
parent d9aa5d8dae
commit cecc4db9e6
2 changed files with 12 additions and 10 deletions

View 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;

View File

@@ -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) => {