import type { AxiosRequestConfig } from 'axios' ; import type { GiphySearchOptions , GiphyRandomOptions , GiphyTrendingOptions , GiphyIdOptions } from './GiphyOptions' ; import type { GiphyResult , GiphyMultipleResult } from './GiphyResult' ; import type { HttpClient } from '../http/' ; export class GiphyAPI { constructor ( private readonly client ) { } public static readonly URL = { GIPHY : 'giphy/v1/gifs' , PROXY : '/proxy' , RANDOM : 'random' , SEARCH : 'search' , TRENDING : 'trending' , } ; see https public async getGiphyByIds ( options ) { const allIds = options . ids . join ( ',' ) ; const optionsWithoutIds = { random_id : options . random_id , rating : options . rating } ; const config = { method : 'get' , params : optionsWithoutIds , url : `${ GiphyAPI . URL . PROXY }/${ GiphyAPI . URL . GIPHY }/${ allIds }` , } ; const response = await this . client . sendJSON < GiphyMultipleResult > ( config ) ; return response . data ; } see https public async getGiphyById ( id ) { const config = { method : 'get' , url : `${ GiphyAPI . URL . PROXY }/${ GiphyAPI . URL . GIPHY }/${ id }` , } ; const response = await this . client . sendJSON < GiphyMultipleResult > ( config ) ; return response . data ; } see https public async getGiphyRandom ( options ? ) { const config = { method : 'get' , params : options , url : `${ GiphyAPI . URL . PROXY }/${ GiphyAPI . URL . GIPHY }/${ GiphyAPI . URL . RANDOM }` , } ; const response = await this . client . sendJSON < GiphyResult > ( config ) ; return response . data ; } see https public async getGiphySearch ( options ) { const config = { method : 'get' , params : options , url : `${ GiphyAPI . URL . PROXY }/${ GiphyAPI . URL . GIPHY }/${ GiphyAPI . URL . SEARCH }` , } ; const response = await this . client . sendJSON < GiphyMultipleResult > ( config ) ; return response . data ; } see https public async getGiphyTrending ( options ) { const config = { method : 'get' , params : options , url : `${ GiphyAPI . URL . PROXY }/${ GiphyAPI . URL . GIPHY }/${ GiphyAPI . URL . TRENDING }` , } ; const response = await this . client . sendJSON < GiphyMultipleResult > ( config ) ; return response . data ; } }