| 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:json'); | 7 #import('dart:json'); |
| 8 #import('dart:uri'); | 8 #import('dart:uri'); |
| 9 #import('io.dart'); | 9 #import('io.dart'); |
| 10 #import('package.dart'); | 10 #import('package.dart'); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * The URL of the default package repository. | 26 * The URL of the default package repository. |
| 27 */ | 27 */ |
| 28 static final defaultUrl = "http://pub.dartlang.org"; | 28 static final defaultUrl = "http://pub.dartlang.org"; |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * 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 |
| 32 * site. | 32 * site. |
| 33 */ | 33 */ |
| 34 Future<List<Version>> getVersions(description) { | 34 Future<List<Version>> getVersions(String name, description) { |
| 35 var parsed = _parseDescription(description); | 35 var parsed = _parseDescription(description); |
| 36 var fullUrl = "${parsed.last}/packages/${parsed.first}.json"; | 36 var fullUrl = "${parsed.last}/packages/${parsed.first}.json"; |
| 37 | 37 |
| 38 return httpGetString(fullUrl).transform((body) { | 38 return httpGetString(fullUrl).transform((body) { |
| 39 var doc = JSON.parse(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) { | 41 }).transformException((ex) { |
| 42 if (ex is HttpException && ex.statusCode == 404) { | 42 if (ex is HttpException && ex.statusCode == 404) { |
| 43 throw 'Could not find package "${parsed.first}" on ${parsed.last}.'; | 43 throw 'Could not find package "${parsed.first}" on ${parsed.last}.'; |
| 44 } | 44 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 130 |
| 131 var name = description["name"]; | 131 var name = description["name"]; |
| 132 if (name is! String) { | 132 if (name is! String) { |
| 133 throw new FormatException("The 'name' key must have a string value."); | 133 throw new FormatException("The 'name' key must have a string value."); |
| 134 } | 134 } |
| 135 | 135 |
| 136 var url = description.containsKey("url") ? description["url"] : defaultUrl; | 136 var url = description.containsKey("url") ? description["url"] : defaultUrl; |
| 137 return new Pair<String, String>(name, url); | 137 return new Pair<String, String>(name, url); |
| 138 } | 138 } |
| 139 } | 139 } |
| OLD | NEW |