<commit_before>
import request from 'superagent';
import dateFormat from 'dateformat';


const API_ADDR = 'http://localhost:3000';


export default class PaymentsAPI {

	constructor() {

	}

	static constructURL(path) {
		return `${API_ADDR}${path}`
	}

	static get(path, params, SuccessCB, ErrorCB) {
		request
		  .get(this.constructURL('/payments')).query(params)
		  .end(function(err, resp){
		    if (err && ErrorCB) {
		    	ErrorCB(err);
		    } else if (SuccessCB) {
		    	SuccessCB(resp.body);
		    }
		  });
	}

	static post(path, data, SuccessCB, ErrorCB) {
		request
		  .post(this.constructURL('/payments')).send(data).set('Content-Type', 'application/json')
		  .end(function(err, resp){
		    if (err && ErrorCB) {
		    	ErrorCB(err);
		    } else if (SuccessCB) {
		    	SuccessCB(resp.body);
		    }
		  });
	}

	static getHighestPayments(N, SuccessCB, ErrorCB) {
		var doc = {};
		doc._sort = 'amount';
		doc._order = 'DESC';
		if (N) {
			doc._limit = N;
			doc._page = 1;
		}
		this.get(this.constructURL('/payments'), doc, SuccessCB, ErrorCB)
	}

	static getPaymentsBy(options, SuccessCB, ErrorCB) {
		this.get(this.constructURL('/payments'), options, SuccessCB, ErrorCB)
	}

	static sendNewPayment(data, SuccessCB, ErrorCB) {
		var d = new Date();
		data.created = dateFormat(d, "ddd mmm dd yyyy HH:MM:ss Z");
		this.post(this.constructURL('/payments'), data, SuccessCB, ErrorCB)
	}

}<commit_msg>move filtering to clientside :sweat:<commit_after>
import request from 'superagent';
import dateFormat from 'dateformat';


const API_ADDR = 'http://localhost:3000';


export default class PaymentsAPI {

	constructor() {

	}

	static constructURL(path) {
		return `${API_ADDR}${path}`
	}

	static get(path, params, SuccessCB, ErrorCB) {
		request
		  .get(this.constructURL('/payments')).query(params)
		  .end(function(err, resp){
		    if (err && ErrorCB) {
		    	ErrorCB(err);
		    } else if (SuccessCB) {
		    	SuccessCB(resp.body);
		    }
		  });
	}

	static post(path, data, SuccessCB, ErrorCB) {
		request
		  .post(this.constructURL('/payments')).send(data).set('Content-Type', 'application/json')
		  .end(function(err, resp){
		    if (err && ErrorCB) {
		    	ErrorCB(err);
		    } else if (SuccessCB) {
		    	SuccessCB(resp.body);
		    }
		  });
	}

	static getHighestPayments(N, SuccessCB, ErrorCB) {
		this.get(this.constructURL('/payments'), {}, function(data) {
			data = data.sort((lhs, rhs) => rhs.amount - lhs.amount).slice(0, 20);
			SuccessCB(data);
		}, ErrorCB);
	}

	static getPaymentsBy(filters, SuccessCB, ErrorCB) {
		this.get(this.constructURL('/payments'), {}, function(data){
			console.log("filtering for", filters)
			console.log(Object.keys(filters))
			Object.keys(filters).forEach( function(filter, _) {
				data = data.filter((item) => item[filter] == filters[filter]);
			})
			SuccessCB(data);
		}, ErrorCB);
	}

	static sendNewPayment(data, SuccessCB, ErrorCB) {
		var d = new Date();
		data.created = dateFormat(d, "ddd mmm dd yyyy HH:MM:ss Z");
		this.post(this.constructURL('/payments'), data, SuccessCB, ErrorCB);
	}

}
{'fraction_non_alphanumeric': 0.16434810740860564, 'fraction_numerical': 0.0038822387576835974, 'mean_word_length': 3.580740740740741, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2735625', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1063, 'n_words': 216}