philschatz / octokat.js

:octocat: Github API Client using Promises or callbacks. Intended for the browser or NodeJS.
http://philschatz.com/2014/05/25/octokat/
MIT License
421 stars 133 forks source link

Using the emitter #109

Open RichardLitt opened 8 years ago

RichardLitt commented 8 years ago

I am continually running into rate limits for the GitHub API, and it's pretty hard for me to diagnose my issues easily. In part, this is because my code has hundred of API calls, so it makes sense. I'd like to have a better picture into my rate limits as they happen by console logging what requests I am making and what rate limits I have left, after each one.

Someone pointed me to this line in the code. Is there an easy way for me to use this?

Thanks.

philschatz commented 8 years ago

Yes. It's not "officially" supported but you should be able to do something like the following:

options = {
  emitter: {
    emit: function(eventType, method, path, data, options) { 
      console.log(arguments); 
    }
  }
};
octo = require('octokat')(options)
octo.repos('philschatz/octokat.js').fetch()

You can try it out by changing the first line at https://tonicdev.com/npm/octokat

Hope that helps, and let me know if it works for you!