const q = require('q');
const request = q.nfbind(require('browser-request'));

export default class RtsClient {
    constructor(url) {
        this._url = url;
    }

    getTeamsConfig() {
        return request({
            url: this._url + '/teams',
            json: true,
        });
    }

    /**
     * Track a referral with the Riot Team Server. This should be called once a referred
     * user has been successfully registered.
     * @param {string} referrer the user ID of one who referred the user to Riot.
     * @param {string} user_id the user ID of the user being referred.
     * @param {string} user_email the email address linked to `user_id`.
     * @returns {Promise} a promise that resolves to [$response, $body], where $response
     * is the response object created by the request lib and $body is the object parsed
     * from the JSON response body. $body should be { team_token: 'sometoken' } upon
     * success.
     */
    trackReferral(referrer, user_id, user_email) {
        return request({
            url: this._url + '/register',
            json: true,
            body: {referrer, user_id, user_email},
            method: 'POST',
        });
    }

    getTeam(team_token) {
        return request({
            url: this._url + '/teamConfiguration',
            json: true,
            qs: {team_token},
        });
    }
}

@@ -37,44 +37,541 @@
 t = 
-q.nfbind(require('browser-request'))
+(opts) =%3E %7B%0A    const expectingJSONOnSucess = opts.json;%0A    if (opts.json) %7B%0A        opts.json = false;%0A    %7D%0A    return q.nfbind(require('browser-request'))(opts).then((args) =%3E %7B%0A        const response = args%5B0%5D;%0A        let body = args%5B1%5D;%0A%0A        // Do not expect JSON on error status code, throw error instead%0A        if (response.statusCode !== 200) %7B%0A            throw new Error(body);%0A        %7D%0A%0A        if (expectingJSONOnSucess) %7B%0A            body = JSON.parse(body);%0A        %7D%0A%0A        return %5Bresponse, body%5D;%0A    %7D);%0A%7D
 ;%0A%0Ae

Throw errors on !==200 status codes from RTS