-
-
Save matanox/d797877e18df03954e81 to your computer and use it in GitHub Desktop.
Helper object parsing the "Link" header of the Github API v3, in Scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* parses the link header field (http://tools.ietf.org/html/rfc5988) returned by Github's api | |
* (c.f. https://developer.github.com/guides/traversing-with-pagination/) | |
*/ | |
trait GithubLinkHeader { | |
def parse(linkHeader: IndexedSeq[String]): Map[String, String] = { | |
assert(linkHeader.size == 1) | |
linkHeader.head.split(',').map { linkEntry => | |
val entryPart = linkEntry.split(';') | |
assert(entryPart.size == 2) | |
val rel = entryPart(1).replace(" rel=\"", "").replace("\"", "") | |
val url = entryPart(0).replace("<", "").replace(">", "") | |
(rel, url) | |
}.toMap | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment