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 2009/03/01 01:04:51 UTC

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

Author: vdichev
Date: Sun Mar  1 00:04:51 2009
New Revision: 748940

URL: http://svn.apache.org/viewvc?rev=748940&view=rev
Log:
ESME-44 Twitter API for following / unfollowing users

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=748940&r1=748939&r2=748940&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 Sun Mar  1 00:04:51 2009
@@ -86,8 +86,8 @@
     case Req(l: List[String], this.method, GetRequest) if l == ApiPath ::: "statuses" :: "followers" :: Nil => followers
     case Req(l: List[String], this.method, GetRequest) if l == ApiPath ::: "users" :: "show" :: l.last :: Nil => () => showUser(l last)
 
-    // case Req(l: List[String], this.method, GetRequest) if l == ApiPath ::: "friendships" :: "create" :: Nil => createFriendship(S.param("user"))
-    // case Req(l: List[String], this.method, GetRequest) if l == ApiPath ::: "friendships" :: "destroy" :: Nil => destroyFriendship(S.param("user"))
+    case Req(l: List[String], this.method, PostRequest) if l == ApiPath ::: "friendships" :: "create" :: l.last :: Nil => () => createFriendship(l last)
+    case Req(l: List[String], this.method, PostRequest) if l == ApiPath ::: "friendships" :: "destroy" :: l.last :: Nil => () => destroyFriendship(l last)
     // case Req(l: List[String], this.method, GetRequest) if l == ApiPath ::: "friendships" :: "exists" :: Nil => existsFriendship
 
     case Req(l: List[String], this.method, GetRequest) if l == ApiPath ::: "account" :: "verify_credentials" :: Nil => verifyCredentials
@@ -238,6 +238,28 @@
     yield Right(Map("status" -> msgData(status)))
   }
 
+  def createFriendship(other: String): Box[TwitterResponse] = {
+    for (user <- calcUser;
+         other <- User.findFromWeb(other))
+    yield {
+      if (user follow other)
+        Right(Map("user" -> userData(other)))
+      else
+        Right(Map("hash" -> Map("error" -> "Could not follow user")))
+    }
+  }
+  
+  def destroyFriendship(other: String): Box[TwitterResponse] = {
+    for (user <- calcUser;
+         other <- User.findFromWeb(other))
+    yield {
+      if (user unfollow other)
+        Right(Map("user" -> userData(other)))
+      else
+        Right(Map("hash" -> Map("error" -> "Could not unfollow user")))
+    }
+  }
+  
   private def calcUser(): Box[User] = 
     LiftRules.authentication match {
       case basicAuth: HttpBasicAuthentication =>