<commit_before>/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */

const https = require('https');
const Rx = require('rx');

const Logger = require('./Logger');

export default class NodeJira {
    constructor(options) {
        this.hostname = options.hostname;
        this.port = options.port;
        this.logger = new Logger(options.logger);
    }

    loginRx(username, password) {
        return Rx.Observable.create((observer) => {
            if (!username || !password) {
                observer.onError('Missing username and/or password');
                observer.onCompleted();
                return;
            }

            const postData = JSON.stringify({
                username,
                password,
            });

            const url = `/rest/auth/1/session`;

            const options = {
                hostname: this.hostname,
                port: this.port,
                path: url,
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'Content-Length': Buffer.byteLength(postData),
                },
            };

            this.logger.info('Handling login to Jira', username);

            const req = https.request(options, (res) => {
                if (res.statusCode === 401) {
                    return observer.onError('Username or password wrong');
                } else if (res.statusCode === 403) {
                    return observer.onError('CAPTCHA required');
                } else if (res.statusCode !== 200) {
                    return observer.onError({
                        code: res.statusCode,
                        message: res.statusMessage,
                    });
                }

                observer.onNext({
                    'setCookie': res.headers['set-cookie'],
                });

                res.setEncoding('utf8');
                res.on('data', (data) => {
                    observer.onNext(data);
                });
                res.on('end', () => {
                    observer.onCompleted();
                });
            });

            req.on('error', (e) => {
                this.logger.error('problem with request: ' + e.message);
                observer.onError(e);
                observer.onCompleted();
            });
            req.write(postData);

            req.end();
        }).reduce((prev, current) => {
            if (current.setCookie) {
                prev.setCookie = current.setCookie;
            } else {
                prev.data += current;
            }
            return prev;
        }, {data: ''}).map((data) => {
            return {
                cookie: new Buffer(JSON.stringify(data.setCookie)).toString('base64'),
                data: JSON.parse(data.data),
            };
        }).map((data) => {
            if (data.errorMessages) {
                this.logger.error(data.errorMessages[0]);
                throw new Error(data.errorMessages[0]);
            }
            return data;
        });
    }<commit_msg>Removed unnecesary functionality from NodeJira<commit_after>/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */

const https = require('https');
const Rx = require('rx');

const Logger = require('./Logger');

export default class NodeJira {
    constructor(options) {
        this.hostname = options.hostname;
        this.port = options.port;
        this.logger = new Logger(options.logger);
    }

    loginRx(username, password) {
        return Rx.Observable.create((observer) => {
            if (!username || !password) {
                observer.onError('Missing username and/or password');
                observer.onCompleted();
                return;
            }

            const postData = JSON.stringify({
                username,
                password,
            });

            const url = `/rest/auth/1/session`;

            const options = {
                hostname: this.hostname,
                port: this.port,
                path: url,
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                    'Content-Length': Buffer.byteLength(postData),
                },
            };

            this.logger.info('Handling login to Jira', username);

            const req = https.request(options, (res) => {
                if (res.statusCode === 401) {
                    return observer.onError('Username or password wrong');
                } else if (res.statusCode === 403) {
                    return observer.onError('CAPTCHA required');
                } else if (res.statusCode !== 200) {
                    return observer.onError({
                        code: res.statusCode,
                        message: res.statusMessage,
                    });
                }

                observer.onNext({
                    'setCookie': res.headers['set-cookie'],
                });

                res.setEncoding('utf8');
                res.on('data', (data) => {
                    observer.onNext(data);
                });
                res.on('end', () => {
                    observer.onCompleted();
                });
            });

            req.on('error', (e) => {
                this.logger.error('problem with request: ' + e.message);
                observer.onError(e);
                observer.onCompleted();
            });
            req.write(postData);

            req.end();
        }).reduce((prev, current) => {
            if (current.setCookie) {
                prev.setCookie = current.setCookie;
            } else {
                prev.data += current;
            }
            return prev;
        }, {data: ''}).map((data) => {
            return {
                cookie: new Buffer(JSON.stringify(data.setCookie)).toString('base64'),
                data: JSON.parse(data.data),
            };
        });
    }
{'fraction_non_alphanumeric': 0.13135379969803723, 'fraction_numerical': 0.004697198456634793, 'mean_word_length': 1.2363090772693173, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 26, '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': '3167497', 'n_tokens_mistral': 1548, 'n_tokens_neox': 1422, 'n_words': 279}