Skip to content

Commit 1ad4764

Browse files
Steve Marxbraincore
authored andcommitted
Support hosts (e.g. notify) and auth (e.g. noauth)
1 parent 9daa09d commit 1ad4764

14 files changed

+223
-192
lines changed

generator/generate_routes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ def main():
6868
}
6969
subprocess.check_output(
7070
(['python', '-m', 'stone.cli', 'js_types', dropbox_pkg_path] +
71-
specs + ['-b', 'team'] + ['-a', 'host', '-a', 'style'] +
71+
specs + ['-b', 'team'] + ['-a', 'host', '-a', 'style', '-a', 'auth'] +
7272
['--', 'types.js', '-e', json.dumps(upload_arg)]),
7373
cwd=stone_path)
7474

7575
subprocess.check_output(
7676
(['python', '-m', 'stone.cli', 'js_client', dropbox_pkg_path] +
77-
specs + ['-b', 'team'] + ['-a', 'host', '-a', 'style'] +
77+
specs + ['-b', 'team'] + ['-a', 'host', '-a', 'style', '-a', 'auth'] +
7878
['--', 'routes.js', '-c', 'Dropbox']),
7979
# '-e', json.dumps(upload_arg)]),
8080
cwd=stone_path)
@@ -84,7 +84,7 @@ def main():
8484
subprocess.check_output(
8585
(['python', '-m', 'stone.cli', 'js_client', dropbox_pkg_path] +
8686
specs + ['-w', 'team', '-f', 'style!="upload" and style!="download"'] +
87-
['-a', 'host', '-a', 'style'] + ['--', 'routes-team.js', '-c', 'DropboxTeam']),
87+
['-a', 'host', '-a', 'style', '-a', 'auth'] + ['--', 'routes-team.js', '-c', 'DropboxTeam']),
8888
cwd=stone_path)
8989

9090
if __name__ == '__main__':

src/download-request.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
var request = require('superagent');
22
var Promise = require('es6-promise').Promise;
3+
var getBaseURL = require('./get-base-url');
34

45
var buildCustomError;
56
var downloadRequest;
67
var nodeBinaryParser;
7-
var BASE_URL = 'https://content.dropboxapi.com/2/';
88

99
// Register a handler that will instruct superagent how to parse the response
1010
request.parse['application/octect-stream'] = function (obj) {
@@ -29,7 +29,11 @@ nodeBinaryParser = function (res, done) {
2929
});
3030
};
3131

32-
downloadRequest = function (path, args, accessToken, selectUser) {
32+
downloadRequest = function (path, args, auth, host, accessToken, selectUser) {
33+
if (auth !== 'user') {
34+
throw new Error('Unexpected auth type: ' + auth);
35+
}
36+
3337
var promiseFunction = function (resolve, reject) {
3438
var apiRequest;
3539

@@ -62,7 +66,7 @@ downloadRequest = function (path, args, accessToken, selectUser) {
6266
}
6367
}
6468

65-
apiRequest = request.post(BASE_URL + path)
69+
apiRequest = request.post(getBaseURL(host) + path)
6670
.set('Authorization', 'Bearer ' + accessToken)
6771
.set('Dropbox-API-Arg', JSON.stringify(args))
6872
.on('request', function () {

src/dropbox-base.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,23 @@ DropboxBase.prototype.getAuthenticationUrl = function (redirectUri, state) {
8888
return authUrl;
8989
};
9090

91-
DropboxBase.prototype.request = function (path, args, host, style) {
92-
if (style === REQUEST_CONSTANTS.RPC) {
93-
return this.getRpcRequest()(path, args, this.getAccessToken(), this.selectUser);
94-
} else if (style === REQUEST_CONSTANTS.DOWNLOAD) {
95-
return this.getDownloadRequest()(path, args, this.getAccessToken(), this.selectUser);
96-
} else if (style === REQUEST_CONSTANTS.UPLOAD) {
97-
return this.getUploadRequest()(path, args, this.getAccessToken(), this.selectUser);
91+
DropboxBase.prototype.request = function (path, args, auth, host, style) {
92+
var request = null;
93+
switch (style) {
94+
case REQUEST_CONSTANTS.RPC:
95+
request = this.getRpcRequest();
96+
break;
97+
case REQUEST_CONSTANTS.DOWNLOAD:
98+
request = this.getDownloadRequest();
99+
break;
100+
case REQUEST_CONSTANTS.UPLOAD:
101+
request = this.getUploadRequest();
102+
break;
103+
default:
104+
throw new Error('Invalid request style: ' + style);
98105
}
99-
throw new Error('Invalid request type');
106+
107+
return request(path, args, auth, host, this.getAccessToken(), this.selectUser);
100108
};
101109

102110
DropboxBase.prototype.setRpcRequest = function (newRpcRequest) {

src/get-base-url.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function getBaseURL(host) {
2+
return 'https://' + host + '.dropboxapi.com/2/';
3+
}
4+
5+
module.exports = getBaseURL;

0 commit comments

Comments
 (0)