/// <inheritdoc /> /// <exception cref="WebException">Thrown if the operation is unsuccessful.</exception> public override async Task <Package> FetchAsync(string packageId, string version) { if (string.IsNullOrWhiteSpace(packageId)) { throw new ArgumentException("A value of null, empty, or whitespace is not valid.", nameof(packageId)); } if (string.IsNullOrWhiteSpace(version)) { throw new ArgumentException("A value of null, empty, or whitespace is not valid.", nameof(version)); } var(foundNpmPackage, error) = await Client.NpmGetPackageAsync(packageId, version); if (error != null) { if (error.StatusCode == HttpStatusCode.NotFound) { return(null); } throw new WebException(error.ErrorMessage); } var foundPackage = foundNpmPackage.ToPackage(); var(content, downloadError) = await Client.NpmDownloadPackageAsync(foundPackage); if (downloadError != null) { throw new WebException(downloadError.ErrorMessage); } foundPackage.Content = content; return(foundPackage); }
private static async Task <Package> ConvertNpmPackageVersionToPackageAsync(NpmClient client, NpmPackageAllVersions npmPackageAllVersions) { var(npmPackage, error) = await client.NpmGetPackageAsync(GetNpmName(npmPackageAllVersions.Package_Name, npmPackageAllVersions.Scope_Name), npmPackageAllVersions.Version_Text); if (error != null) { throw new WebException(error.ErrorMessage); } var match = Regex.Match(npmPackage.Id, prereleaseRegEx); var prerelease = match.Groups["Prerelease"].Value.Any(); var package = new Package { Id = ConvertNpmPackageNameToId(npmPackageAllVersions), Version = npmPackageAllVersions.Version_Text, PackageDownloadUrl = npmPackage.Dist[NpmPackage.ArchiveKey], PackageHash = npmPackage.Dist[NpmPackage.HashKey], IsPrerelease = prerelease }; return(package); }