Replace spring-social-twitter with twitter4j. Removed all spring jars.

Fixed review target directory.
This commit is contained in:
Christian P. MOMON 2017-12-31 16:26:28 +01:00
parent a310feeef2
commit 45413c643f
31 changed files with 82 additions and 29 deletions

View File

@ -16,22 +16,6 @@
<classpathentry kind="lib" path="lib/Logs/log4j-1.2.17.jar"/>
<classpathentry kind="lib" path="lib/Logs/slf4j-api-1.7.5.jar"/>
<classpathentry kind="lib" path="lib/Logs/slf4j-log4j12-1.7.5.jar"/>
<classpathentry kind="lib" path="lib/Spring/aopalliance-1.0.jar"/>
<classpathentry kind="lib" path="lib/Spring/spring-aop-4.1.7.jar"/>
<classpathentry kind="lib" path="lib/Spring/spring-beans-4.1.7.jar"/>
<classpathentry kind="lib" path="lib/Spring/spring-context-4.1.7.jar"/>
<classpathentry kind="lib" path="lib/Spring/spring-context-support-4.1.7.jar"/>
<classpathentry kind="lib" path="lib/Spring/spring-core-4.1.7.jar"/>
<classpathentry kind="lib" path="lib/Spring/spring-expression-4.1.7.jar"/>
<classpathentry kind="lib" path="lib/Spring/spring-security-crypto-3.2.3.jar"/>
<classpathentry kind="lib" path="lib/Spring/spring-social-config-1.1.0.jar"/>
<classpathentry kind="lib" path="lib/Spring/spring-social-core-1.1.0.jar"/>
<classpathentry kind="lib" path="lib/Spring/spring-social-twitter-1.1.0.jar"/>
<classpathentry kind="lib" path="lib/Spring/spring-social-web-1.1.0.jar"/>
<classpathentry kind="lib" path="lib/Spring/spring-test-4.1.7.jar"/>
<classpathentry kind="lib" path="lib/Spring/spring-tx-4.1.7.jar"/>
<classpathentry kind="lib" path="lib/Spring/spring-web-4.0.3.jar"/>
<classpathentry kind="lib" path="lib/Spring/spring-webmvc-4.0.3.jar"/>
<classpathentry kind="lib" path="lib/UnitTesting/hamcrest-core-1.3.jar"/>
<classpathentry kind="lib" path="lib/UnitTesting/junit-4.11.jar"/>
<classpathentry kind="lib" path="lib/commons-cli-1.4.jar"/>
@ -48,8 +32,9 @@
<classpathentry kind="lib" path="lib/scribe-1.3.7.jar"/>
<classpathentry kind="lib" path="lib/quartz-2.2.3.jar" sourcepath="lib/quartz-2.2.3-source.zip"/>
<classpathentry kind="lib" path="lib/devinsy-strings-0.4.4.jar" sourcepath="lib/devinsy-strings-0.4.4-sources.zip"/>
<classpathentry kind="lib" path="lib/jackson-annotations-2.3.2.jar"/>
<classpathentry kind="lib" path="lib/jackson-core-2.3.2.jar"/>
<classpathentry kind="lib" path="lib/jackson-databind-2.3.2.jar"/>
<classpathentry kind="lib" path="lib/twitter4j-async-4.0.4.jar" sourcepath="lib/twitter4j-async-4.0.4-src.zip"/>
<classpathentry kind="lib" path="lib/twitter4j-core-4.0.4.jar" sourcepath="lib/twitter4j-core-4.0.4-src.zip"/>
<classpathentry kind="lib" path="lib/twitter4j-media-support-4.0.4.jar" sourcepath="lib/twitter4j-media-support-4.0.4-src.zip"/>
<classpathentry kind="lib" path="lib/twitter4j-stream-4.0.4.jar" sourcepath="lib/twitter4j-stream-4.0.4-src.zip"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -143,7 +143,7 @@ public class HebdobotCLI
{
logger.info("Bot configuring…");
Hebdobot bot = new Hebdobot(config.getIrcHost(), config.getIrcPort(), config.getIrcName(), config.getIrcChannel(),
config.getReviewFileSuffix());
configFile.getParentFile(), config.getReviewFileSuffix());
bot.getPastebinSettings().setApiKey(config.getPastebinApiKey());
bot.getIdenticaSettings().setApiKey(config.getIdenticaApiKey());

View File

@ -48,9 +48,9 @@ import org.joda.time.format.ISODateTimeFormat;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.social.ApiException;
import fr.devinsy.util.strings.StringsUtils;
import twitter4j.TwitterException;
/**
* The Class Hebdobot.
@ -59,6 +59,7 @@ public class Hebdobot extends PircBot
{
private static final Logger logger = LoggerFactory.getLogger(Hebdobot.class);
private File homeDirectory;
private String host;
private int port;
private String channel;
@ -83,8 +84,10 @@ public class Hebdobot extends PircBot
* @param channel
* the channel
*/
public Hebdobot(final String host, final int port, final String name, final String channel, final String reviewFileSuffix)
public Hebdobot(final String host, final int port, final String name, final String channel, final File homeDirectory,
final String reviewFileSuffix)
{
this.homeDirectory = homeDirectory;
this.host = host;
this.port = port;
this.channel = channel;
@ -110,26 +113,61 @@ public class Hebdobot extends PircBot
this.dispose();
}
/**
* Gets the aliases.
*
* @return the aliases
*/
public UserAliases getAliases()
{
return this.aliases;
}
/**
* Gets the cron settings.
*
* @return the cron settings
*/
public CronSettings getCronSettings()
{
return this.cronSettings;
}
/**
* Gets the home directory.
*
* @return the home directory
*/
public File getHomeDirectory()
{
return this.homeDirectory;
}
/**
* Gets the identica settings.
*
* @return the identica settings
*/
public IdenticaSettings getIdenticaSettings()
{
return this.identicaSettings;
}
/**
* Gets the pastebin settings.
*
* @return the pastebin settings
*/
public PastebinSettings getPastebinSettings()
{
return this.pastebinSettings;
}
/**
* Gets the twitter settings.
*
* @return the twitter settings
*/
public TwitterSettings getTwitterSettings()
{
return this.twitterSettings;
@ -162,10 +200,10 @@ public class Hebdobot extends PircBot
this.twitterSettings.getAccessToken(), this.twitterSettings.getAccessTokenSecret());
twitter.tweet(message);
}
catch (ApiException exception)
catch (TwitterException exception)
{
logger.error("Error in tweet", exception);
sendMessage("Pour information, le tweet de notifiation a échoué : " + exception.getMessage());
sendMessage("(pour information, la notification par Tweet a échoué : " + exception.getErrorMessage() + ")");
}
}
}
@ -304,7 +342,7 @@ public class Hebdobot extends PircBot
logger.info("Write review file.");
try
{
File file = new File(date + "_" + this.reviewFileSuffix);
File file = new File(this.homeDirectory, date + "_" + this.reviewFileSuffix);
FileUtils.writeStringToFile(file, textReview);
sendMessage("% Compte-rendu de la revue : " + file.getName());
}
@ -564,4 +602,15 @@ public class Hebdobot extends PircBot
logger.debug("Send message : {}", message);
this.sendMessage(this.channel, message);
}
/**
* Sets the home directory.
*
* @param homeDirectory
* the new home directory
*/
public void setHomeDirectory(final File homeDirectory)
{
this.homeDirectory = homeDirectory;
}
}

View File

@ -19,13 +19,22 @@
package org.april.hebdobot.twitter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.social.twitter.api.impl.TwitterTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;
/**
* The Class TwitterClient.
*/
public class TwitterClient
{
private static final Logger logger = LoggerFactory.getLogger(TwitterClient.class);
private String consumerKey;
private String consumerSecret;
private String accessToken;
@ -75,10 +84,20 @@ public class TwitterClient
*
* @param message
* the message
* @throws TwitterException
*/
public void tweet(final String message)
public void tweet(final String message) throws TwitterException
{
TwitterTemplate twitterClient = new TwitterTemplate(this.consumerKey, this.consumerSecret, this.accessToken, this.accessTokenSecret);
twitterClient.timelineOperations().updateStatus(message);
ConfigurationBuilder config = new ConfigurationBuilder();
config.setDebugEnabled(true);
config.setOAuthConsumerKey(this.consumerKey);
config.setOAuthConsumerSecret(this.consumerSecret);
config.setOAuthAccessToken(this.accessToken);
config.setOAuthAccessTokenSecret(this.accessTokenSecret);
Twitter twitter = new TwitterFactory(config.build()).getInstance();
Status status = twitter.updateStatus(message);
logger.info("Tweet result [" + status.getText() + "].");
}
}