Skip to content

Commit

Permalink
Read all pages of a package's results. Fixes praeclarum#95
Browse files Browse the repository at this point in the history
When the NuGet API returns package versions as part of the response, the
code only read the versions from the last page. It now reads the
versions from all pages, whether they're returned inline or referenced
via a secondary URL.
  • Loading branch information
bgrainger committed Feb 15, 2020
1 parent 192f296 commit 000e245
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions Data/PackageVersions.cs
Expand Up @@ -97,19 +97,16 @@ private static async Task ReadVersionsFromUrl (HttpClient httpClient, PackageVer
// Console.WriteLine(rootJson + "\n\n\n\n");
var root = JObject.Parse (rootJson);
var pages = (JArray)root["items"];
if (pages.Count > 0) {
var lastPage = pages.Last ();
var lastPageItems = lastPage["items"] as JArray;
if (lastPageItems != null) {
package.Read (lastPageItems);
foreach (var p in pages) {
var pageItems = p["items"] as JArray;
if (pageItems != null) {
package.Read (pageItems);
}
else {
foreach (var p in pages.Reverse ()) {
var pageUrl = p["@id"].ToString ();
var pageRootJson = await httpClient.GetStringAsync (pageUrl).ConfigureAwait (false);
var pageRoot = JObject.Parse (pageRootJson);
package.Read ((JArray)pageRoot["items"]);
}
var pageUrl = p["@id"].ToString ();
var pageRootJson = await httpClient.GetStringAsync (pageUrl).ConfigureAwait (false);
var pageRoot = JObject.Parse (pageRootJson);
package.Read ((JArray)pageRoot["items"]);
}
}
}
Expand Down

1 comment on commit 000e245

@loic-sharma
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me 👍

Please sign in to comment.