npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bungie-net-api

v1.0.6

Published

A zero dependency library for the Bungie.net api

Downloads

7

Readme

Node.js Bungie.net API Library

This library aims to be the fastest, lightest-weight JavaScript implementation of the Bungie.net API. This project has 3 sacred goals

  1. Zero Dependency
  2. Fully Asynchronous
  3. Well Documented

Setup

  1. First create a project at https://www.bungie.net/en/Application
  2. Make sure that your OAuth client type is "Confidential" if you need to make oAuth calls
  3. Install this library npm install bungie-net-api
  4. Finally, create an API object as show below
  const ApiCredentials = {
    key : "you_secret_key",
    clientId : "your_client_id",
    clientSecret: "your_client_secret"
  }

  const BungieLib = require( 'bungie-net-api' );

  // This will load ALL micro-libraries
  const Api = new BungieLib( ApiCredentials );
  1. If you only need to load certain endpoints, you can do so by passing an array of micro-libraries that you will need to the BungieLib constructor
  const ApiCredentials = {
    key : "you_secret_key",
    clientId : "your_client_id",
    clientSecret: "your_client_secret"
  }

  const BungieLib = require( 'bungie-lib' );

  // This will only load the Destiny2, Forum, and User Micro-Libraries
  const Api = new BungieLib( ApiCredentials, [ 'destiny2', 'forum', 'user' ] );
  1. The first thing that you should do now is redirect your end user to the authentication endpoint and have them give your app permission to interact with their account
  // Redirect the end user to the auth uri somehow
  WebSocket.send( Api.authUri );
  1. Once the user has approved your application, they will be redirected to the uri that you specified at https://www.bungie.net/en/Application/Detail/ and your accessCode will be a querystring parameter. Grab it associate it with this client somehow (I use a session store). You'll need this code if you want to make privileged API requests

Fully Asynchronous

The library makes extensive use of native ES6 promises. Any non-trivial work load is exectued asynchonously making the library extrememly scalable. All API call return an ES6 Promise that resolves with the parsed Bungie.net API response.

  Api.User.getAvailableThemes().then( resp => {
    console.log( resp ); // Do something with the response
  } );

This means that you can make as many API calls as you want simultaneously.

  // All of these API calls will me made simultaneously.
  let calls = [
    Api.User.searchUsers( 'JackSparrow' ),
    Api.User.getAvailableThemes(),
    Api.Destiny2.searchPlayer( "JackSparrow", "TIGERPSN" ),
    Api.Trending.getTrendingCategory()
  ];

  // Once all of those API calls have finished, do work
  Promise.all( calls ).then( data => {
    // data[0] is the result of Api.User.searchUsers( 'JackSparrow' ), etc
  } );

Api Call Chaining

The Flexibility of promises allows us to take multiple API calls and chain them one after the other. FOr instance, lets request an oAuth access token and then immediately refresh that token. (You would never do this in real life, but it's a good example of an instance when we need one promise to wait on another promise)

  Api.OAuth.requestAccessToken( ApiCreds )
	.then( accessToken => Api.OAuth.refreshAccessToken( accessToken) )
	.then( newToken => {
		// Store our latest token somehow
	}) ;

Requesting an oAuth token

  Api.OAuth.requestAccessToken( ApiCreds.authCode ).then( oAuth => {
    // Save your oAuth tokens. A session store is recommended
  } );

Refreshing an oAuth token

  Api.OAuth.refrshAccessToken( oAuth ).then( oAUth => {
    // Save your oAuth tokens. A session store is recommended
  } );