!SLIDE
import dispatch._
!SLIDE
def api = host("api.meetup.com").secure
val key = Map("key" -> "yourapikey")
!SLIDE
def profiles(group: String) = (
api / "2" / "profiles.xml" <<?
key ++ Map("group_urlname" -> group,
"order" -> "interesting") >
as.xml.Elem
)
val profs = Http(profiles("Scala-Berlin-Brandenburg"))
!SLIDE
val ps = profs()
val names = for {
name <- ps \\ "item" \ "name"
} yield name.text
!SLIDE
val bios = for {
item <- ps \\ "item"
} yield {
(item \ "bio").headOption.map {
_.text
}.getOrElse("")
}
!SLIDE
for {
(name, bio) <- names.zip(bios).take(5)
} {
println("%s\n%s\n".format(name,bio))
}
!SLIDE
Moar concurrency
val idsPromise =
for (p <- profs)
yield for (id <- (p \\ "member_id").take(10))
yield id.text
!SLIDE
def groups(memberId: String) = (
api / "2" / "groups.xml" <<?
key ++ Map("member_id" -> memberId) >
as.xml.Elem
)
!SLIDE
val memberGroups = for {
id <- idsPromise.values
gs <- Http(groups(id))
} yield gs \\ "urlname"
!SLIDE
val flattened =
for (members <- memberGroups)
yield for {
member <- members
group <- member
} yield group.text
!SLIDE
flattened().toSet.size