EventRegistry / event-registry-node-js

Node.js package for API access to news articles and events in the Event Registry
MIT License
13 stars 2 forks source link

Utility methods not found #8

Closed HARAJLI98 closed 6 years ago

HARAJLI98 commented 6 years ago

When trying to access API usage data, I get the following error:

TypeError: er.getRemainingAvailableRequests is not a function
    at Object.fetchRemainingTokens (/src/jobs/eventregistry.js:41:25)
    at eventRegistry (/src/server.js:37:29)
    at Object.<anonymous> (/src/server.js:43:1)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)

Here's how I'm using the library:

const { EventRegistry } = require('eventregistry');
const er = new EventRegistry({apiKey: EVENT_REGISTRY_API_KEY});

try {
      console.log(er);
      return await er.getRemainingAvailableRequests();
} catch (e) {
      console.log(e);
}
UnspokenMallard commented 6 years ago

Thanks for the report. Fix for this issue is in the latest version (8.3.11) that was deployed today.

HARAJLI98 commented 6 years ago

I'm still not seeing updated values for the dailyRemainingRequests and remainingAvailableRequests. Those values are only initialized to -1 and never updated...

UnspokenMallard commented 6 years ago

The above-mentioned utility functions return values that are updated every time you make a query/request. If you only initialize the object without making any kind of requests then it only returns -1. This function is available on the EventRegistry object and you don't have to use await because it's not a Promise.

We are currently among other things adding an additional API endpoint that'll provide usage information.

HARAJLI98 commented 6 years ago

@UnspokenMallard Do you have an approximate time on when the API usage endpoints will be complete?

Thanks.

UnspokenMallard commented 6 years ago

@HARAJLI98 Usage information endpoint is available in the latest version (8.3.12) which was deployed today.

The function in question is called getUsageInfo and you can use it like this:

const er = new EventRegistry({apiKey: EVENT_REGISTRY_API_KEY});
er.getUsageInfo().then((data) => {
    console.log(data);
});