1.7.0 • Published 11 months ago

artifacts-api-client v1.7.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Api Client for Artifacts

npm npm

API wrapper for NodeJS and browsers with TypeScript support

Installation

npm i artifacts-api-client

Usage

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 works

Error 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.

1.7.0

11 months ago

1.6.0

11 months ago

1.5.0

11 months ago

1.2.0

12 months ago

1.1.0

12 months ago

1.0.1

12 months ago

1.4.0

12 months ago

1.3.0

12 months ago

1.0.0

12 months ago