{"size": 1287, "ext": "js", "max_stars_repo_path": "machines/get-user-profile.js", "max_stars_repo_name": "grntartaglia/machinepack-treehouse", "max_stars_repo_stars_event_min_datetime": "2015-06-05T20:15:11.000Z", "max_stars_repo_stars_event_max_datetime": "2015-10-30T18:30:10.000Z", "max_issues_repo_path": "machines/get-user-profile.js", "max_issues_repo_name": "grntartaglia/machinepack-treehouse", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "machines/get-user-profile.js", "max_forks_repo_name": "grntartaglia/machinepack-treehouse", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 16.0875, "max_line_length": 74, "alphanum_fraction": 0.5648795649}
module.exports = {


  friendlyName: 'Get user profile',


  description: "Get a user's Treehouse profile information.",


  cacheable: false,


  sync: false,


  idempotent: false,


  inputs: {

    username: {
      example: 'chalkers',
      description: 'The Treehouse username.',
      required: true
    }

  },


  exits: {

    error: {
      description: 'Unexpected error occurred.'
    },

    notFound: {
      description: 'Treehouse profile not found.'
    },

    success: {
      description: 'Returns a user object.'
    },

  },


  fn: function (inputs, exits) {

    var Http = require('machinepack-http');

    Http.sendHttpRequest({
      baseUrl: 'https://teamtreehouse.com',
      url: '/' + inputs.username + '.json',
      method: 'get'
    }).exec({
      error: function(err) {
        return exits.error('An unexpected error occured.');
      },

      notFound: function(result) {
        return exits.notFound('Treehouse profile not found.');
      },

      success: function(result) {
        var responseBody;

        try {
          responseBody = JSON.parse(result.body);
        } catch(e) {
          return exits.error('An error occurred while parsing the body.');
        }

        return exits.success(responseBody);
      }
    });
  }


};
