Created
August 30, 2012 02:13
-
-
Save brianium/3521716 to your computer and use it in GitHub Desktop.
repo get
This file contains hidden or 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 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