code_corps v0.0.1 CodeCorps.GitHub.API.Pagination View Source
Used to parse and build pagination data when fetching multiple pages from the GitHub API
Link to this section Summary
Link to this section Functions
Adds a page query parameter to an options Keyword list.
For HTTPPoison, query parameters go under the params key of the options
argument, so this function also ensures the params key is present.
retrieve_total_pages(list()) :: integer()
Parses a collection of response headers and determines the record page count for a GitHub endpoint.
The response the headers are retrieved from is usually generated using a
:head request.
The value of a “Link” header is used to determine the page count.
If the “Link” header is not present in the collection, the count is assumed 1
If the “Link” header is present, we use regex to parse the pagination info from its value.
The format of the header is as follows:
{"Link", '<https://api.github.com/search/code?q=addClass+user%3Amozilla&page=15>; rel="next",
<https://api.github.com/search/code?q=addClass+user%3Amozilla&page=34>; rel="last",
<https://api.github.com/search/code?q=addClass+user%3Amozilla&page=1>; rel="first",
<https://api.github.com/search/code?q=addClass+user%3Amozilla&page=13>; rel="prev"'
The page count is determind by locating the rel="last" url and extracting
the page query parameter from it.
From the specified page count, generates a list of integers, 1..count