/**
 * The authorization token with which calls to the API are made.
 * @type {String}
 */
let token = '';

const AUTHORIZE_ENDPOINT = 'https://www.dropbox.com/oauth2/authorize';

const getAuthorizationUrl = (clientId) => {
  return AUTHORIZE_ENDPOINT + '?' +
    'response_type=token' +
    'client_id=' + clientId;
};

/**
 * Authorize via OAuth 2.0 for Dropbox API calls.
 *
 * @parameter {string} clientId your app's key
 * @parameter {string} redirectUri the uri where the user should be redirected
 * to, after authorization has completed
 * @return {function} a promise that resolves or fails both with the returned
 * HTTP status code
 */
const authorize = (clientId, redirectUri = '') => {
  return new Promise((resolve, reject) => {
    reject('Not implemented yet, please obtain a token manually by calling ' +
      getAuthorizationUrl(clientId));
  });
};

/**
 * Set the token that is used for all Dropbox API calls to the given value.
 * @param  {string} t The new token value.
 */
const setToken = (t) => {
  if (typeof t !== 'string') {
    throw new Error('invalid argument ' + t + ' (expected: string)');
  }
  token = t;
};

/**
 * Upload the given file to the dropbox.
 * @param  {object} file an object describing the file, consisting of:
 *  - {string} name
 *  - {Buffer} content
 *  - {boolean} replace
 * @param  {string} destinationPath the path in the dropbox where the file should
 * be uploaded to
 * @return {function} a promise that resolves when the upload is complete or
 * fails with an error message
 */
const upload = ({ name, content, replace }, destinationPath) => {
  return new Promise((resolve, reject) => {
    reject('Not implemented yet');
  });
};

module.exports = {
  authorize,
  setToken,
  upload
};

@@ -1,12 +1,50 @@
+const fetch = require('node-fetch');%0A%0A
 /**%0A * The a
@@ -126,16 +126,17 @@
  */%0Alet 
+_
 token = 
@@ -136,24 +136,51 @@
 oken = '';%0A%0A
+const API_VERSION = '2/';%0A%0A
 const AUTHOR
@@ -237,16 +237,83 @@
 horize';
+%0Aconst CONTENT_UPLOAD_ENDPOINT = 'https://content.dropboxapi.com/';
 %0A%0Aconst 
@@ -1142,16 +1142,20 @@
 ken = (t
+oken
 ) =%3E %7B%0A 
@@ -1167,16 +1167,20 @@
 typeof t
+oken
  !== 'st
@@ -1231,16 +1231,20 @@
 nt ' + t
+oken
  + ' (ex
@@ -1268,16 +1268,17 @@
 ;%0A  %7D%0A  
+_
 token = 
@@ -1278,16 +1278,20 @@
 oken = t
+oken
 ;%0A%7D;%0A%0A/*
@@ -1435,14 +1435,14 @@
  - %7B
-Buffer
+string
 %7D co
@@ -1458,23 +1458,19 @@
  - %7B
-boolean%7D replac
+string%7D mod
 e%0A *
@@ -1567,16 +1567,174 @@
 aded to%0A
+ * @param  %7Bstring?%7D token the OAuth 2 token that is used to access your app;%0A * can be omitted (in this case, the token that is set via %60%60setToken%60 is used)%0A
  * @retu
@@ -1874,14 +1874,11 @@
 nt, 
-replac
+mod
 e %7D,
@@ -1897,93 +1897,1032 @@
 Path
-) =%3E %7B%0A  return new Promise((resolve, reject) =%3E %7B%0A    reject('Not implemented yet');
+, token = _token) =%3E %7B%0A  if (typeof name !== 'string') %7B%0A    throw new Error('invalid argument ' + name + ' (expected: string)');%0A  %7D%0A  if (typeof content !== 'string') %7B%0A    throw new Error('invalid argument ' + content + ' (expected: string)');%0A  %7D%0A  if (typeof mode !== 'string') %7B%0A    throw new Error('invalid argument ' + mode + ' (expected: string)');%0A  %7D%0A  if (typeof destinationPath !== 'string') %7B%0A    throw new Error('invalid argument ' + destinationPath + ' (expected: string)');%0A  %7D%0A  if (typeof token !== 'string') %7B%0A    throw new Error('invalid argument ' + token + ' (expected: string)');%0A  %7D%0A%0A  const path = destinationPath + '/' + name;%0A  return fetch(CONTENT_UPLOAD_ENDPOINT + API_VERSION + '/files/upload', %7B%0A    method: 'POST',%0A    headers: %7B%0A      'Content-Type': 'application/octet-stream',%0A      'Authorization': 'Bearer ' + token,%0A      'Dropbox-API-Arg': JSON.stringify(%7B%0A        'path': path,%0A        'mode': mode,%0A        'autorename': true,%0A        'mute': false%0A      %7D)%0A    %7D,%0A    body: content
 %0A  %7D

Implement `upload`