<commit_before>import config from '../config.json';
import rp from 'request-promise';
import request from 'request';
import fs from 'fs';

const options = {
            method: 'GET',
            url: "",
            agentOptions: {
                pfx: fs.readFileSync(config.certificate),
                passphrase: config.passphrase,
                securityOptions: 'SSL_OP_NO_SSLv3'
            }
        };

export default {
    get: (cardnum) => {
        let magstrip = "", rfid = "";
        if(cardnum.length === 16) {
            if(cardnum[0] !== ';') {
                rfid = cardnum;
            } else if(cardnum[0] === ';') {
                magstrip = cardnum.substring(1,14);
            } else {
                throw new IDCardFormatError("Invalid Card Number");
            }
        } else if(cardnum.length === 14) {
            magstrip = cardnum;
        } else {
            throw new IDCardFormatError("Invalid Card Number");
        }
        let opts = Object.assign({}, options, { 
            url: config.idcardBaseUrl +  "?mag_strip_code=" + magstrip + "&prox_rfid=" + rfid,
            json: true
        });

        return rp(opts)
          .then((parsedBody) => {
            return parsedBody.Cards[0].RegID;
          })
          .catch((err) => {
              throw err;
          });
    },
    getPhoto: (regId) => {
        let opts = Object.assign({}, options, { 
            url: config.photoBaseUrl + regId + '-large.jpg',
            encoding: null
        });
        return new Promise(function(resolve, reject) {
            request.get(opts, function (error, response, body) {
                if (!error && response.statusCode == 200) {
                    var data = "data:" + response.headers["content-type"] + ";base64," + new Buffer(body).toString('base64');
                    console.log(data);
                    resolve(data);
                } else {
                    reject(new IDCardFormatError("Photo not found", 404));
                }
            });
        });
    }
}

function IDCardFormatError(message, code = 400) {
   this.message = message;
   this.statusCode = code;
   this.toString = function() {
      return this.message;
   };
}<commit_msg>adding documentation<commit_after>import config from '../config.json';
import rp from 'request-promise';
import request from 'request';
import fs from 'fs';

const options = {
            method: 'GET',
            url: "",
            agentOptions: {
                pfx: fs.readFileSync(config.certificate),
                passphrase: <PASSWORD>,
                securityOptions: 'SSL_OP_NO_SSLv3'
            }
        };

export default {
    get: (cardnum) => {
        let magstrip = "", rfid = "";
        if(cardnum.length === 16) {
            if(cardnum[0] !== ';') {
                rfid = cardnum;
            } else if(cardnum[0] === ';') {
                magstrip = cardnum.substring(1,14);
            } else {
                throw new IDCardFormatError("Invalid Card Number");
            }
        } else if(cardnum.length === 14) {
            magstrip = cardnum;
        } else {
            throw new IDCardFormatError("Invalid Card Number");
        }
        let opts = Object.assign({}, options, { 
            url: config.idcardBaseUrl +  "?mag_strip_code=" + magstrip + "&prox_rfid=" + rfid,
            json: true
        });

        return rp(opts)
          .then((parsedBody) => {
            return parsedBody.Cards[0].RegID;
          })
          .catch((err) => {
              throw err;
          });
    },
    getPhoto: (regId) => {
        let opts = Object.assign({}, options, { 
            url: config.photoBaseUrl + regId + '-large.jpg',
            encoding: null
        });
        return new Promise(function(resolve, reject) {
            // Have to use request instead of request-promise as we need a buffer to convert to base64
            request.get(opts, function (error, response, body) {
                if (!error && response.statusCode == 200) {
                    var data = "data:" + response.headers["content-type"] + ";base64," + new Buffer(body).toString('base64');S
                    resolve(data);
                } else {
                    reject(new IDCardFormatError("Photo not found", 404));
                }
            });
        });
    }
}

function IDCardFormatError(message, code = 400) {
   this.message = message;
   this.statusCode = code;
   this.toString = function() {
      return this.message;
   };
}
{'fraction_non_alphanumeric': 0.13404114134041142, 'fraction_numerical': 0.011059500110595002, 'mean_word_length': 1.585477415666095, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3069585', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1235, 'n_words': 282}