artifacts-api-client
v2.0.0
Published
Api client for https://artifactsmmo.com
Readme
Looking for maintainers
Contact me with discord (sirandev) or telegram if you interested in.
Api Client for Artifacts
API wrapper for NodeJS and browsers with TypeScript support
Installation
npm i artifacts-api-clientUsage
artifacts-api-client fully implements official API.
import { ArtifactsApi } from 'artifacts-api-client';
// Initialization
const artifactsApi = ArtifactsApi.create({
token: 'TOKEN'
});
// Usage
const status = await artifactsApi.getStatus();
const resources = await artifactsApi.resources.getAll({
min_level: 1,
max_level: 10,
})
await artifactsApi.myCharacters.fight('name');Alternatively, you can set token later:
import { ArtifactsApi } from 'artifacts-api-client';
const artifactsApi = ArtifactsApi.create();
await artifactsApi.myCharacters.fight('name'); // <-- fail, auth required
const { token } = await artifactsApi.token.generate('username', 'password');
artifactsApi.setToken(token);
await artifactsApi.myCharacters.fight('name'); // <-- now it worksError handling
All artifacts API errors are wrapped with ArtifactsError.
Keep in mind, that the others errors like NetworkError left as they are:
import { ArtifactsApi, ArtifactsError } from 'artifacts-api-client';
const artifactsApi = ArtifactsApi.create({
token: 'TOKEN'
});
try {
await artifactsApi.myCharacters.fight('name');
} catch (err) {
if (err instanceof ArtifactsError) {
console.error('Artifacts error', e.message, e.code, e.data);
} else {
throw e;
}
}Type bindings
If package being used with TypeScript you'll probably need methods' types. They are available to import:
import { ArtifactsApi, GetAllMapsApiResult, GetAllMapsApiQuery } from 'artifacts-api-client';
const artifactsApi = ArtifactsApi.create({
token: 'TOKEN'
});
function getMaps(params: GetAllMapsApiQuery): Promise<GetAllMapsApiResult> {
// ... custom logic ...
return artifactsApi.maps.getAll(params);
};Develop
Refer to DEVELOPMENT.md.
