You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@esme.apache.org by vd...@apache.org on 2010/06/03 22:24:33 UTC

svn commit: r951142 - /incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/TwitterAPI.scala

Author: vdichev
Date: Thu Jun  3 20:24:32 2010
New Revision: 951142

URL: http://svn.apache.org/viewvc?rev=951142&view=rev
Log:
Introduced count parameter in Twitter API.

Modified:
    incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/TwitterAPI.scala

Modified: incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/TwitterAPI.scala
URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/TwitterAPI.scala?rev=951142&r1=951141&r2=951142&view=diff
==============================================================================
--- incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/TwitterAPI.scala (original)
+++ incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/TwitterAPI.scala Thu Jun  3 20:24:32 2010
@@ -17,13 +17,6 @@
  * under the License.
  */
 
-/*
- * RestAPI.scala
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
 package org.apache.esme.api
 
 import net.liftweb._
@@ -191,7 +184,7 @@ abstract class TwitterAPI {
   def friendsTimeline(): Box[TwitterResponse] = {
     calcUser map { user => 
       val statusList =
-        for ((msg, why, _) <- Mailbox.mostRecentMessagesFor(user.id, 20))
+        for ((msg, why, _) <- Mailbox.mostRecentMessagesFor(user.id, getCount))
           yield { msgData(msg) }
       Right(Map("statuses" -> ("status", statusList) ))
     }
@@ -201,7 +194,7 @@ abstract class TwitterAPI {
     val statusList = 
       Message.findAll(By(Message.author, user),
                       By(Message.pool, Empty),
-                      MaxRows(20),
+                      MaxRows(getCount),
                       OrderBy(Message.id, Descending)).
         map(msgData _)
     Right(Map("statuses" -> ("status", statusList) ))
@@ -216,8 +209,7 @@ abstract class TwitterAPI {
   }
   
   def homeTimeline(user: User): TwitterResponse = {
-   val count: String = S.param("count") openOr "20"
-   val since_id: String = S.param("since_id") openOr "1"
+    val since_id: String = S.param("since_id") openOr "1"
    
    /*     val statusList = 
       Mailbox.mostRecentMessagesFor(user.id, count.toInt);*/
@@ -225,7 +217,7 @@ abstract class TwitterAPI {
     val statusList = 
       Message.findAll(By(Message.author, user),
                       By(Message.pool, Empty),
-                      MaxRows(count.toInt),
+                      MaxRows(getCount),
                       OrderBy(Message.id, Descending)).
         map(msgData _)
     Right(Map("statuses" -> ("status", statusList) ))
@@ -243,7 +235,7 @@ abstract class TwitterAPI {
   def replies(user: User): TwitterResponse = {
     val statusList = 
       Message.findAll(In(Message.replyTo, Message.id, By(Message.author, user)),
-                      MaxRows(20),
+                      MaxRows(getCount),
                       OrderBy(Message.id, Descending)).
         map(msgData _)
     Right(Map("statuses" -> ("status", statusList) ))
@@ -260,7 +252,7 @@ abstract class TwitterAPI {
   def publicTimeline(): Box[TwitterResponse] = {
     val statusList =
       Message.findAll(OrderBy(Message.id, Descending),
-                      MaxRows(20),
+                      MaxRows(getCount),
                       By(Message.pool, Empty)).
         map(msgData _)
     Full(Right(Map("statuses" -> ("status", statusList) )))
@@ -356,13 +348,15 @@ abstract class TwitterAPI {
       val msgIds = 
         Mailbox.findMap(param,
                         By(Mailbox.user, user),
-                        MaxRows(20),
+                        MaxRows(getCount),
                         OrderBy(Mailbox.id, Descending)) (m => Full(m.message.is))
       val msgMap = Message.findMessages(msgIds)
       val statusList = msgIds.flatMap(msgMap.get).
           map(msgData _)
       Right(Map("statuses" -> ("status", statusList) ))
     }
+
+  private def getCount() = S.param("count").map(_.toInt) openOr 20
   
   private def calcUser(): Box[User] = {
     val userBox =