/* http://docs.gurock.com/testrail-api2/start */
var rp = require('request-promise');

module.exports = TestRail = function(host, user, password) {
    this.host = host + "/index.php?/api/v2/";
    this.user = user;
    this.password = password;
    this.rejectUnauthorized = true;
    this.simpleRequests = false;
};

["cases","configs","milestones","plans","projects","results","runs",
    "sections","suites","tests","users","helpers"]
    .forEach(function(file){ require("./" + file); });

TestRail.prototype.allowUntrustedCertificate = function(){
    this.rejectUnauthorized = false;
};

TestRail.prototype.simpleRequests = function(){
    this.simpleRequests = true;
};

TestRail.prototype.getFullApiPath = function() {
    //Maybe return a promise like all other functions
    return this.host;
};

TestRail.prototype.get = function(url) {
    var options = {
        simple: this.simpleRequests,
        uri:this.host + url,
        json: true,
        rejectUnauthorized: this.rejectUnauthorized,
        headers: {
            "content-type": "application/json"
        }
    };
    return rp(options).auth(this.user, this.password, true);
};

TestRail.prototype.post = function(url,obj) {
    var options = {
        simple: this.simpleRequests,
        uri:this.host + url,
        json: true,
        rejectUnauthorized: this.rejectUnauthorized,
        headers: {
            "content-type": "application/json"
        },
        body: obj
    };
    return rp.post(options).auth(this.user, this.password, true);
};

//http://docs.gurock.com/testrail-api2/reference-statuses
TestRail.prototype.getStatuses = function() {
  return this.get("get_statuses/");
};

//http://docs.gurock.com/testrail-api2/reference-templates
TestRail.prototype.getTemplates = function(obj) {
    return this.get("get_templates/" + obj.project_id);
};

@@ -548,46 +548,153 @@
 ion(
+bool
 )%7B%0A    
-this.rejectUnauthorized = false
+if (typeof bool === 'undefined')%7B bool = false; %7D%0A    this.rejectUnauthorized = bool;%0A    return this.promise(this.rejectUnauthorized)
 ;%0A%7D;
@@ -744,41 +744,144 @@
 ion(
+bool
 )%7B%0A    
-this.simpleRequests = true
+if (typeof bool === 'undefined')%7B bool = true; %7D%0A    this.simpleRequests = bool;%0A    return this.promise(this.simpleRequests)
 ;%0A%7D;
@@ -939,69 +939,28 @@
     
-//Maybe 
 return 
-a 
+this.
 promise
- like all other functions%0A    return 
+(
 this
@@ -964,16 +964,17 @@
 his.host
+)
 ;%0A%7D;%0A%0ATe

Return promises for everything,