Skip to content

Instantly share code, notes, and snippets.

@seanparsons
Created July 11, 2014 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanparsons/b0f5347d61e76307e26f to your computer and use it in GitHub Desktop.
Save seanparsons/b0f5347d61e76307e26f to your computer and use it in GitHub Desktop.
path("metric" / Segment) { location =>
val _uri = "http://<url>/api/crowd_api/metric?mode=Select&location=" + location
val _result = scala.io.Source.fromURL(_uri).mkString
val _xml = XML.loadString(_result)
val _crowd = _xml \\ "crowd"
case class Crowd(c_location: String, c_metric: String)
implicit def CrowdCodecJson: CodecJson[Crowd] = casecodec2(Crowd.apply, Crowd.unapply)("c_location", "c_metric")
val crowd_ = _crowd.map{ n =>
val location = (n \ "location").text
val crowd_metric = (n \ "crowd_metric").text
("metric" := crowd_metric) ->: ("location" := location) ->: jEmptyObject
}.toList.asJson
val cm_output = crowd_
get { ctx => ctx.complete(cm_output) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment