@karate-combat/api
Version:
Karate Combat API Client
171 lines (162 loc) • 3.97 kB
JavaScript
;
var axios = require('axios');
class ApiClient {
constructor(baseURL = 'https://public-api.karate.com/api') {
this.http = axios.create({
baseURL
});
this.get = this.http.get;
}
}
let api = new ApiClient();
const initApiClient = (baseUrl) => {
api = new ApiClient(baseUrl);
};
async function getFightEvent(id) {
try {
const response = await api.get(`/fight-events/${id}`);
return response.data;
}
catch (error) {
console.error(error);
throw error;
}
}
async function getFightEventBySlug(slug) {
try {
const response = await api.get(`/fight-events/slug/${slug}`);
return response.data;
}
catch (error) {
console.error(error);
throw error;
}
}
async function getFightEventResults(id) {
try {
const response = await api.get(`/fight-events/${id}/results`);
return response.data;
}
catch (error) {
console.error(error);
throw error;
}
}
async function getFightEvents(params) {
try {
const response = await api.get(`/fight-events`, {
params
});
return response.data;
}
catch (error) {
console.error(error);
throw error;
}
}
async function getFighter(id) {
try {
const response = await api.get(`/fighters/${id}`);
return response.data;
}
catch (error) {
console.error(error);
throw error;
}
}
async function getFighterBySlug(slug) {
try {
const response = await api.get(`/fighters/slug/${slug}`);
return response.data;
}
catch (error) {
console.error(error);
throw error;
}
}
async function getFighterByWalletAddress(walletAddress) {
try {
const response = await api.get(`/fighters/address/${walletAddress}`);
return response.data;
}
catch (error) {
console.error(error);
throw error;
}
}
async function getFighters(params) {
try {
const response = await api.get(`/fighters`, {
params
});
return response.data;
}
catch (error) {
console.error(error);
throw error;
}
}
async function getFighterHistory(id) {
try {
const response = await api.get(`/fighters/${id}/history`);
return response.data;
}
catch (error) {
console.error(error);
throw error;
}
}
async function getFighterStats(id) {
try {
const response = await api.get(`/fighters/${id}/stats`);
return response.data;
}
catch (error) {
console.error(error);
throw error;
}
}
async function getFightResult(id) {
try {
const response = await api.get(`/fights/${id}`);
return response.data;
}
catch (error) {
console.error(error);
throw error;
}
}
async function getCountries() {
try {
const response = await api.get(`/countries`);
return response.data;
}
catch (error) {
console.error(error);
throw error;
}
}
async function getWeightClasses() {
try {
const response = await api.get(`/weight-classes`);
return response.data;
}
catch (error) {
console.error(error);
throw error;
}
}
exports.getCountries = getCountries;
exports.getFightEvent = getFightEvent;
exports.getFightEventBySlug = getFightEventBySlug;
exports.getFightEventResults = getFightEventResults;
exports.getFightEvents = getFightEvents;
exports.getFightResult = getFightResult;
exports.getFighter = getFighter;
exports.getFighterBySlug = getFighterBySlug;
exports.getFighterByWalletAddress = getFighterByWalletAddress;
exports.getFighterHistory = getFighterHistory;
exports.getFighterStats = getFighterStats;
exports.getFighters = getFighters;
exports.getWeightClasses = getWeightClasses;
exports.initApiClient = initApiClient;