caffeinewriter/node-scholarcheck

View on GitHub
out/index.js.html

Summary

Maintainability
Test Coverage
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Source: index.js</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

    <h1 class="page-title">Source: index.js</h1>

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>var request = require('request');

/**
 * Constructor for the Scholarcheck module.
 * @constructor
 * @param {string} apiKey - ScholarCheck.io API key
 */
var Scholarcheck = function(apiKey) {
  this.apiUrl = "https://app.scholarcheck.io/api/v1/";
  this.apiKey = apiKey || '';
};

/**
 * Internal API call method that returns raw data from an endpoint.
 * @param {string} endpoint - The endpoint to use in the request.
 * @param {Scholarcheck~apiCallback} callback - A callback to handle the returned data.
 */

Scholarcheck.prototype._apiCall = function(endpoint, callback) {
  var options = {
    url: this.apiUrl + endpoint,
    headers: {
      'Token': this.apiKey
    }
  };
  request(options, function(err, res, body) {
    callback(err, JSON.parse(body));
  });
};

/**
 * @callback Scholarcheck~apiCallback
 * @param {string} err - Any error that occured. Otherwise null.
 * @param {object} data - Raw API data returned.
 */

/**
 * Returns true in the callback if the email is a valid institutional email.
 * @param {string} email - An email to test for validity
 * @param {Scholarcheck~validCallback} cb - Calback that returns validity.
 */

Scholarcheck.prototype.valid = function(email, cb) {
  var apiReq = 'email/' + email;
  this._apiCall(apiReq, function(err, data) {
    if (!!err) {
      return cb(err);
    }
    return cb(null, data.valid);
  });
};

/**
 * @callback Scholarcheck~validCallback
 * @param {string} err - Any error that occured. Otherwise null.
 * @param {boolean} valid - True if email is institutional, otherwise false.
 */

/**
 * Returns the institution name in the callback if the email is a valid institutional email.
 * @param {string} email - An email to test for validity
 * @param {Scholarcheck~institutionCallback} cb - Calback that returns institution.
 */

Scholarcheck.prototype.institution = function(email, cb) {
  var apiReq = 'email/' + email;
  this._apiCall(apiReq, function(err, data) {
    if (!!err) {
      cb(err);
    }
    return cb(null, data.institutionName);
  });
};


/**
 * @callback Scholarcheck~institutionCallback
 * @param {string} err - Any error that occured. Otherwise null.
 * @param {string} institution - True if email is institutional, otherwise false.
 */

/**
 * Returns the raw data from the email endpoint.
 * @param {string} email - An email to test for validity
 * @param {Scholarcheck~rawCallback} cb - Calback that returns the raw data.
 */

Scholarcheck.prototype.rawData = function(email, cb) {
  var apiReq = 'email/' + email;
  this._apiCall(apiReq, function(err, data) {
    if (!!err) {
      return cb(err);
    }
    return cb(null, data);
  });
};

/**
 * @callback Scholarcheck~rawCallback
 * @param {string} err - Any error that occured. Otherwise null.
 * @param {object} data - Raw API data returned.
 */

module.exports = Scholarcheck;
</code></pre>
        </article>
    </section>




</div>

<nav>
    <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Scholarcheck.html">Scholarcheck</a></li></ul>
</nav>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-beta3</a> on Sat May 02 2015 17:29:25 GMT-0700 (Pacific Daylight Time)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>