| 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:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io' as io; | 8 import 'dart:io' as io; |
| 9 import 'dart:json' as json; | 9 import 'dart:json' as json; |
| 10 import 'dart:uri'; | 10 import 'dart:uri'; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 import 'utils.dart'; | 21 import 'utils.dart'; |
| 22 import 'version.dart'; | 22 import 'version.dart'; |
| 23 | 23 |
| 24 /// A package source that installs packages from a package hosting site that | 24 /// A package source that installs packages from a package hosting site that |
| 25 /// uses the same API as pub.dartlang.org. | 25 /// uses the same API as pub.dartlang.org. |
| 26 class HostedSource extends Source { | 26 class HostedSource extends Source { |
| 27 final name = "hosted"; | 27 final name = "hosted"; |
| 28 final shouldCache = true; | 28 final shouldCache = true; |
| 29 | 29 |
| 30 /// The URL of the default package repository. | 30 /// The URL of the default package repository. |
| 31 static final defaultUrl = "http://pub.dartlang.org"; | 31 static final defaultUrl = "https://pub.dartlang.org"; |
| 32 | 32 |
| 33 /// Downloads a list of all versions of a package that are available from the | 33 /// Downloads a list of all versions of a package that are available from the |
| 34 /// site. | 34 /// site. |
| 35 Future<List<Version>> getVersions(String name, description) { | 35 Future<List<Version>> getVersions(String name, description) { |
| 36 var parsed = _parseDescription(description); | 36 var parsed = _parseDescription(description); |
| 37 var fullUrl = "${parsed.last}/packages/${parsed.first}.json"; | 37 var fullUrl = "${parsed.last}/packages/${parsed.first}.json"; |
| 38 | 38 |
| 39 return httpClient.read(fullUrl).then((body) { | 39 return httpClient.read(fullUrl).then((body) { |
| 40 var doc = json.parse(body); | 40 var doc = json.parse(body); |
| 41 return doc['versions'] | 41 return doc['versions'] |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 159 |
| 160 var name = description["name"]; | 160 var name = description["name"]; |
| 161 if (name is! String) { | 161 if (name is! String) { |
| 162 throw new FormatException("The 'name' key must have a string value."); | 162 throw new FormatException("The 'name' key must have a string value."); |
| 163 } | 163 } |
| 164 | 164 |
| 165 var url = description.containsKey("url") ? description["url"] : defaultUrl; | 165 var url = description.containsKey("url") ? description["url"] : defaultUrl; |
| 166 return new Pair<String, String>(name, url); | 166 return new Pair<String, String>(name, url); |
| 167 } | 167 } |
| 168 } | 168 } |
| OLD | NEW |