Created
May 16, 2017 10:52
-
-
Save jeffreyolchovy/422819b7e523e2a69440732fb74acce8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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