planetside-census-request
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Planetside Census Request

An API wrapper to request data from the Census API.

Usage

Examples

CensusRequest with list validation

import CensusRequest from 'planetside-census-request';
import { NamespaceType } from 'planetside-census-data';

interface ICharacterFaction {
  character_id: string;
  faction_id: number;
}

const api = new CensusRequest(NamespaceType.PC, 's:example')

const getCharacters = async (
  ids: stirng[],
  collection: string = undefined
) => {
  return await api.get<ICharacterFaction[]>({
    uri: 'character',
    params: {
      'character_id': ids.join(','),
      'c:show': ['character_id','faction_id']
    },
    collection
  });
}

const characters = await getCharacters([
  '54200000000000000',
  '54200000000000001'
], 'character_list');

console.log(characters);

// [
//   {
//     character_id: '54200000000000000',
//     faction_id: 1,
//   },
//   {
//     character_id: '54200000000000001',
//     faction_id: 2,
//   }
// ]

CensusRequest without list validation

import CensusRequest from 'planetside-census-request';
import { NamespaceType } from 'planetside-census-data';

interface ICharacterFaction {
  character_id: string;
  faction_id: number;
}

const api = new CensusRequest(NamespaceType.PC, 's:example')

const getCharacters = async (
  ids: stirng[],
  collection: string = undefined
) => {
  return await api.get<ICharacterFaction[]>({
    uri: 'character',
    params: {
      'character_id': ids.join(','),
      'c:show': ['character_id','faction_id']
    },
    collection
  });
}

const characters = await getCharacters([
  '54200000000000000',
  '54200000000000001'
]);

console.log(characters);

// {
//    character_list: [
//      {
//        character_id: '54200000000000000',
//        faction_id: 1,
//      },
//      {
//        character_id: '54200000000000001',
//        faction_id: 2,
//      }
//    ],
//    returned: 2
// }

Readme

Keywords

Package Sidebar

Install

npm i planetside-census-request

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

9 kB

Total Files

10

Last publish

Collaborators

  • nicekiwi