import { ApisauceInstance, create } from "apisauce";
import { getGeneralApiProblem } from "services/api/apiProblem";

class YoutubeOembed {
  api: ApisauceInstance;
  constructor() {
    this.api = create({
      baseURL: "https://www.youtube.com",
      timeout: 10000,
    });
  }
  async metadata(url: string) {
    const response = await this.api.get(`oembed?url=` + url + `&format=json`);
    if (!response.ok) {
      return getGeneralApiProblem(response);
    }
    return response;
  }
}

export default new YoutubeOembed();
