<commit_before>var functions = require('firebase-functions')
var admin = require('firebase-admin')
var request = require('request')
var express = require('express')
var bodyParser = require('body-parser')
var requestPromise = require('request-promise')

var expressApp = express()

expressApp.use(bodyParser.json())
expressApp.use(bodyParser.urlencoded({ extended: true }))

exports.Authenticate = functions.https.onRequest(function(appRequest, appResponse) {
    var apiUri = 'http://zerobot.herokuapp.com/hubot/otp/' + appRequest.body.username

    var options = {
        method: 'POST',
        uri: apiUri,
        body: { 
            token: appRequest.body.token
        },
        json: true,
        resolveWithFullResponse: true,
        simple: false
    };

    console.log('Request to "' + apiUri 
        + '" with token = "' + appRequest.body.token + '", user = "' + appRequest.body.username +'"');

    requestPromise(options)
        .then(function (apiResponse) {
            console.log('Response code = ' + apiResponse.statusCode);
            console.log('The API authentication process was successful? = ' + (apiResponse.statusCode == 200));
            appResponse.status(apiResponse.statusCode).end();
        })
        .catch(function (error) {
            console.log('Error happened in the API request.');
            console.log(error);
            appResponse.status(400).end();
        })
})<commit_msg>Add a cloud function which sets a member in Firebase DB.<commit_after>var functions = require('firebase-functions')
var admin = require('firebase-admin')
var request = require('request')
var express = require('express')
var bodyParser = require('body-parser')
var requestPromise = require('request-promise')

var expressApp = express()

expressApp.use(bodyParser.json())
expressApp.use(bodyParser.urlencoded({ extended: true }))
admin.initializeApp(functions.config().firebase)

exports.Authenticate = functions.https.onRequest(function(appRequest, appResponse) {
    var apiUri = 'http://zerobot.herokuapp.com/hubot/otp/' + appRequest.body.username

    var options = {
        method: 'POST',
        uri: apiUri,
        body: { 
            token: appRequest.body.token
        },
        json: true,
        resolveWithFullResponse: true,
        simple: true
    };

    console.log('Request to "' + apiUri 
        + '" with token = "' + appRequest.body.token + '", user = "' + appRequest.body.username +'"');

    requestPromise(options)
        .then(function (apiResponse) {
            console.log('Response code = ' + apiResponse.statusCode);
            console.log('The API authentication process was successful? = ' + (apiResponse.statusCode == 200));
            appResponse.status(apiResponse.statusCode).end();
        })
        .catch(function (error) {
            console.log('Error happened in the API request.');
            console.log(error);
            appResponse.status(400).end();
        })
})

exports.SetMember = functions.https.onRequest(function (request, response) {
    var dataUri = 'member/' + request.body.username;
    var memberData = {
        name: request.body.username
    };

    admin.database().ref(dataUri).set(memberData)
        .then(function (snapshot) {
            console.log('Successfully saved the user. To = "' + dataUri + '"');
            console.log(memberData);
            response.status(200).end();
        })
        .catch(function (error) {
            console.log('Saving the user information failed. To = "' + dataUri + '"');
            console.log(error);
            response.status(400).end();
        });
})
{'fraction_non_alphanumeric': 0.13926499032882012, 'fraction_numerical': 0.004973749654600719, 'mean_word_length': 2.7512953367875648, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6171721', 'n_tokens_mistral': 1010, 'n_tokens_neox': 987, 'n_words': 205}