This is a Scala wrapper of Twitter4J.
It provides easy way to use basic functions of Twitter4J in Scala.
Add the following dependencies to build.sbt.
resolvers += "bintray" at "http://dl.bintray.com/shinsuke-abe/maven"
libraryDependencies += "com.github.Shinsuke-Abe" %% "twitter4s" % "2.1.0"
Twitter4S is built in following environments.
- Scala 2.10.3
- sbt 0.13.1
- Twitter4J 3.0.5
Note: Built on latest stable library at January 18,2014.
Twitter4S has no dependencies without Twitter4J.
Twitter4S, there are available two ways of writing that use the DSL (Twitter4S unique features) and compliant Twitter4J way.
DSL is not implemented all of Twiiter4J functions yet. Twitter4S implements frequency used functions only.
import twitter4s._ // You must import for implicit type converion.
val twitter = Twitter()
twitter.setOAuthConsumer(ConsumerKey("consumerKey", "consumerSecret"))
twitter.setOAuthAccessToken(AccessToken("accessToken", "tokenSecret"))
twitter.(API Methods...) (It have one-to-one correspondence between Twitter4S and Twitter4J.)
DSL provides StringContext and some methods.
import twitter4s.dsl._
implicit val consumerKey = ConsumerKey("consumerKey", "consumerSecret")
withToken(AccessToken("accessToken", "tokenSecret") { implicit twitter =>
tweet"test tweet" udpate
}
Please notice that operate for user authorized by AccessToken with withToken argument.
StringContext that implementation is as follows.
user"screen name"
user"id:user id"
list"List Slug"
list"id:List ID"
tweet"Tweet"
message"Content of DM"
// method for Tweet.
tweet"test" update // tweet 'test'
// methods for User.
get(user"USER-A") // Get infomation of USER-A
follow(user"USER-A") // Follow USER-A
unfollow(user"USER-A") // Unfollow USER-A
block(user"USER-A") // Block USER-A
// methods for List.
get(list"LIST-A") // Get infomation of USER-A
add(user"USER-A") to list"LIST-A" // Add USER-A to LIST-A
remove(user"USER-A") from list"LIST-A" // Remove USER-A from LIST-A
// methods for DM.
send(message"TEST") to user"USER-A" // Send DirectMessage 'test' to USER-A.
New functions will be added for new version.
If you want any other DSL, add issue or send mention to @mao_instantlife on Twitter please.