<commit_before>require('es6-promise').polyfill();
require('isomorphic-fetch');

import EnvConstants from './../constants/EnvConstants';

function Api() {

}

Api.prototype.get = function (url, params) {
    console.log(EnvConstants.getApiServerUrl() + url + params)
    return fetch(
        EnvConstants.getApiServerUrl() + url + params,
        {
            method: 'GET',
            mode: "cors",
            headers: new Headers({
                 'Accept': 'application/json'
            })
        }
    ).then(function(response) {
        return response.json();
    }).then(function(json) {
        return json;
    }).catch(function(e) {
        console.log("An Error has occurred" + e);
    });
};

Api.prototype.post = function (url, params) {
    console.log(EnvConstants.getApiServerUrl());
    return fetch(
        EnvConstants.getApiServerUrl() + url,
        {
            method: 'POST',
            mode: "cors",
            body: JSON.stringify(params),
            headers: new Headers({
                'Accept': 'application/json'
            })
        }             
    ).then(function(response) {
        return response.json();
    }).then(function(json) {
        return json;
    }).catch(function(e) {
        console.log("An Error has occurred :" +e);
    });
};

Api.prototype.put = function (url, params) {
    console.log(EnvConstants.getApiServerUrl());
    return fetch(
        EnvConstants.getApiServerUrl() + url,
        {
            method: 'PUT',
            mode: "cors",
            body: JSON.stringify(params),
            headers: new Headers({
                'Accept': 'application/json'
            })
        }
    ).then(function(response) {
        return response.json();
    }).then(function(json) {
        return json;
    }).catch(function() {
        console.log("An Error has occurred");
    });
};

Api.prototype.delete = function (url, params) {
    console.log(EnvConstants.getApiServerUrl());
    return fetch(
        EnvConstants.getApiServerUrl() + url,
        {
            method: 'DELETE',
            mode: "cors",
            body: JSON.stringify(params),
            headers: new Headers({
                'Accept': 'application/json'
            })
        }
    ).then(function(response) {
        return response.json();
    }).then(function(json) {
        return json;
    }).catch(function() {
        console.log("An Error has occurred");
    });
};

Api.prototype.getJson = function (url, params) {
    return fetch(
        url,
        {
            method: 'POST',
            mode: "cors",
            body: JSON.stringify(params),
            headers: new Headers({
                'Accept': 'application/json'
            })
        }
    ).then(function(response) {
        return response.json();
    }).then(function(json) {
        return json;
    }).catch(function(e) {
        console.log("An Error has occurred :" +e);
    });
};

export default Api;<commit_msg>Refactoring Api.js to ECMA 2015<commit_after>require('es6-promise').polyfill();
require('isomorphic-fetch');
 
import EnvConstants from './../constants/EnvConstants';

export default class Api{
    get (url, params) {
        console.log(EnvConstants.getApiServerUrl() + url + params);
        return fetch(
            EnvConstants.getApiServerUrl() + url + params,
            {
                method: 'GET',
                mode: "cors",
                headers: new Headers({
                    'Accept': 'application/json'
                })
            }
        ).then(function(response) {
            return response.json();
        }).then(function(json) {
            return json;
        }).catch(function(e) {
            console.log("An Error has occurred" + e);
        });
    };

    post(url, params) {
        console.log(EnvConstants.getApiServerUrl());
        return fetch(
            EnvConstants.getApiServerUrl() + url,
            {
                method: 'POST',
                mode: "cors",
                body: JSON.stringify(params),
                headers: new Headers({
                    'Accept': 'application/json'
                })
            }             
        ).then(function(response) {
            return response.json();
        }).then(function(json) {
            return json;
        }).catch(function(e) {
            console.log("An Error has occurred :" +e);
        });
        };

    put(url, params) {
        console.log(EnvConstants.getApiServerUrl());
        return fetch(
            EnvConstants.getApiServerUrl() + url,
            {
                method: 'PUT',
                mode: "cors",
                body: JSON.stringify(params),
                headers: new Headers({
                    'Accept': 'application/json'
                })
            }
        ).then(function(response) {
            return response.json();
        }).then(function(json) {
            return json;
        }).catch(function() {
            console.log("An Error has occurred");
        });
    };

    delete  (url, params) {
        console.log(EnvConstants.getApiServerUrl());
        return fetch(
            EnvConstants.getApiServerUrl() + url,
            {
                method: 'DELETE',
                mode: "cors",
                body: JSON.stringify(params),
                headers: new Headers({
                    'Accept': 'application/json'
                })
            }
        ).then(function(response) {
            return response.json();
        }).then(function(json) {
            return json;
        }).catch(function() {
            console.log("An Error has occurred");
        });
    };

    getJson  (url, params) {
        return fetch(
            url,
            {
                method: 'POST',
                mode: "cors",
                body: JSON.stringify(params),
                headers: new Headers({
                    'Accept': 'application/json'
                })
            }
        ).then(function(response) {
            return response.json();
        }).then(function(json) {
            return json;
        }).catch(function(e) {
            console.log("An Error has occurred :" +e);
        });
    };
}
{'fraction_non_alphanumeric': 0.13709677419354838, 'fraction_numerical': 0.000967741935483871, 'mean_word_length': 1.521756811712078, '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': '4717745', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1631, 'n_words': 331}