{"size": 728, "ext": "js", "max_stars_repo_path": "lib/rdstation/client.js", "max_stars_repo_name": "agendor/rdstation-node-client", "max_stars_repo_stars_event_min_datetime": "2016-02-14T23:37:28.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-28T20:44:06.000Z", "max_issues_repo_path": "lib/rdstation/client.js", "max_issues_repo_name": "agendor/rdstation-node-client", "max_issues_repo_issues_event_min_datetime": "2016-05-30T18:46:24.000Z", "max_issues_repo_issues_event_max_datetime": "2017-08-30T19:50:56.000Z", "max_forks_repo_path": "lib/rdstation/client.js", "max_forks_repo_name": "agendor/rdstation-node-client", "max_forks_repo_forks_event_min_datetime": "2016-02-01T13:18:34.000Z", "max_forks_repo_forks_event_max_datetime": "2018-01-29T18:57:21.000Z"}
{"max_stars_count": 12, "max_issues_count": 3, "max_forks_count": 7, "avg_line_length": 20.2222222222, "max_line_length": 63, "alphanum_fraction": 0.6565934066}
'use strict';

var Q = require('q');
var url = require('url');
var baseURL = 'https://www.rdstation.com.br';
var apiURL = baseURL + '/api/1.2/';
var request = require('superagent');

var self = module.exports = {

	post: function post(endpoint, body){
		return self.exec('post', endpoint, body);
	},

	
	put: function put(endpoint, body){
		return self.exec('put', endpoint, body);
	},
	
	exec: function exec(method, endpoint, body){
		var deferred = Q.defer(); // to convert callback into promise
		request[method](url.resolve(apiURL, endpoint))
			.send(body)
			.end(function(error, res){
				if (error) return deferred.reject(error);
				deferred.resolve(res);
			});
		return deferred.promise;
	},

	baseURL: baseURL

};


