/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.twitter;
import twitter4j.Twitter;
import twitter4j.TwitterFactory;
import twitter4j.TwitterStream;
import twitter4j.TwitterStreamFactory;
import twitter4j.conf.Configuration;
import twitter4j.conf.ConfigurationBuilder;
public class TwitterConfiguration {
private String consumerKey;
private String consumerSecret;
private String accessToken;
private String accessTokenSecret;
private String user;
private String keywords;
private int delay = 60;
private String type;
private String locations;
private String userIds;
private boolean filterOld = true;
private Twitter twitter;
private TwitterStream twitterStream;
public void checkComplete() {
if (twitter == null && twitterStream == null
&& (consumerKey.isEmpty() || consumerSecret.isEmpty() || accessToken.isEmpty() || accessTokenSecret.isEmpty())) {
throw new IllegalArgumentException("twitter or twitterStream or all of consumerKey, consumerSecret, accessToken, and accessTokenSecret must be set!");
}
}
public Configuration getConfiguration() {
ConfigurationBuilder confBuilder = new ConfigurationBuilder();
confBuilder.setOAuthConsumerKey(consumerKey);
confBuilder.setOAuthConsumerSecret(consumerSecret);
confBuilder.setOAuthAccessToken(accessToken);
confBuilder.setOAuthAccessTokenSecret(accessTokenSecret);
return confBuilder.build();
}
public String getConsumerKey() {
return consumerKey;
}
public void setConsumerKey(String consumerKey) {
this.consumerKey = consumerKey;
}
public String getConsumerSecret() {
return consumerSecret;
}
public void setConsumerSecret(String consumerSecret) {
this.consumerSecret = consumerSecret;
}
public String getAccessToken() {
return accessToken;
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public String getAccessTokenSecret() {
return accessTokenSecret;
}
public void setAccessTokenSecret(String accessTokenSecret) {
this.accessTokenSecret = accessTokenSecret;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getKeywords() {
return keywords;
}
public void setKeywords(String keywords) {
this.keywords = keywords;
}
public int getDelay() {
return delay;
}
public void setDelay(int delay) {
this.delay = delay;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getLocations() {
return locations;
}
public void setLocations(String locations) {
this.locations = locations;
}
public String getUserIds() {
return userIds;
}
public void setUserIds(String userIds) {
this.userIds = userIds;
}
public boolean isFilterOld() {
return filterOld;
}
public void setFilterOld(boolean filterOld) {
this.filterOld = filterOld;
}
public Twitter getTwitter() {
return twitter;
}
public void setTwitter(Twitter twitter) {
this.twitter = twitter;
}
public TwitterStream getTwitterStream() {
return twitterStream;
}
public void setTwitterStream(TwitterStream twitterStream) {
this.twitterStream = twitterStream;
}
public Twitter getTwitterInstance() {
checkComplete();
return getTwitter() != null ? getTwitter() : new TwitterFactory(getConfiguration()).getInstance();
}
public TwitterStream getTwitterStreamInstance() {
checkComplete();
return getTwitterStream() != null ? getTwitterStream() : new TwitterStreamFactory(getConfiguration()).getInstance();
}
}