Author: vdichev
Date: Mon Oct 12 20:06:46 2009
New Revision: 824480

URL: http://svn.apache.org/viewvc?rev=824480&view=rev
Log:
TwitterAPI: new retweet methods: retweeted_by_me, retweeted_to_me

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=824480&r1=824479&r2=824480&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 
Mon Oct 12 20:06:46 2009
@@ -59,6 +59,9 @@
 object TwitterAPI {
   val ApiPath = Props.get("twitter.prefix", 
"twitter").split("/").toList.filter(_.length > 0)
   
+  val ByMe = By(Mailbox.resent, true)
+  val ToMe = NotBy(Mailbox.resentBy, Empty)
+  
   def twitterAuth = HttpBasicAuthentication("esme") {
     case (user: String, password: String, _) =>
       !(for(auth <- AuthToken.find(By(AuthToken.uniqueId, password));
@@ -71,7 +74,7 @@
 }
 
 abstract class TwitterAPI {
-  import TwitterAPI.ApiPath
+  import TwitterAPI._
   
   val tf = new java.text.SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy", 
java.util.Locale.US)
   val logger: Logger = Logger.getLogger("org.apache.esme.api")
@@ -96,6 +99,9 @@
     case Req(ApiPath ::> "statuses" ::> "followers" ::> last, this.method, 
GetRequest) => () => followers(last)
     case Req(ApiPath ::> "users" ::> "show" ::> last, this.method, GetRequest) 
=> () => showUser(last)
 
+    case Req(ApiPath ::> "statuses" ::> "retweeted_by_me", this.method, 
GetRequest) => () => retweeted(ByMe)
+    case Req(ApiPath ::> "statuses" ::> "retweeted_to_me", this.method, 
GetRequest) => () => retweeted(ToMe)
+
     case Req(ApiPath ::> "friendships" ::> "create" ::> last, this.method, 
PostRequest) => () => createFriendship(last)
     case Req(ApiPath ::> "friendships" ::> "destroy" ::> last, this.method, 
PostRequest) => () => destroyFriendship(last)
     case Req(ApiPath ::> "friendships" ::> "exists", this.method, GetRequest) 
=> existsFriendship
@@ -319,6 +325,19 @@
     }
   }
   
+  def retweeted(param: QueryParam[Mailbox]): Box[TwitterResponse] =
+    calcUser.map { user =>
+      val msgIds = 
+        Mailbox.findMap(param,
+                        By(Mailbox.user, user),
+                        MaxRows(20),
+                        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 calcUser(): Box[User] = {
     val userBox =
       LiftRules.authentication match {


Reply via email to