org.springframework.social.twitter.api.impl.TwitterTemplate Java Examples

The following examples show how to use org.springframework.social.twitter.api.impl.TwitterTemplate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TwitterstreamSourceConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Bean
public MessageProducer twitterStream(TwitterTemplate twitterTemplate) {
	TwitterStreamMessageProducer messageProducer =
			new TwitterStreamMessageProducer(twitterTemplate, twitterStreamProperties);
	messageProducer.setOutputChannel(source.output());
	return messageProducer;
}
 
Example #2
Source File: TwitterSourceIntegrationTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Bean
public TwitterTemplate twitterTemplate() {
	TwitterTemplate mockTemplate = mock(TwitterTemplate.class);
	RestTemplate restTemplate = mock(RestTemplate.class);
	final ClientHttpResponse response = mock(ClientHttpResponse.class);
	ByteArrayInputStream bais = new ByteArrayInputStream("foo".getBytes());
	try {
		when(response.getBody()).thenReturn(bais);
	}
	catch (IOException e) {
	}
	doAnswer(new Answer<Void>() {

		@Override
		public Void answer(InvocationOnMock invocation) throws Throwable {
			uri().set(invocation.getArgumentAt(0, URI.class));
			ResponseExtractor<?> extractor = invocation.getArgumentAt(3, ResponseExtractor.class);
			extractor.extractData(response);
			return null;
		}

	}).when(restTemplate).execute(any(URI.class), any(HttpMethod.class), any(RequestCallback.class),
			any(ResponseExtractor.class));
	when(mockTemplate.getRestTemplate()).thenReturn(restTemplate);
	return mockTemplate;
}
 
Example #3
Source File: TwitterTestConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Bean
@ConditionalOnClass(TwitterTemplate.class)
public TwitterTemplate twitterTemplate() {
	TwitterTemplate mockTemplate = mock(TwitterTemplate.class);
	RestTemplate restTemplate = mock(RestTemplate.class);
	final ClientHttpResponse response = mock(ClientHttpResponse.class);
	ByteArrayInputStream bais = new ByteArrayInputStream("foo".getBytes());
	try {
		when(response.getBody()).thenReturn(bais);
	}
	catch (IOException e) {
	}
	doAnswer(new Answer<Void>() {

		@Override
		public Void answer(InvocationOnMock invocation) throws Throwable {
			ResponseExtractor<?> extractor = invocation.getArgumentAt(3, ResponseExtractor.class);
			extractor.extractData(response);
			return null;
		}

	}).when(restTemplate).execute(any(URI.class), any(HttpMethod.class), any(RequestCallback.class),
			any(ResponseExtractor.class));
	when(mockTemplate.getRestTemplate()).thenReturn(restTemplate);
	return mockTemplate;
}
 
Example #4
Source File: SocialZwitscherConfiguration.java    From cloud-native-zwitscher with MIT License 4 votes vote down vote up
@Bean
public Twitter twitter(final @Value("${spring.social.twitter.appId}") String appId,
                       final @Value("${spring.social.twitter.appSecret}") String appSecret) {
    return new TwitterTemplate(appId, appSecret);
}
 
Example #5
Source File: SearchController.java    From spring-twitter-stream with MIT License 4 votes vote down vote up
public SearchController(TwitterTemplate twitterTemplate) {
    this.twitterTemplate=twitterTemplate;
}
 
Example #6
Source File: TwitterConfig.java    From spring-twitter-stream with MIT License 4 votes vote down vote up
@Bean
TwitterTemplate getTwtTemplate(){
    return new TwitterTemplate(consumerKey, consumerSecret, accessToken, accessTokenSecret);
}
 
Example #7
Source File: AbstractTwitterInboundChannelAdapter.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
protected AbstractTwitterInboundChannelAdapter(TwitterTemplate twitter) {
	this.twitter = twitter;
	// Fix to get round TwitterErrorHandler not handling 401s etc.
	this.twitter.getRestTemplate().setErrorHandler(new DefaultResponseErrorHandler());
	this.setPhase(Integer.MAX_VALUE);
}
 
Example #8
Source File: TwitterstreamSourceConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public TwitterTemplate twitterTemplate() {
	return new TwitterTemplate(credentials.getConsumerKey(), credentials.getConsumerSecret(),
			credentials.getAccessToken(), credentials.getAccessTokenSecret());
}
 
Example #9
Source File: TwitterStreamMessageProducer.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
TwitterStreamMessageProducer(TwitterTemplate twitterTemplate, TwitterStreamProperties twitterStreamProperties) {
	super(twitterTemplate);
	this.twitterStreamProperties = twitterStreamProperties;
}