import axios, {AxiosPromise, AxiosRequestConfig, AxiosResponse} from 'axios' import {JoinCreateGameObject, IsStartedObject, ApiObject} from "@/objects/objects"; export default class PerudoApi { private static baseUrl = 'http://localhost:8000/' private static objectInstance?: PerudoApi; public static get instance(): PerudoApi { if (typeof PerudoApi.objectInstance === 'undefined') { PerudoApi.objectInstance = new PerudoApi(); } return PerudoApi.objectInstance; } public createGame(name: string): Promise { return this.get(PerudoApi.baseUrl + 'game/create?name=' + name) .then((response: AxiosResponse) => { return response.data; }) } public joinGame(name: string, code: string): Promise { return this.get(PerudoApi.baseUrl + 'game/join/' + code + '?name=' + name) .then((response: AxiosResponse) => { return response.data; }) } public startedGame(playerId: string): Promise { return this.get(PerudoApi.baseUrl + 'game/started/' + playerId) .then((response: AxiosResponse) => { return response.data; }) } public startGame(playerId: string): Promise { return this.get(PerudoApi.baseUrl + 'game/start/' + playerId) .then((response: AxiosResponse) => { return response.data; }); } private get(url: string, getParameters?: Record) { return axios.get(url).then((response: AxiosResponse) => { return response; }) } }