davidchambers/tutor

The languages parser should handle pagination

nicknovitski opened this issue · 1 comments

cf: http://gatherer.wizards.com/Pages/Card/Languages.aspx?multiverseid=289327

It's a bit annoying, since the vast majority of cards will only have one page, but to keep the responses consistent, they should all have a page property, with the collection held in a languages property or something like that.

I'd appreciate a review of these changes, @nicknovitski. Now that we make multiple HTTP requests each time tutor.card is called, and since the performance cost is negligible, we needn't paginate. Instead, we request the first page, which tells us how many pages there are in total, then request the remaining pages in parallel. There are now several functions involved in retrieving and transforming the data:

  • fetch provides a callback with the specified page's content
  • extract takes a page's content and returns a [code, name, id] triplet
  • merge takes an array of [code, name, id] triplets and merges them into a single object