Skip to content

Instantly share code, notes, and snippets.

@jeffreyolchovy
Created May 16, 2017 10:52
Show Gist options
  • Save jeffreyolchovy/422819b7e523e2a69440732fb74acce8 to your computer and use it in GitHub Desktop.
Save jeffreyolchovy/422819b7e523e2a69440732fb74acce8 to your computer and use it in GitHub Desktop.
package com.example.sbt
import scala.util.Try
import twitter4j.{Twitter, TwitterFactory}
import twitter4j.conf.ConfigurationBuilder
case class TweeterService(client: Twitter) {
def post(tweet: String): Try[Long] = {
Try(client.updateStatus(tweet)).map(_.getId)
}
}
object TweeterService {
def apply(consumerKey: String, consumerSecret: String, accessToken: String, accessTokenSecret: String): TweeterService = {
val config = (new ConfigurationBuilder)
.setOAuthConsumerKey(consumerKey)
.setOAuthConsumerSecret(consumerSecret)
.setOAuthAccessToken(accessToken)
.setOAuthAccessTokenSecret(accessTokenSecret)
.build()
val client = new TwitterFactory(config).getInstance()
TweeterService(client)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment