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/12 00:58:54 UTC

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

Author: vdichev
Date: Fri Jun 11 22:58:53 2010
New Revision: 953899

URL: http://svn.apache.org/viewvc?rev=953899&view=rev
Log:
Implemented since_id and max_id parameters 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=953899&r1=953898&r2=953899&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 Fri Jun 11 22:58:53 2010
@@ -80,8 +80,7 @@ abstract class TwitterAPI {
     case Req(ApiPath ::> "statuses" ::> "friends_timeline", this.method, GetRequest) => friendsTimeline
     case Req(ApiPath ::> "statuses" ::> "user_timeline", this.method, GetRequest) => userTimeline
     case Req(ApiPath ::> "statuses" ::> "user_timeline" ::> last, this.method, GetRequest) => () => userTimeline(last)
-    case Req(ApiPath ::> "statuses" ::> "home_timeline", this.method, GetRequest) => homeTimeline
-    case Req(ApiPath ::> "statuses" ::> "home_timeline" ::> last, this.method, GetRequest) => () => homeTimeline(last)
+    case Req(ApiPath ::> "statuses" ::> "home_timeline", this.method, GetRequest) => friendsTimeline
     case Req(ApiPath ::> "statuses" ::> "show" ::> last, this.method, GetRequest) => () => showStatus(last)
     case Req(ApiPath ::> "statuses" ::> "update", this.method, PostRequest) => update
 
@@ -195,7 +194,10 @@ abstract class TwitterAPI {
       By(Message.author, user),
       By(Message.pool, Empty),
       MaxRows(getCount),
-      OrderBy(Message.id, Descending)) ++ getStart[Message]
+      OrderBy(Message.id, Descending)) ++
+      getStart[Message] ++
+      getSinceId(Message.id) ++
+      getMaxId(Message.id)
     val statusList = Message.findAll(queryParams: _*).map(msgData _)
     Right(Map("statuses" -> ("status", statusList) ))
   }
@@ -208,31 +210,14 @@ abstract class TwitterAPI {
     calcUser map (userTimeline)
   }
   
-  def homeTimeline(user: User): TwitterResponse = {
-    val since_id: String = S.param("since_id") openOr "1"
-   
-   /*     val statusList = 
-      Mailbox.mostRecentMessagesFor(user.id, count.toInt);*/
-    val statusList =
-        for ((msg, why, _) <- Mailbox.mostRecentMessagesFor(user.id, getCount))
-          yield { msgData(msg) }
-      Right(Map("statuses" -> ("status", statusList) ))
-  }
-        
-  
-  def homeTimeline(userName: String): Box[TwitterResponse] = {
-    User.findFromWeb(userName).map(homeTimeline) ?~ S.?("base_twitter_api_err_user_not_found")
-  }
-  
-  def homeTimeline(): Box[TwitterResponse] = {
-    calcUser map (homeTimeline)
-  }
-  
   def replies(user: User): TwitterResponse = {
     val queryParams = List[QueryParam[Message]](
       In(Message.replyTo, Message.id, By(Message.author, user)),
       MaxRows(getCount),
-      OrderBy(Message.id, Descending)) ++ getStart[Message]
+      OrderBy(Message.id, Descending)) ++
+      getStart[Message] ++
+      getSinceId(Message.id) ++
+      getMaxId(Message.id)
     val statusList = Message.findAll(queryParams: _*).map(msgData _)
     Right(Map("statuses" -> ("status", statusList) ))
   }
@@ -347,7 +332,10 @@ abstract class TwitterAPI {
         param,
         By(Mailbox.user, user),
         MaxRows(getCount),
-        OrderBy(Mailbox.id, Descending)) ++ getStart[Mailbox]
+        OrderBy(Mailbox.id, Descending)) ++
+        getStart[Mailbox] ++
+        getSinceId(Mailbox.message) ++
+        getMaxId(Mailbox.message)
         
       val msgIds = 
         Mailbox.findMap(queryParams: _*) (m => Full(m.message.is))
@@ -358,6 +346,16 @@ abstract class TwitterAPI {
     }
 
   private def getCount() = S.param("count").map(_.toInt) openOr 20
+
+  private def getSinceId[T <: Mapper[T]](field: MappedLong[T]) =
+    S.param("since_id").map { since =>
+      By_>(field, since.toLong)
+    }
+
+  private def getMaxId[T <: Mapper[T]](field: MappedLong[T]) =
+    S.param("max_id").map { max =>
+      By_<(field, max.toLong + 1L)
+    }
   
   private def getStart[T <: Mapper[T]]() =
     S.param("page").map { page =>