Skip to content

Instantly share code, notes, and snippets.

@arnobroekhof
Created January 6, 2017 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnobroekhof/12f079c0aac65d3f2a130436bb83e3d4 to your computer and use it in GitHub Desktop.
Save arnobroekhof/12f079c0aac65d3f2a130436bb83e3d4 to your computer and use it in GitHub Desktop.
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