3.0.1 • Published 7 months ago

bungie-net-core v3.0.1

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

bungie-net-core

This is a Typescript wrapper for the Bungie API. It is mostly for personal use, but if you find any bugs please report them.

Installation

npm i bungie-net-core

Example Usage

This http method is used for makingrequests to the Bungie Platform API

import { BungieHttpProtocol } from 'bungie-net-core';
import { getProfile } from 'bungie-net-core/services/Destiny2';

const bungiePlatformHttp: BungieHttpProtocol = async config => {
  const headers = new Headers({
    'X-API-KEY': process.env.BUNGIE_API_KEY!
  });

  let body;
  if (config.contentType === 'application/json') {
    headers.set('Content-Type', config.contentType);
    body = JSON.stringify(config.body);
  }

  // implement how you like
  // headers.set('Authorization', `Bearer ${access_token}`);

  const url = config.baseUrl + (config.searchParams ? '?' + config.searchParams.toString() : '');

  const payload = {
    method: config.method,
    body,
    headers
  };

  const res = await fetch(url, payload);
  if (!res.ok) {
    // Your choice here
    throw new Error(res.statusText);
  }

  if (res.headers.get('Content-Type')?.includes('application/json')) {
    return await res.json();
  } else {
    // Your choice here
    throw new Error('Response was not JSON');
  }
};

getProfile(bungiePlatformHttp, {
  components: ['CharacterInventories'],
  destinyMembershipId: '4611741274194011',
  membershipType: 3
});
2.2.0

7 months ago

2.1.4

7 months ago

3.0.1

7 months ago

3.0.0

7 months ago

2.1.3

11 months ago

2.1.2

11 months ago

1.1.7

2 years ago

1.1.6

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago