benweier / blizzard.js

A promise-based Node.JS library for the Blizzard Battle.net Community Platform API
MIT License
145 stars 29 forks source link

Examples do not work, documentation pretty sparse. #114

Closed jwshive closed 3 years ago

jwshive commented 4 years ago

New to blizzard.js, working with passport-bnet and it works just fine for authentication but needing to pull from the game apis.

Using the example on the readme I'm getting:

Error: Request failed with status code 403

My actual code:

const keys = require('./config/keys')

const blizzard = require('blizzard.js').initialize({
  key: keys.bnet.bnet_id,
  secret: keys.bnet.bnet_secret ,
  origin: 'us',
  locale: 'en_US'
});

async function example () {
  try {
    await blizzard.getApplicationToken()
      .then(response => {
        blizzard.defaults.token = response.data.access_token
      });
    const item = await blizzard.wow.item({ id: 168185 });
    console.log(item)
  } catch (err) {
    console.error(err);
  }
}

example();

The response url is not accurate for receiving an item it seems, responseUrl: 'https://us.api.blizzard.com/wow/item/168185?locale=en_US', does not work but responseUrl: 'https://us.api.blizzard.com/data/wow/item/168185?locale=en_US', But that appears to be the url for a different function in blizzard.js.

I do have to add ?namespace=static-us&locale=en_US&access_token= for the test to work.

I don't know if the initialize parameters aren't making it through or what's up but if this example should work, it does not.

Using node v12.18.2 and blizzard.js 3.2.0

Nerothos commented 4 years ago

I'm not sure the lib has been updated with the last change from the API.

anthony-bernardo commented 3 years ago

getting Error: Request failed with status code 403

think this lib is dead =(

rejas commented 3 years ago

yes, unfortunaltly @benweier seems to have abandoned it. or maybe he just didnt find the time to reply yet? eh @benweier how is life? hope you are okay?

benweier commented 3 years ago

I want to sincerely apologise for ghosting everyone who use this library and have been waiting for an update to the latest API. I'm not going to make an excuse, there's no reason why I couldn't have found a few minutes while watching Netflix to drop a comment explaining my absence. To provide some context though, this year has been pretty crazy (for so many people as we all know). I was furloughed from my job with a travel company in March, picked up a contract gig in April building the frontend for a new platform in React+TypeScript, this has been a major learning experience for me (especially TS) so I've been focused on that for some time. The contract turned permanent in July, followed by the most intense delivery period of my life which is really the only reason why I haven't responded here. Long story short: we publicly launched the project into the wild this week! I'm currently taking a week off to gather myself and hopefully give some attention to the things I have been neglecting recently.

I'm not able to guarantee I can pick up development of blizzard.js this week because I have a couple of personal goals to tackle, but I am now in a much better position to respond in a timely fashion and work with you all to get this updated for Shadowlands. I do promise to share more details within the coming week though.

Nerothos commented 3 years ago

Thanks for taking the time to reply. Take some time for you !

benweier commented 3 years ago

@Nerothos @rejas @xero88 @jwshive

First thing's first: I don't consider this library to be dead.

I've spent some time this week reacquainting myself with where I got to in the TypeScript rewrite for the new APIs. I'm fairly confident that once I nail the base types for the core functionality (creating an instance of the client, request generic, extending the sub-classes) that hooking up the right API paths and parameters will go smoothly. I'm working on this core atm while addressing the build tooling etc.

The eventual plan is to type the API responses as well, but that is going to be a lot of work considering all the individual requests and their configurations. This is probably where community contributions are going to be most valuable once I've sorted out what the rest looks like.

I'm sorry again for leaving you guys hanging for an update and really appreciate any remaining patience you are willing to spare 😄

rejas commented 3 years ago

welcome back @benweier just holla when we can help :-)

benweier commented 3 years ago

Alright, info dump time:

Library usage will change to look something like this

import { createInstance } from 'blizzard.js/wow';

const wow = await createInstance({ key, secret, token? }); // validates token if provided, gets one if not provided or token expired

const character = await wow.character(...) // the resources and methods have not been mapped out yet so this hasn't been finalised yet

console.log(character.data.name)

Axios makes it pretty easy to type the static data from a known response, but perhaps generics can work for the more dynamic endpoints. It could be simpler (or just less error-prone) for everyone if this responsibility is placed on the user, but we'll see where it makes most sense.

benweier commented 3 years ago

@rejas @Nerothos @xero88 @jwshive wishing you all a happy and safe [your specific regional or religious season greeting]! It's been a long time coming, and unfortunately we're not there yet, but I have just pushed the v4-ts branch so that you all can track the progress of the TypeScript rewrite. Tomorrow I'll add individual tasks to the PR to document what's left to do, but it's basically implementing all the methods for each game API.. so there's plenty of work remaining.

Please direct any specific comments or feedback to #118