Created
January 6, 2017 13:35
-
-
Save arnobroekhof/12f079c0aac65d3f2a130436bb83e3d4 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 TwitterClient | |
import com.twitter.hbc.ClientBuilder; | |
import com.twitter.hbc.core.Client; | |
import com.twitter.hbc.core.Constants; | |
import com.twitter.hbc.core.Hosts; | |
import com.twitter.hbc.core.HttpHosts; | |
import com.twitter.hbc.core.endpoint.StatusesFilterEndpoint; | |
import com.twitter.hbc.core.processor.StringDelimitedProcessor; | |
import com.twitter.hbc.httpclient.auth.Authentication; | |
import com.twitter.hbc.httpclient.auth.OAuth1; | |
import java.util.Arrays; | |
/** | |
* wrapper that configures and manages the hbc twitter {@Link Client}. | |
*/ | |
public class TwitterClient { | |
private final Client client; | |
public TwitterClient( | |
final String appName, | |
final String consumerKey, | |
final String consumerSecret, | |
final String twitterToken, | |
final String twitterSecret, | |
final String[] terms) { | |
Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST); | |
Authentication hosebirdAuth = new OAuth1(consumerKey, consumerSecret, token, secret); | |
StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint(); | |
hosebirdEndpoint.trackTerms(Arrays.asList(terms)); | |
ClientBuilder clientBuilder = new ClientBuilder().name(appName).hosts(hosebirdHosts).authentication | |
(hosebirdAuth).endpoint(hosebirdEndpoint); | |
client = clientBuilder.processor(new StringDelimitedProcessor(queueWrapper.getQueue())).build(); | |
} | |
public void readTweets() { | |
client.connect(); | |
} | |
public void cleanUp() { | |
client.stop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment