Skip to content

Instantly share code, notes, and snippets.

@guizmaii
Last active February 18, 2017 00:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save guizmaii/11294879 to your computer and use it in GitHub Desktop.
Save guizmaii/11294879 to your computer and use it in GitHub Desktop.
Helper object that help to parse the "Link" header of the Github API v3, in Scala
object GithubHelper {
/**
* Parse the Github Link HTTP header used for pagination
*
* http://developer.github.com/v3/#pagination
*
* Original code found here : https://gist.github.com/niallo/3109252
*
* @param linkHeader
* @return
*/
private def parseLinkHeader(linkHeader: String): Map[String, String] = {
linkHeader.split(',') map { part =>
val section = part.split(';')
val url = section(0).replace("<", "").replace(">", "")
val name = section(1).replace(" rel=\"", "").replace("\"", "")
(name, url)
}.toMap
}
}
@guizmaii
Copy link
Author

Updated to a more functional way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment