Return-Path: Delivered-To: apmail-incubator-esme-commits-archive@minotaur.apache.org Received: (qmail 44966 invoked from network); 20 Feb 2009 20:18:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 20 Feb 2009 20:18:26 -0000 Received: (qmail 68605 invoked by uid 500); 20 Feb 2009 20:18:26 -0000 Delivered-To: apmail-incubator-esme-commits-archive@incubator.apache.org Received: (qmail 68589 invoked by uid 500); 20 Feb 2009 20:18:26 -0000 Mailing-List: contact esme-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: esme-dev@incubator.apache.org Delivered-To: mailing list esme-commits@incubator.apache.org Received: (qmail 68578 invoked by uid 99); 20 Feb 2009 20:18:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Feb 2009 12:18:25 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Feb 2009 20:18:23 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id ECB4A238896B; Fri, 20 Feb 2009 20:18:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r746358 - in /incubator/esme/trunk/server/src/main/scala: bootstrap/liftweb/Boot.scala org/apache/esme/api/TwitterAPI.scala Date: Fri, 20 Feb 2009 20:18:01 -0000 To: esme-commits@incubator.apache.org From: vdichev@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090220201801.ECB4A238896B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: vdichev Date: Fri Feb 20 20:18:01 2009 New Revision: 746358 URL: http://svn.apache.org/viewvc?rev=746358&view=rev Log: Use stateful dispatch for Twitter API and get request from S object. Modified: incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala incubator/esme/trunk/server/src/main/scala/org/apache/esme/api/TwitterAPI.scala Modified: incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala URL: http://svn.apache.org/viewvc/incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala?rev=746358&r1=746357&r2=746358&view=diff ============================================================================== --- incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala (original) +++ incubator/esme/trunk/server/src/main/scala/bootstrap/liftweb/Boot.scala Fri Feb 20 20:18:01 2009 @@ -124,8 +124,8 @@ LiftRules.authentication = TwitterAPI.twitterAuth - LiftRules.statelessDispatchTable.append(TwitterXmlAPI.dispatch) - LiftRules.statelessDispatchTable.append(TwitterJsonAPI.dispatch) + LiftRules.dispatch.append(TwitterXmlAPI.dispatch) + LiftRules.dispatch.append(TwitterJsonAPI.dispatch) LiftRules.early.append(makeUtf8) 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=746358&r1=746357&r2=746358&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 Feb 20 20:18:01 2009 @@ -75,12 +75,12 @@ def dispatch: LiftRules.DispatchPF protected def dispatchMethod: PartialFunction[Req, () => Box[TwitterResponse]] = { case Req(ApiPath :: "statuses" :: "public_timeline" :: Nil, this.method, GetRequest) => publicTimeline - case req @ Req(ApiPath :: "statuses" :: "replies" :: Nil, this.method, GetRequest) => () => replies(req) + case Req(ApiPath :: "statuses" :: "replies" :: Nil, this.method, GetRequest) => replies case Req(ApiPath :: "direct_messages" :: Nil, this.method, GetRequest) => directMessages - case req @ Req(ApiPath :: "statuses" :: "friends_timeline" :: Nil, this.method, GetRequest) => () => friendsTimeline(req) - case req @ Req(ApiPath :: "statuses" :: "user_timeline" :: Nil, this.method, GetRequest) => () => userTimeline(req) + case Req(ApiPath :: "statuses" :: "friends_timeline" :: Nil, this.method, GetRequest) => friendsTimeline + case Req(ApiPath :: "statuses" :: "user_timeline" :: Nil, this.method, GetRequest) => userTimeline // case Req(ApiPath :: "statuses" :: "show" :: Nil, this.method, GetRequest) => showStatus - case req @ Req(ApiPath :: "statuses" :: "update" :: Nil, this.method, PostRequest) => () => update(S, req) + case Req(ApiPath :: "statuses" :: "update" :: Nil, this.method, PostRequest) => update // case Req(ApiPath :: "statuses" :: "friends" :: Nil, this.method, GetRequest) => friends // case Req(ApiPath :: "statuses" :: "followers" :: Nil, this.method, GetRequest) => followers @@ -90,7 +90,7 @@ // case Req(ApiPath :: "friendships" :: "destroy" :: Nil, this.method, GetRequest) => destroyFriendship(S.param("user")) // case Req(ApiPath :: "friendships" :: "exists" :: Nil, this.method, GetRequest) => existsFriendship - case req @ Req(ApiPath :: "account" :: "verify_credentials" :: Nil, this.method, GetRequest) => () => verifyCredentials(req) + case Req(ApiPath :: "account" :: "verify_credentials" :: Nil, this.method, GetRequest) => verifyCredentials // case Req(ApiPath :: "account" :: "end_session" :: Nil, this.method, GetRequest) => endSession // case Req(ApiPath :: "account" :: "rate_limit_status" :: Nil, this.method, GetRequest) => rateLimitStatus // case Req(ApiPath :: "update_profile" :: Nil, this.method, GetRequest) => updateProfile @@ -137,12 +137,12 @@ (("user", userAttributes(msgUser))) } - def verifyCredentials(req: Req): Box[TwitterResponse] = { - calcUser(req) map { user => Right(Map("user" -> userData(user))) } + def verifyCredentials(): Box[TwitterResponse] = { + calcUser map { user => Right(Map("user" -> userData(user))) } } - def friendsTimeline(req: Req): Box[TwitterResponse] = { - calcUser(req) map { user => + def friendsTimeline(): Box[TwitterResponse] = { + calcUser map { user => val statusList = for ((msg, why) <- Mailbox.mostRecentMessagesFor(user.id, 20)) yield { msgData(msg) } @@ -150,8 +150,8 @@ } } - def userTimeline(req: Req): Box[TwitterResponse] = { - calcUser(req) map { user => + def userTimeline(): Box[TwitterResponse] = { + calcUser map { user => val statusList = Message.findAll(By(Message.author, user), MaxRows(20), @@ -161,8 +161,8 @@ } } - def replies(req: Req): Box[TwitterResponse] = { - userTimeline(req) + def replies(): Box[TwitterResponse] = { + userTimeline } def directMessages(): Box[TwitterResponse] = { @@ -177,8 +177,9 @@ Full(Right(Map("statuses" -> ("status", statusList) ))) } - def update(params: HasParams, req: Req): Box[TwitterResponse] = { - for (user <- calcUser(req) ?~ "User not found"; + def update(): Box[TwitterResponse] = { + for (req <- S.request; + user <- calcUser ?~ "User not found"; text <- req.param("status") ?~ "Message not included"; msg <- Message.create.author(user.id.is).when(millis). source(req.param("source") openOr "twitterapi"). @@ -189,10 +190,13 @@ } } - private def calcUser(req: Req): Box[User] = + private def calcUser(): Box[User] = LiftRules.authentication match { case basicAuth: HttpBasicAuthentication => - basicAuth.credentials(req).flatMap(cred => User.findFromWeb(cred._1)) + for (req <- S.request; + cred <- basicAuth.credentials(req); + user <- User.findFromWeb(cred._1)) + yield user } }