OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library command_uploader; | 5 library command_uploader; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:args/args.dart'; | 10 import 'package:args/args.dart'; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 } | 56 } |
57 | 57 |
58 return new Future.sync(() { | 58 return new Future.sync(() { |
59 var package = commandOptions['package']; | 59 var package = commandOptions['package']; |
60 if (package != null) return package; | 60 if (package != null) return package; |
61 return new Entrypoint(path.current, cache).root.name; | 61 return new Entrypoint(path.current, cache).root.name; |
62 }).then((package) { | 62 }).then((package) { |
63 var uploader = commandOptions.rest[0]; | 63 var uploader = commandOptions.rest[0]; |
64 return oauth2.withClient(cache, (client) { | 64 return oauth2.withClient(cache, (client) { |
65 if (command == 'add') { | 65 if (command == 'add') { |
66 var url = server.resolve("/packages/${Uri.encodeComponent(package)}" | 66 var url = server.resolve("/api/packages/" |
67 "/uploaders.json"); | 67 "${Uri.encodeComponent(package)}/uploaders"); |
68 return client.post(url, fields: {"email": uploader}); | 68 return client.post(url, |
| 69 headers: PUB_API_HEADERS, |
| 70 fields: {"email": uploader}); |
69 } else { // command == 'remove' | 71 } else { // command == 'remove' |
70 var url = server.resolve("/packages/${Uri.encodeComponent(package)}" | 72 var url = server.resolve("/api/packages/" |
71 "/uploaders/${Uri.encodeComponent(uploader)}.json"); | 73 "${Uri.encodeComponent(package)}/uploaders/" |
72 return client.delete(url); | 74 "${Uri.encodeComponent(uploader)}"); |
| 75 return client.delete(url, headers: PUB_API_HEADERS); |
73 } | 76 } |
74 }); | 77 }); |
75 }).then(handleJsonSuccess) | 78 }).then(handleJsonSuccess) |
76 .catchError((error) => handleJsonError(error.response), | 79 .catchError((error) => handleJsonError(error.response), |
77 test: (e) => e is PubHttpException); | 80 test: (e) => e is PubHttpException); |
78 } | 81 } |
79 } | 82 } |
OLD | NEW |