{"size": 1066, "ext": "js", "max_stars_repo_path": "src/scripts/utils/request.js", "max_stars_repo_name": "JanKuukkanen/Oauth-client-react", "max_stars_repo_stars_event_min_datetime": "2016-05-09T14:41:56.000Z", "max_stars_repo_stars_event_max_datetime": "2016-05-09T14:41:56.000Z", "max_issues_repo_path": "src/scripts/utils/request.js", "max_issues_repo_name": "JanKuukkanen/Oauth-client-react", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/scripts/utils/request.js", "max_forks_repo_name": "JanKuukkanen/Oauth-client-react", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.6111111111, "max_line_length": 78, "alphanum_fraction": 0.6679174484}
import superagent from 'superagent/lib/client';
import page       from 'page';
import BroadcastAction from '../actions/broadcast';
/**
 * Simple helper module to make HTTP requests.
 */
export default {
	get:  request.bind(null, superagent.get),
	put:  request.bind(null, superagent.put),
	del:  request.bind(null, superagent.del),
	post: request.bind(null, superagent.post)
}

/**
 * Simple helper function to make HTTP requests. Note that you don't call this
 * directly but instead use one of the pre-bound methods above.a
 */
function request(to, options = {}) {
	return new Promise((resolve, reject) => {
		let request = to(options.url)
			.set('Accept',        'application/json')
			.set('Content-Type',  'application/json')
			.set('Authorization', `Bearer ${options.token}`);
		if(options.payload) {
			request = request.send(options.payload)
		}
		return request.end((err, res) => {
			if(err) {
				err.statusCode = err.status || res ? res.status : 0;
				return reject(err);
			}
			return resolve({ body: res.body, headers: res.headers });
		});
	});
}
