'use strict';

var request = require('request');

class CartoDBMapClient {
  constructor(user, apiKey) {
    this.user = user;
  	this.apiKey = apiKey;
    this.baseURL = 'https://' + this.user + '.cartodb.com/';
  }

  createNamedMap(options) {
    this.existsNamedMap(options.name).then(function() {

    });
  }

  existsNamedMap(name) {
    var $this = this;
    var promise = new Promise(function(resolve, reject) {
      request({
        method: 'GET',
        uri: $this.baseURL + 'tiles/template/' + name,
        qs: {
          'api_key': $this.apiKey,
        },
        json: {}
      }, function(error, response, body) {
        if(error) {
          reject(error);
        }
        resolve({
          exists: response.statusCode !== 404,
          data: body
        });
      });
    });
    return promise;
  }

  getGroupID(name) {
    var $this = this;
    var promise = new Promise(function(resolve, reject) {
      request({
        method: 'POST',
        uri: $this.baseURL + 'tiles/template/' + name,
        qs: {
          'api_key': $this.apiKey,
        },
        json: {}
      }, function(error, response, body) {
        if(error) {
          reject(error);
        }
        resolve(body);
      });
    });
    return promise;
  }
}

module.exports = CartoDBMapClient;

@@ -1259,16 +1259,468 @@
 ise;%0A  %7D
+%0A%0A  api(suffixUrl, params) %7B%0A    var $this = this;%0A    // jshint camelcase: false%0A    params.api_key = this.apiKey;%0A    var promise = new Promise(function(resolve, reject) %7B%0A      request(%7B%0A        method: 'GET',%0A        uri: $this.baseURL + suffixUrl,%0A        qs: params,%0A        json: %7B%7D%0A      %7D, function(error, response, body) %7B%0A        if(error) %7B%0A          reject(error);%0A        %7D%0A        resolve(body);%0A      %7D);%0A    %7D);%0A    return promise;%0A  %7D
 %0A%7D%0A%0Amodu

Add api method