public string GetDownloadUrlFor(NuGetPackage pkg) { Debug.Assert(pkg != null); var downloadBarUrl = "https://api.nuget.org/v3-flatcontainer"; var lowerVersion = pkg.Version.ToString().ToLowerInvariant(); var lowerId = pkg.Id.ToLowerInvariant(); // GET {@id}/{LOWER_ID}/{LOWER_VERSION}/{LOWER_ID}.{LOWER_VERSION}.nupkg var url = $"{downloadBarUrl}/{lowerId}/{lowerVersion}/{lowerId}.{lowerVersion}.nupkg"; return(url); }
// TODO: Move these methods somewhere else public static TemplatePack CreateFromNuSpec(NuGetPackage pkg, string pathToNuspecFile, List <string> pathToTemplateJsonFiles) { Debug.Assert(pkg != null); Debug.Assert(File.Exists(pathToNuspecFile)); Debug.Assert(pathToTemplateJsonFiles != null && pathToTemplateJsonFiles.Count > 0); try { var nuspec = NuspecFile.CreateFromNuspecFile(pathToNuspecFile); var templateList = new List <Template>(); foreach (var filepath in pathToTemplateJsonFiles) { Console.WriteLine($"reading template file from {filepath}"); try { var template = CreateTemplateFromJsonFile(filepath); templateList.Add(template); } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw ex; } } // TODO: get download count var templatePack = new TemplatePack { Authors = nuspec.Metadata.Authors, Copyright = nuspec.Metadata.Copyright, Description = nuspec.Metadata.Description, IconUrl = nuspec.Metadata.IconUrl, LicenseUrl = nuspec.Metadata.LicenseUrl, Owners = nuspec.Metadata.Owners, ProjectUrl = nuspec.Metadata.ProjectUrl, Version = nuspec.Metadata.Version, Templates = templateList.ToArray(), DownloadCount = pkg.TotalDownloads }; return(templatePack); } catch (Exception ex) { Console.WriteLine(ex.ToString()); throw ex; } }