'use strict';

const WebMergeAPI = require('.');


function promiseFromCallback(fn) {
  return new Promise((resolve, reject) => {
    fn((err, response) => {
      if (err) return reject(err);
      return resolve(response);
    });
  });
}

class WebMergePromiseAPI extends WebMergeAPI {
  getDocuments(opts) {
    return promiseFromCallback(cb => super.getDocuments(opts, cb));
  }

  getDocument(id) {
    return promiseFromCallback(cb => super.getDocument(id, cb));
  }

  getDocumentFields(id) {
    return promiseFromCallback(cb => super.getDocumentFields(id, cb));
  }
}


module.exports = WebMergePromiseAPI;

@@ -235,16 +235,108 @@
  %7D);%0A%7D%0A%0A
+%0Afunction promisify(fn, ...args) %7B%0A  return promiseFromCallback(cb =%3E fn(...args, cb));%0A%7D%0A%0A%0A
 class We
@@ -376,27 +376,29 @@
 API %7B%0A  
+mer
 ge
-t
 Document
 s(opts) 
@@ -389,21 +389,23 @@
 Document
-s(opt
+(...arg
 s) %7B%0A   
@@ -422,56 +422,212 @@
 omis
-eFromCallback(cb =%3E super.getDocuments(opts, cb)
+ify(super.mergeDocument, ...args);%0A  %7D%0A%0A  createDocument(...args) %7B%0A    return promisify(super.createDocument, ...args);%0A  %7D%0A%0A  updateDocument(...args) %7B%0A    return promisify(super.updateDocument, ...args
 );%0A 
@@ -643,19 +643,25 @@
 Document
-(id
+s(...args
 ) %7B%0A    
@@ -673,36 +673,101 @@
 n promis
-eFromCallback(cb =%3E 
+ify(super.getDocuments, ...args);%0A  %7D%0A%0A  getDocument(...args) %7B%0A    return promisify(
 super.ge
@@ -775,24 +775,25 @@
 Document
-(id, cb)
+, ...args
 );%0A  %7D%0A%0A
@@ -812,18 +812,23 @@
 tFields(
-id
+...args
 ) %7B%0A    
@@ -840,36 +840,20 @@
 n promis
-eFromCallback(cb =%3E 
+ify(
 super.ge
@@ -871,16 +871,17 @@
 elds
-(id, cb)
+, ...args
 );%0A 

Refactor Promise API.