'use strict';

const got = require('got');

class Request {
    constructor (options) {
        options = options || {};

        this.baseUrl = 'https://api.glesys.com';
        this.userAgent = 'https://github.com/jwilsson/glesys-api';

        this.apiKey = options.apiKey;
        this.apiUser = options.apiUser;
    }

    get (url, data) {
        const options = {
            method: 'GET',
            query: data,
        };

        url = this.baseUrl + url;

        return this.request(url, options);
    }

    post (url, data) {
        const options = {
            body: data,
            method: 'POST',
        };

        url = this.baseUrl + url;

        return this.request(url, options);
    }

    request (url, options) {
        const authString = new Buffer(`${ this.apiUser }:${ this.apiKey }`).toString('base64');
        const defaults = {
            headers: {
                Authorization: `Basic ${ authString }`,
            },
            json: true,
        };

        options = Object.assign(defaults, options);

        return got(url, options);
    }
}

module.exports = Request;

'use strict';

const got = require('got');

class Request {
    constructor (options) {
        options = options || {};

        this.baseUrl = 'https://api.glesys.com';
        this.userAgent = 'https://github.com/jwilsson/glesys-api';

        this.apiKey = options.apiKey;
        this.apiUser = options.apiUser;
    }

    get (url, data) {
        const options = {
            method: 'GET',
            query: data,
        };

        url = this.baseUrl + url;

        return this.request(url, options);
    }

    post (url, data) {
        const options = {
            body: data,
            method: 'POST',
        };

        url = this.baseUrl + url;

        return this.request(url, options);
    }

    request (url, options) {
        // eslint-disable-next-line node/no-deprecated-api
        const authString = new Buffer(`${ this.apiUser }:${ this.apiKey }`).toString('base64');
        const defaults = {
            headers: {
                Authorization: `Basic ${ authString }`,
            },
            json: true,
        };

        options = Object.assign(defaults, options);

        return got(url, options);
    }
}

module.exports = Request;

Disable node/no-deprecated-api for Buffer constructor
Disable node/no-deprecated-api for Buffer constructor

The use is deprecated since Node 6 but we still support Node 4 so we can't replace it yet.
