Skip to content
Browse files

Basic API complete. Now feature compatible with the original liftweb …

…version.
  • Loading branch information...
1 parent bd2a67d commit 6c2b4316b9c8ea3d5a37213933db85079dafc576 @tackley committed
Showing with 30 additions and 3 deletions.
  1. +2 −0 .gitignore
  2. +1 −1 Procfile
  3. +22 −0 app/controllers/Api.scala
  4. +2 −0 app/lib/Backend.scala
  5. +2 −0 conf/routes
  6. +1 −2 readme.md
View
2 .gitignore
@@ -3,3 +3,5 @@ target/
.idea*/
logs/
+dist/
+
View
2 Procfile
@@ -1,4 +1,4 @@
-webapp: ./sbt run
+webapp: ./sbt start
listenerguweb01: ./start_pub.sh guweb01
listenerguweb51: ./start_pub.sh guweb51
View
22 app/controllers/Api.scala
@@ -2,7 +2,29 @@ package controllers
import play.api._
import play.api.mvc._
+import net.liftweb.json._
+import lib.Backend
object Api extends Controller {
+ implicit val formats = Serialization.formats(NoTypeHints)
+
+
+ def withCallback(callback: Option[String])(block: => String) = {
+ Ok(callback map { _ + "(" + block + ")" } getOrElse block)
+ }
+
+ def counts(callback: Option[String]) = Action {
+ withCallback(callback) {
+ val response = Backend.currentHits
+ .map{ hit => hit.fullUrl -> tidy("%.1f".format(hit.hitsPerSec)) }.toMap
+
+ Serialization.write(response)
+ }
+ }
+
+ private def tidy(s: String) = s match {
+ case "0.0" => "trace"
+ case other => other
+ }
}
View
2 app/lib/Backend.scala
@@ -32,4 +32,6 @@ object Backend {
def currentStats = (calculator ? GetStats()).as[(List[HitReport], ListsOfStuff)]
def currentLists = currentStats.map(_._2)
+
+ def currentHits = currentStats.map(_._1).get
}
View
2 conf/routes
@@ -12,5 +12,7 @@ GET /top20chart controllers.Application.top20chart()
GET /details controllers.Application.details()
+GET /api/counts controllers.Api.counts(callback: Option[String])
+
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
View
3 readme.md
@@ -36,8 +36,7 @@ Then startup with:
foreman start
-Now go to http://localhost:8080 and enjoy. (Note I do development on port 8081, so depending on how I checked stuff in
-you might need to go to that port instead.)
+Now go to http://localhost:5000 and enjoy.

0 comments on commit 6c2b431

Please sign in to comment.
Something went wrong with that request. Please try again.