Skip to content

Commit

Permalink
More scala-ish implementation of Tweet
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelcm committed Aug 22, 2011
1 parent b1d15f0 commit 4adeada
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/main/scala/com/retwis/api/Retwis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ object Retwis {
try {
val jsonTwt = jedis.get("pid:" + id + ":tweet")
if (jsonTwt != null) {
return Tweet.getTweetFromJson(jsonTwt)
return Tweet(jsonTwt)
}
} catch {
case e => e.printStackTrace()
Expand All @@ -241,7 +241,7 @@ object Retwis {
var tweets = new Array[Tweet](tweetIds.length)
var i = 0
for(id<-tweetIds) {
tweets(i) = Tweet.getTweetFromJson(jedis.get("pid:" + id + ":tweet"))
tweets(i) = Tweet(jedis.get("pid:" + id + ":tweet"))
i += 1
}
return tweets
Expand All @@ -266,7 +266,7 @@ object Retwis {
var tweets = new Array[Tweet](tweetIds.length)
var i = 0
for(id<-tweetIds) {
tweets(i) = Tweet.getTweetFromJson(jedis.get("pid:" + id + ":tweet"))
tweets(i) = Tweet(jedis.get("pid:" + id + ":tweet"))
i += 1
}
return tweets
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/com/retwis/model/Tweet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import net.liftweb.json.JsonAST._
import net.liftweb.json.JsonDSL._

object Tweet {
def getTweetFromJson(jsonStr: String):Tweet = {
def apply(jsonStr: String):Tweet = {
implicit val formats = net.liftweb.json.DefaultFormats
val json = parse(jsonStr)
val id = (json \ "tweet" \ "id").extract[String]
Expand All @@ -16,7 +16,7 @@ object Tweet {
}
}

class Tweet(val id: String, val time: Long, val message: String, val authorId: String) {
class Tweet(val id: String, val time: Long, val message: String, val authorId: String) {
/* Serialize tweet to JSON string */
def toJson(): String = {
val json = ("tweet" ->
Expand Down

0 comments on commit 4adeada

Please sign in to comment.