moved option parsing in superclass 'get' method
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import fetch from 'cross-fetch';
|
import fetch from 'cross-fetch';
|
||||||
|
import { parseOptions } from './utils';
|
||||||
|
|
||||||
const BASE_URL_V3 = 'https://api.themoviedb.org/3';
|
const BASE_URL_V3 = 'https://api.themoviedb.org/3';
|
||||||
|
|
||||||
@@ -7,8 +8,9 @@ export default class Api {
|
|||||||
this.accessToken = accessToken;
|
this.accessToken = accessToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
async get<T>(path: string): Promise<T> {
|
async get<T>(path: string, options?: Record<string,any>): Promise<T> {
|
||||||
const response = await fetch(`${BASE_URL_V3}${path}`, {
|
const params = parseOptions(options);
|
||||||
|
const response = await fetch(`${BASE_URL_V3}${path}?${params}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${this.accessToken}`,
|
Authorization: `Bearer ${this.accessToken}`,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export function parseOptions(
|
export function parseOptions(
|
||||||
options?: { [s: string]: any },
|
options?: Record<string, any>,
|
||||||
): string {
|
): string {
|
||||||
return options
|
return options
|
||||||
? new URLSearchParams(Object.entries(options)).toString()
|
? new URLSearchParams(Object.entries(options)).toString()
|
||||||
|
|||||||
Reference in New Issue
Block a user