Last active
August 29, 2015 14:01
-
-
Save quii/a8165f87656c031cf9d6 to your computer and use it in GitHub Desktop.
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
def index(doi: String) = Action.async { request => | |
// Fake way of checking whether a particular user has access to the content or not (for demo purposes of course!) | |
val fakeAccessCheck = math.random < 0.50 | |
for { | |
timeBody <- getBodyOf("http://localhost:9000/time") | |
fullTextBody <- getFulltextOrAbstract(doi,fakeAccessCheck) | |
downloadsBody <- getBodyOf(s"http://localhost:9000/downloads/${encodeDoi(doi)}") | |
} yield { | |
Ok(views.html.index(timeBody, fullTextBody, downloadsBody)) | |
} | |
} | |
private def getBodyOf(url:String): Future[String] = WS.url(url).get.map(r=> r.body) | |
private def getFulltextOrAbstract(doi: String, hasAccess:Boolean): Future[String] = { | |
val encodedDoi = encodeDoi(doi) | |
val url = if(hasAccess) s"http://localhost:9000/fulltext/$encodedDoi" else s"http://localhost:9000/abstract/$encodedDoi" | |
getBodyOf(url) | |
} | |
private def encodeDoi(doi: String) = java.net.URLEncoder.encode(doi) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment