Search in sources :

Example 1 with HttpHosts

use of com.twitter.hbc.core.HttpHosts in project ignite by apache.

the class IgniteTwitterStreamerTest method testStatusesFilterEndpointOAuth1.

/**
 * @throws Exception Test exception.
 */
public void testStatusesFilterEndpointOAuth1() throws Exception {
    try (IgniteDataStreamer<Long, String> dataStreamer = grid().dataStreamer(DEFAULT_CACHE_NAME)) {
        TwitterStreamerImpl streamer = newStreamerInstance(dataStreamer);
        Map<String, String> params = new HashMap<>();
        params.put("track", "apache, twitter");
        // @ApacheIgnite id.
        params.put("follow", "3004445758");
        streamer.setApiParams(params);
        streamer.setEndpointUrl(MOCK_TWEET_PATH);
        streamer.setHosts(new HttpHosts("http://localhost:8080"));
        streamer.setThreadsCount(8);
        executeStreamer(streamer);
    }
}
Also used : HttpHosts(com.twitter.hbc.core.HttpHosts) HashMap(java.util.HashMap)

Example 2 with HttpHosts

use of com.twitter.hbc.core.HttpHosts in project ignite by apache.

the class TwitterStreamer method getClient.

/**
 * @param tweetQueue Tweet queue.
 * @return Client.
 */
protected Client getClient(BlockingQueue<String> tweetQueue) {
    StreamingEndpoint endpoint;
    HttpHosts hosts;
    switch(endpointUrl.toLowerCase()) {
        case StatusesFilterEndpoint.PATH:
            endpoint = new StatusesFilterEndpoint();
            hosts = HttpHosts.STREAM_HOST;
            break;
        case StatusesFirehoseEndpoint.PATH:
            endpoint = new StatusesFirehoseEndpoint();
            hosts = HttpHosts.STREAM_HOST;
            break;
        case StatusesSampleEndpoint.PATH:
            endpoint = new StatusesSampleEndpoint();
            hosts = HttpHosts.STREAM_HOST;
            break;
        case UserstreamEndpoint.PATH:
            endpoint = new UserstreamEndpoint();
            hosts = HttpHosts.USERSTREAM_HOST;
            break;
        case SitestreamEndpoint.PATH:
            String follow = apiParams.remove(SITE_USER_ID_KEY);
            List<Long> followers = Lists.newArrayList();
            for (String follower : Splitter.on(',').trimResults().omitEmptyStrings().split(follow)) followers.add(Long.valueOf(follower));
            endpoint = new SitestreamEndpoint(followers);
            hosts = HttpHosts.SITESTREAM_HOST;
            break;
        default:
            endpoint = new DefaultStreamingEndpoint(endpointUrl, HttpConstants.HTTP_GET, false);
            hosts = HttpHosts.STREAM_HOST;
    }
    for (Map.Entry<String, String> entry : apiParams.entrySet()) {
        endpoint.addPostParameter(entry.getKey(), entry.getValue());
    }
    return buildClient(tweetQueue, hosts, endpoint);
}
Also used : HttpHosts(com.twitter.hbc.core.HttpHosts) DefaultStreamingEndpoint(com.twitter.hbc.core.endpoint.DefaultStreamingEndpoint) StreamingEndpoint(com.twitter.hbc.core.endpoint.StreamingEndpoint) SitestreamEndpoint(com.twitter.hbc.core.endpoint.SitestreamEndpoint) DefaultStreamingEndpoint(com.twitter.hbc.core.endpoint.DefaultStreamingEndpoint) UserstreamEndpoint(com.twitter.hbc.core.endpoint.UserstreamEndpoint) StatusesFirehoseEndpoint(com.twitter.hbc.core.endpoint.StatusesFirehoseEndpoint) StatusesSampleEndpoint(com.twitter.hbc.core.endpoint.StatusesSampleEndpoint) Map(java.util.Map) StatusesFilterEndpoint(com.twitter.hbc.core.endpoint.StatusesFilterEndpoint)

Aggregations

HttpHosts (com.twitter.hbc.core.HttpHosts)2 DefaultStreamingEndpoint (com.twitter.hbc.core.endpoint.DefaultStreamingEndpoint)1 SitestreamEndpoint (com.twitter.hbc.core.endpoint.SitestreamEndpoint)1 StatusesFilterEndpoint (com.twitter.hbc.core.endpoint.StatusesFilterEndpoint)1 StatusesFirehoseEndpoint (com.twitter.hbc.core.endpoint.StatusesFirehoseEndpoint)1 StatusesSampleEndpoint (com.twitter.hbc.core.endpoint.StatusesSampleEndpoint)1 StreamingEndpoint (com.twitter.hbc.core.endpoint.StreamingEndpoint)1 UserstreamEndpoint (com.twitter.hbc.core.endpoint.UserstreamEndpoint)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1