Browse files

TFJ-744 respect includeEntitiesEnabled / includeRTsEnabled params

  • Loading branch information...
1 parent 4ce9be7 commit 45ac5ebadb7675b748c2c7d2277f2f9204979db7 @yusuke committed Dec 23, 2012
View
32 twitter4j-core/src/main/java/twitter4j/TwitterImpl.java
@@ -43,20 +43,34 @@
private final HttpParameter[] IMPLICIT_PARAMS;
private final HttpParameter INCLUDE_MY_RETWEET;
+ private static final Map<Configuration, HttpParameter[]> implicitParamsMap = new HashMap<Configuration, HttpParameter[]>();
+ private static final Map<Configuration, String> implicitParamsStrMap = new HashMap<Configuration, String>();
+
/*package*/
TwitterImpl(Configuration conf, Authorization auth) {
super(conf, auth);
INCLUDE_MY_RETWEET = new HttpParameter("include_my_retweet", conf.isIncludeMyRetweetEnabled());
- if (conf.getContributingTo() != -1L) {
- IMPLICIT_PARAMS_STR = "include_entities=1&include_rts=1&contributingto=" + conf.getContributingTo();
- IMPLICIT_PARAMS = new HttpParameter[]{new HttpParameter("include_entities", "1")
- , new HttpParameter("include_rts", "1")
- , new HttpParameter("contributingto", conf.getContributingTo())};
- } else {
- IMPLICIT_PARAMS_STR = "include_entities=1&include_rts=1";
- IMPLICIT_PARAMS = new HttpParameter[]{new HttpParameter("include_entities", "1")
- , new HttpParameter("include_rts", "1")};
+ HttpParameter[] implicitParams = implicitParamsMap.get(conf);
+ String implicitParamsStr = implicitParamsStrMap.get(conf);
+ if (implicitParams == null) {
+ String includeEntities = conf.isIncludeEntitiesEnabled() ? "1" : "0";
+ String includeRTs = conf.isIncludeRTsEnabled() ? "1" : "0";
+ boolean contributorsEnabled = conf.getContributingTo() != -1L;
+ implicitParamsStr = "include_entities=" + includeEntities + "&include_rts=" + includeRTs
+ + (contributorsEnabled ? "&contributingto=" + conf.getContributingTo() : "");
+ implicitParamsStrMap.put(conf, implicitParamsStr);
+
+ List<HttpParameter> params = new ArrayList<HttpParameter>();
+ params.add(new HttpParameter("include_entities", includeEntities));
+ params.add(new HttpParameter("include_rts", includeRTs));
+ if (contributorsEnabled) {
+ params.add(new HttpParameter("contributingto", conf.getContributingTo()));
+ }
+ implicitParams = params.toArray(new HttpParameter[params.size()]);
+ implicitParamsMap.put(conf, implicitParams);
}
+ IMPLICIT_PARAMS = implicitParams;
+ IMPLICIT_PARAMS_STR = implicitParamsStr;
}
/* Timelines Resources */
View
4 twitter4j-core/src/main/java/twitter4j/conf/Configuration.java
@@ -123,4 +123,8 @@
String getDispatcherImpl();
String getLoggerFactory();
+
+ boolean isIncludeRTsEnabled();
+
+ boolean isIncludeEntitiesEnabled();
}
View
10 twitter4j-core/src/main/java/twitter4j/conf/ConfigurationBase.java
@@ -608,6 +608,16 @@ public String getLoggerFactory() {
return loggerFactory;
}
+ @Override
+ public boolean isIncludeRTsEnabled() {
+ return includeRTsEnabled;
+ }
+
+ @Override
+ public boolean isIncludeEntitiesEnabled() {
+ return includeEntitiesEnabled;
+ }
+
protected final void setLoggerFactory(String loggerImpl) {
this.loggerFactory = loggerImpl;
}

0 comments on commit 45ac5eb

Please sign in to comment.