Skip to content

Instantly share code, notes, and snippets.

@brianium
Created August 30, 2012 02:13
Show Gist options
  • Save brianium/3521716 to your computer and use it in GitHub Desktop.
Save brianium/3521716 to your computer and use it in GitHub Desktop.
repo get
def get(fbid: String):Option[FacebookObject] = {
val response = graphFetch(fbid)
response().map(jstr => {
val js = jstr.asJson.asJsObject
val obj = js.convertTo[FacebookObject]
val comments = js.getFields("comments")
if (comments.isEmpty) obj else build(obj, comments.head.asJsObject.convertTo[CommentsJson])
})
}
@tailrec
final def build(obj: FacebookObject, json: CommentsJson): FacebookObject = {
val nextRequest = if (!json.paging.isDefined || !json.paging.get.next.isDefined) None
else graphFetch(json.paging.get.next.get.replaceFirst("http://graph.facebook.com/",""))()
nextRequest match {
case None => obj
case Some(jstr) => {
val result = jstr.asJson.convertTo[CommentsJson]
build(obj.addComments(result.data), result)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment