'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 promise = new Promise(function(reject, resolve) {
      request({
        method: 'GET',
        uri: this.baseURL + 'tiles/template/' + name,
        qs: {
          'api_key': this.apiKey,
        },
        json: {}
      }, function(error, response, body) {
        if(error) {
          reject(error);
        }
        resolve({
          notExists: response.status === 404,
          exists: response.status === 200,
          data: body
        });
      });
    });
    return promise;
  }

  getGroupID(name) {
    var promise = new Promise(function(reject, resolve) {
      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;

@@ -326,32 +326,54 @@
 amedMap(name) %7B%0A
+    var $this = this;%0A
     var promise 
@@ -393,37 +393,37 @@
 (function(re
-ject, resolve
+solve, reject
 ) %7B%0A      re
@@ -458,32 +458,33 @@
 ',%0A        uri: 
+$
 this.baseURL + '
@@ -535,32 +535,33 @@
      'api_key': 
+$
 this.apiKey,%0A   
@@ -715,12 +715,9 @@
     
-notE
+e
 xist
@@ -738,59 +738,20 @@
 atus
- === 404,%0A          exists: response.status === 200
+Code !== 404
 ,%0A  
@@ -837,32 +837,54 @@
 GroupID(name) %7B%0A
+    var $this = this;%0A
     var promise 
@@ -912,21 +912,21 @@
 n(re
-ject, resolve
+solve, reject
 ) %7B%0A
@@ -978,16 +978,17 @@
    uri: 
+$
 this.bas
@@ -1055,16 +1055,17 @@
 i_key': 
+$
 this.api

Fix promises params and this references