'use strict';

var request = require('request');

var opts = parseOptions(process.argv[2]);

request(opts, function (err, res, body) {
    if (err) throw new Error(err);

    var format = '[%s]: %s %s %s %s';

    for (var i = 0; i < body.length; i++) {
        /*
         * TODO return something like this as JSON
         * for caller consumption (useful for servers).
         */
        console.log(format
            , body[i].created_at
            , body[i].type
            , body[i].actor.login
            , body[i].repo.name);
    }
});

/*
 * Verify param is present, and just return it.
 * TODO
 *   Check for multiple params, and check validity
 *   as well as presence.
 */
function parseParams(params) {
    if (! params) {
        console.log('Usage: nodejs gevents.js <user-name>');
        process.exit(0);
    }

    return params;
}

function parseOptions(opts) {

    // org or users, resource, query topic
    var who = '/users'
      , where = '/' + opts
      , what  = '/events'

    var options = {
        uri: 'https://api.github.com'
          + who
          + where
          + what,
        json: true,
        method: 'GET',
        headers: {
            'User-Agent': 'nodejs script'
        }
    }

    return options;
}


'use strict';

var request = require('request');

var opts = parseOptions(process.argv[2]);

request(opts, function (err, res, body) {
    if (err) throw new Error(err);

    var format = '[%s]: %s %s %s';

    for (var i = 0; i < body.length; i++) {
        /*
         * TODO return something like this as JSON
         * for caller consumption (useful for servers).
         */
        console.log(format
            , body[i].created_at
            , body[i].type
            , body[i].actor.login
            , body[i].repo.name);
    }
});

/*
 * Verify param is present, and just return it.
 * TODO
 *   Check for multiple params, and check validity
 *   as well as presence.
 */
function parseParams(params) {
    if (! params) {
        console.log('Usage: nodejs gevents.js <user-name>');
        process.exit(0);
    }

    return params;
}

function parseOptions(opts) {

    // org or users, resource, query topic
    var who = '/users'
      , where = '/' + opts
      , what  = '/events'

    var options = {
        uri: 'https://api.github.com'
          + who
          + where
          + what,
        json: true,
        method: 'GET',
        headers: {
            'User-Agent': 'nodejs script'
        }
    }

    return options;
}


Remove superfluous string from format variable