getPackageVersions method
Retrieves the all versions of the packageId
.
Note: This list contains both listed and unlisted package versions.
Throws a PackageNotFoundException if the server returns a 404 status code.
Throws a NuGetServerException if the server returns a non-200 status code.
Implementation
Future<List<String>> getPackageVersions(String packageId) async {
final id = packageId.toLowerCase();
final uri = resourceUri
.replace(pathSegments: [...resourceUri.pathSegments, id, 'index.json']);
final response = await httpClient.get(uri);
return switch (response.statusCode) {
404 => throw PackageNotFoundException(packageId),
200 => (json.decode(response.body)['versions'] as List<dynamic>)
.cast<String>(),
_ => throw NuGetServerException('Failed to get package versions: '
'${response.statusCode} ${response.reasonPhrase}'),
};
}