k33g / gh3

Client-side Javascript API wrapper for GitHub API V3
370 stars 79 forks source link

Improve async api #1

Closed mklabs closed 12 years ago

mklabs commented 12 years ago

Most of the methods are designed to work asynchronously.

Kind.prototype.fetch = function(bob, foo, ..., callback) {
   // do stuff ...

  Gh3.Helper.callHttpApi({
      service : url,
      success : function(res) {
        callback(null, res);
      },
      error : function (res) {
        callbac(new Error(res));
      }
  });
};

...
var bob = new Kind;
bob.fetch(function('bob', 'and', 'his', 'friends', function(err, response) {
   console.log('fetching bob and is friends');
   if(err) {
      // deal with error
      return;
   }

   // handle response
   console.log(response);
});
k33g commented 12 years ago

:) yes, it will be provided, Atinux has already made the remark, you're all right. thank you for sample. i'm going to do that. I will probably submit you code snippet before commit.