Skip to content

Instantly share code, notes, and snippets.

@matanox
Forked from guizmaii/GithubHelper.scala
Last active December 29, 2015 23:19
Show Gist options
  • Save matanox/d797877e18df03954e81 to your computer and use it in GitHub Desktop.
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
/*
* 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