This package provides an easy-to-use client for interacting with the GuessMaster. It allows you to register users, log in, manage games, submit guesses, access leaderboards, and retrieve current user.
You can install this package via npm:
npm install guessmasterclient
To use the API client, first import the necessary services:
import { AuthService, GameService, GuessService, LeaderboardService, UserService } from 'guessmasterclient';
const registerUser = async () => {
try {
const response = await AuthService.RegisterUser({
name: 'John Doe',
email: 'john@example.com',
password: 'password123'
});
console.log(response.msg);
} catch (error) {
console.error(error);
}
};
const loginUser = async () => {
try {
const response = await AuthService.LoginUser({
email: 'john@example.com',
password: 'password123'
});
console.log(response.user);
} catch (error) {
console.error(error);
}
};
const logoutUser = async () => {
try {
const response = await AuthService.LogoutUser();
console.log(response.msg);
} catch (error) {
console.error(error);
}
};
const createGame = async () => {
try {
const response = await GameService.CreateGame({
difficulty: 'medium'
});
console.log(response);
} catch (error) {
console.error(error);
}
};
const getAllGames = async () => {
try {
const response = await GameService.GetAllGames();
console.log(response.games);
} catch (error) {
console.error(error);
}
};
const deleteGame = async (gameId) => {
try {
const response = await GameService.DeleteGame(gameId);
console.log(response.msg);
} catch (error) {
console.error(error);
}
};
const createGuess = async (gameId, guess) => {
try {
const response = await GuessService.CreateGuess(gameId, {
guess: guess
});
console.log(response.result);
} catch (error) {
console.error(error);
}
};
const getEasyLeaderboard = async () => {
try {
const response = await LeaderboardService.getLeaderboardEasyLevel();
console.log(response);
} catch (error) {
console.error(error);
}
};
const getMediumLeaderboard = async () => {
try {
const response = await LeaderboardService.getLeaderboardMediumLevel();
console.log(response);
} catch (error) {
console.error(error);
}
};
const getHardLeaderboard = async () => {
try {
const response = await LeaderboardService.getLeaderboardHardLevel();
console.log(response);
} catch (error) {
console.error(error);
}
};
const getCurrentUser = async () => {
try {
const response = await UserService.GetCurrentUser();
console.log(response.user);
} catch (error) {
console.error(error);
}
};
If you'd like to contribute, please fork the repository and submit a pull request.
This project is licensed under the MIT License.