incubator-esme-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vdic...@apache.org
Subject svn commit: r747937 - /incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/TwitterAPI.scala
Date Wed, 25 Feb 2009 21:58:47 GMT
Author: vdichev
Date: Wed Feb 25 21:58:47 2009
New Revision: 747937

URL: http://svn.apache.org/viewvc?rev=747937&view=rev
Log:
ESME-33 Extended user information via 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=747937&r1=747936&r2=747937&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 Wed Feb
25 21:58:47 2009
@@ -84,7 +84,7 @@
 
     case Req(l: List[String], this.method, GetRequest) if l == ApiPath ::: "statuses" ::
"friends" :: Nil => friends
     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" :: Nil => showUser
+    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"))
@@ -123,6 +123,27 @@
     )
   }
   
+  def extendedAttributes(user: User) = {
+    Map(
+      "profile_background_color" -> None,
+      "profile_text_color" -> None,
+      "profile_link_color" -> None,
+      "profile_sidebar_fill_color" -> None,
+      "profile_sidebar_border_color" -> None,
+      "friends_count" -> user.following.size,
+      "created_at" -> None,
+      "favourites_count" -> 0,
+      "utc_offset" -> 0,
+      "time_zone" -> user.timezone,
+      "profile_background_image_url" -> None,
+      "profile_background_tile" -> false,
+      "following" -> calcUser.map(_.following_?(user)).getOrElse(false),
+      "notifications" -> false,
+      "statuses_count " -> Message.count(By(Message.author, user))
+    )
+  }
+  
+  
   def userData(user: User) = {
     val lastMsg = Message.findAll(By(Message.author, user),
                                   OrderBy(Message.id, Descending),
@@ -131,6 +152,9 @@
       (("status", lastMsg.map(msgAttributes _).firstOption.getOrElse("")))
   }
   
+  def extendedUserData(user: User) =
+    userData(user) ++ extendedAttributes(user)
+  
   def msgData(msg: Message) = {
     val msgUser = User.find(msg.author).get
     msgAttributes(msg) +
@@ -204,6 +228,10 @@
     }
   }
   
+  def showUser(name: String): Box[TwitterResponse] = {
+    for (user <- User.findFromWeb(name) ?~ "User not found")
+    yield Right(Map("user" -> extendedUserData(user)))
+  }
 
   private def calcUser(): Box[User] = 
     LiftRules.authentication match {



Mime
View raw message