<commit_before>'use strict';

var config      = require('../config');
var HttpGateway = require('synapse-common/http/auth-gateway');
var qs          = require('querystring');
var store       = require('store');

var OAuthClient = HttpGateway.extend({

    config : config.api,

    login : function(email, password)
    {
        return this.apiRequest(
            'POST',
            '/oauth/token',
            qs.stringify({
                username      : email,
                password      : password,
                grant_type    : 'password',
                client_id     : this.config.client_id,
                client_secret : this.config.client_secret
            })
        );
    },

    logout : function()
    {
        var token = store.get('token') || {};

        return this.apiRequest(
            'POST',
            '/oauth/logout',
            {
                refresh_token : token.refresh_token
            }
        );
    },

    refresh : function()
    {
        var token = store.get('token') || {};

        return this.apiRequest(
            'POST',
            '/oauth/token',
            qs.stringify({
                grant_type    : 'refresh_token',
                client_id     : this.config.client_id,
                refresh_token : token.refresh_token
            })
        );
    },

    _getRequestOptions : function(method, path)
    {
        var options;

        options = HttpGateway.prototype._getRequestOptions.call(this, method, path);

        options.headers['Content-Type'] = 'application/x-www-form-urlencoded';

        return options;
    }
});

module.exports = new OAuthClient();<commit_msg>Refs #55 - Extract OAuth endpoints to constants<commit_after>'use strict';

var config      = require('../config');
var HttpGateway = require('synapse-common/http/auth-gateway');
var qs          = require('querystring');
var store       = require('store');

var OAuthClient = HttpGateway.extend({

    config : config.api,

    OAUTH_TOKEN_ENDPOINT : '/oauth/token',

    OAUTH_LOGOUT_ENDPOINT : '/oauth/logout',

    login : function(email, password)
    {
        return this.apiRequest(
            'POST',
            this.OAUTH_TOKEN_ENDPOINT,
            qs.stringify({
                username      : email,
                password      : password,
                grant_type    : 'password',
                client_id     : this.config.client_id,
                client_secret : this.config.client_secret
            })
        );
    },

    logout : function()
    {
        var token = store.get('token') || {};

        return this.apiRequest(
            'POST',
            this.OAUTH_LOGOUT_ENDPOINT,
            {
                refresh_token : token.refresh_token
            }
        );
    },

    refresh : function()
    {
        var token = store.get('token') || {};

        return this.apiRequest(
            'POST',
            this.OAUTH_TOKEN_ENDPOINT,
            qs.stringify({
                grant_type    : 'refresh_token',
                client_id     : this.config.client_id,
                refresh_token : token.refresh_token
            })
        );
    },

    _getRequestOptions : function(method, path)
    {
        var options;

        options = HttpGateway.prototype._getRequestOptions.call(this, method, path);

        options.headers['Content-Type'] = 'application/x-www-form-urlencoded';

        return options;
    }
});

module.exports = new OAuthClient();
{'fraction_non_alphanumeric': 0.11610486891385768, 'fraction_numerical': 0.0005762028233938346, 'mean_word_length': 1.5949177877429, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6171411', 'n_tokens_mistral': 970, 'n_tokens_neox': 929, 'n_words': 169}