examples/node/index.js
function queryUserInfo(parentSpan, username, callback) {
    // Aggregated user information across multiple API calls
    var user = {
        login        : null,
        type         : null,
        repoNames    : [],
        recentEvents : 0,
        eventCounts  : {},
    };

    // Call the callback only when all three API requests finish or on the
    // first error.
    var remainingCalls = 3;
    var next = function (err) {
        // Early terminate on any error
        remainingCalls -= err ? Math.max(remainingCalls, 1) : 1;
        if (remainingCalls === 0) {
            callback(err, err ? null : user);
        }
    };

    // First query the user info for the given username
    httpGet(parentSpan, 'http://api.github.com/users/' + username, function (err, json) {
        if (err) {
            return next(err);
        }
        user.login = json.login;
        user.type  = json.type;

        // Use the user info to query names of all the user's public repositories
        httpGet(parentSpan, json.repos_url, function (err, json) {
            if (err) {
                return next(err);
            }
            for (var i = 0; i < json.length; i++) {
                user.repoNames.push(json[i].name);
            }
            next(null);
        });

        // In parallel, query the recent events activity for the user
        httpGet(parentSpan, json.received_events_url, function (err, json) {
            if (err) {
                return next(err);
            }
            user.recentEvents = json.length;
            for (var i = 0; i < json.length; i++) {
                var eventType = json[i].type;
                user.eventCounts[eventType] = user.eventCounts[eventType] || 0;
                user.eventCounts[eventType]++;
            }
            next(null);
        });

        next(null);
    });
}
function queryUserInfo(parentSpan, username, callback) {
    // Aggregated user information across multiple API calls
    var user = {
        login        : null,
        type         : null,
        repoNames    : [],
        recentEvents : 0,
        eventCounts  : {},
    };

    // Call the callback only when all three API requests finish or on the
    // first error.
    var remainingCalls = 3;
    var next = function (err) {
        // Early terminate on any error
        remainingCalls -= err ? Math.max(remainingCalls, 1) : 1;
        if (remainingCalls === 0) {
            callback(err, err ? null : user);
        }
    };

    // First query the user info for the given username
    httpGet(parentSpan, 'http://api.github.com/users/' + username, function (err, json) {
        if (err) {
            return next(err);
        }
        user.login = json.login;
        user.type  = json.type;

        // Use the user info to query names of all the user's public repositories
        httpGet(parentSpan, json.repos_url, function (err, json) {
            if (err) {
                return next(err);
            }
            for (var i = 0; i < json.length; i++) {
                user.repoNames.push(json[i].name);
            }
            next(null);
        });

        // In parallel, query the recent events activity for the user
        httpGet(parentSpan, json.received_events_url, function (err, json) {
            if (err) {
                return next(err);
            }
            user.recentEvents = json.length;
            for (var i = 0; i < json.length; i++) {
                var eventType = json[i].type;
                user.eventCounts[eventType] = user.eventCounts[eventType] || 0;
                user.eventCounts[eventType]++;
            }
            next(null);
        });

        next(null);
    });
}
function queryUserInfo ( parentSpan , username , callback ) { // Aggregated user information across multiple API calls var user = { login : null , type : null , repoNames : [ ] , recentEvents : 0 , eventCounts : { } , } ; // Call the callback only when all three API requests finish or on the // first error. var remainingCalls = 3 ; var next = function ( err ) { // Early terminate on any error remainingCalls -= err ? Math . max ( remainingCalls , 1 ) : 1 ; if ( remainingCalls === 0 ) { callback ( err , err ? null : user ) ; } } ; // First query the user info for the given username httpGet ( parentSpan , 'http://api.github.com/users/' + username , function ( err , json ) { if ( err ) { return next ( err ) ; } user . login = json . login ; user . type = json . type ; // Use the user info to query names of all the user's public repositories httpGet ( parentSpan , json . repos_url , function ( err , json ) { if ( err ) { return next ( err ) ; } for ( var i = 0 ; i < json . length ; i ++ ) { user . repoNames . push ( json [ i ] . name ) ; } next ( null ) ; } ) ; // In parallel, query the recent events activity for the user httpGet ( parentSpan , json . received_events_url , function ( err , json ) { if ( err ) { return next ( err ) ; } user . recentEvents = json . length ; for ( var i = 0 ; i < json . length ; i ++ ) { var eventType = json [ i ] . type ; user . eventCounts [ eventType ] = user . eventCounts [ eventType ] || 0 ; user . eventCounts [ eventType ] ++ ; } next ( null ) ; } ) ; next ( null ) ; } ) ; }
Make a series GitHub calls and aggregate the data into the `user` object
defined below.
Make a series GitHub calls and aggregate the data into the user object defined below .