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('hosted_source'); | 5 #library('hosted_source'); |
6 | 6 |
7 #import('dart:io'); | |
8 #import('dart:json'); | 7 #import('dart:json'); |
9 #import('dart:uri'); | 8 #import('dart:uri'); |
10 #import('io.dart'); | 9 #import('io.dart'); |
11 #import('package.dart'); | 10 #import('package.dart'); |
12 #import('pubspec.dart'); | 11 #import('pubspec.dart'); |
13 #import('source.dart'); | 12 #import('source.dart'); |
14 #import('source_registry.dart'); | 13 #import('source_registry.dart'); |
15 #import('utils.dart'); | 14 #import('utils.dart'); |
16 #import('version.dart'); | 15 #import('version.dart'); |
17 | 16 |
(...skipping 10 matching lines...) Expand all Loading... |
28 */ | 27 */ |
29 static final defaultUrl = "http://pub.dartlang.org"; | 28 static final defaultUrl = "http://pub.dartlang.org"; |
30 | 29 |
31 /** | 30 /** |
32 * Downloads a list of all versions of a package that are available from the | 31 * Downloads a list of all versions of a package that are available from the |
33 * site. | 32 * site. |
34 */ | 33 */ |
35 Future<List<Version>> getVersions(description) { | 34 Future<List<Version>> getVersions(description) { |
36 var parsed = _parseDescription(description); | 35 var parsed = _parseDescription(description); |
37 var fullUrl = "${parsed.last}/packages/${parsed.first}.json"; | 36 var fullUrl = "${parsed.last}/packages/${parsed.first}.json"; |
38 return consumeInputStream(httpGet(fullUrl)).transform((data) { | 37 |
39 var doc = JSON.parse(new String.fromCharCodes(data)); | 38 return httpGetString(fullUrl).transform((body) { |
| 39 var doc = JSON.parse(body); |
40 return doc['versions'].map((version) => new Version.parse(version)); | 40 return doc['versions'].map((version) => new Version.parse(version)); |
| 41 }).transformException((ex) { |
| 42 if (ex is HttpException && ex.statusCode == 404) { |
| 43 throw 'Could not find package "${parsed.first}" on ${parsed.last}.'; |
| 44 } |
| 45 |
| 46 // Otherwise re-throw the original exception. |
| 47 throw ex; |
41 }); | 48 }); |
42 } | 49 } |
43 | 50 |
44 /** | 51 /** |
45 * Downloads and parses the pubspec for a specific version of a package that | 52 * Downloads and parses the pubspec for a specific version of a package that |
46 * is available from the site. | 53 * is available from the site. |
47 */ | 54 */ |
48 Future<Pubspec> describe(PackageId id) { | 55 Future<Pubspec> describe(PackageId id) { |
49 var parsed = _parseDescription(id.description); | 56 var parsed = _parseDescription(id.description); |
50 var fullUrl = "${parsed.last}/packages/${parsed.first}/versions/" | 57 var fullUrl = "${parsed.last}/packages/${parsed.first}/versions/" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 130 |
124 var name = description["name"]; | 131 var name = description["name"]; |
125 if (name is! String) { | 132 if (name is! String) { |
126 throw new FormatException("The 'name' key must have a string value."); | 133 throw new FormatException("The 'name' key must have a string value."); |
127 } | 134 } |
128 | 135 |
129 var url = description.containsKey("url") ? description["url"] : defaultUrl; | 136 var url = description.containsKey("url") ? description["url"] : defaultUrl; |
130 return new Pair<String, String>(name, url); | 137 return new Pair<String, String>(name, url); |
131 } | 138 } |
132 } | 139 } |
OLD | NEW |