Switched to OkHttp.
This commit is contained in:
parent
73dbd6c0d8
commit
06789a80a1
3 changed files with 16 additions and 17 deletions
|
@ -53,18 +53,18 @@ dependencies {
|
|||
|
||||
compile 'pircbot:pircbot:1.5.0'
|
||||
|
||||
compile 'commons-codec:commons-codec:1.10'
|
||||
//compile 'commons-codec:commons-codec:1.10'
|
||||
compile 'commons-logging:commons-logging:1.2'
|
||||
compile 'commons-net:commons-net:3.6'
|
||||
compile 'commons-cli:commons-cli:1.4'
|
||||
compile 'commons-httpclient:commons-httpclient:3.1'
|
||||
compile 'com.squareup.okhttp3:okhttp:3.8.0'
|
||||
|
||||
compile 'oro:oro:2.0.8'
|
||||
|
||||
compile 'org.jsoup:jsoup:1.10.2'
|
||||
compile 'com.rometools:rome:1.7.1'
|
||||
compile 'com.rometools:rome:1.7.3'
|
||||
compile 'org.slf4j:slf4j-log4j12:1.7.25'
|
||||
compile 'org.json:json:20160810'
|
||||
compile 'org.json:json:20170516'
|
||||
compile 'org.ostermiller:utils:1.07.00'
|
||||
|
||||
compile 'net.objecthunter:exp4j:0.4.8'
|
||||
|
|
|
@ -56,18 +56,18 @@ val p = project {
|
|||
|
||||
compile("pircbot:pircbot:1.5.0")
|
||||
|
||||
compile("commons-codec:commons-codec:1.10")
|
||||
//compile("commons-codec:commons-codec:1.10")
|
||||
compile("commons-logging:commons-logging:1.2")
|
||||
compile("commons-net:commons-net:3.6")
|
||||
compile("commons-cli:commons-cli:1.4")
|
||||
compile("commons-httpclient:commons-httpclient:3.1")
|
||||
compile("com.squareup.okhttp3:okhttp:3.8.0")
|
||||
|
||||
compile("oro:oro:2.0.8")
|
||||
|
||||
compile("org.jsoup:jsoup:1.10.2")
|
||||
compile("com.rometools:rome:1.7.1")
|
||||
compile("com.rometools:rome:1.7.3")
|
||||
compile("org.slf4j:slf4j-log4j12:1.7.25")
|
||||
compile("org.json:json:20160810")
|
||||
compile("org.json:json:20170516")
|
||||
compile("org.ostermiller:utils:1.07.00")
|
||||
|
||||
compile("net.objecthunter:exp4j:0.4.8")
|
||||
|
|
|
@ -33,8 +33,9 @@ package net.thauvin.erik.mobibot.modules;
|
|||
|
||||
import com.Ostermiller.util.CSVParser;
|
||||
import net.thauvin.erik.mobibot.Mobibot;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -87,14 +88,12 @@ final public class StockQuote extends AbstractModule {
|
|||
*/
|
||||
private void run(final Mobibot bot, final String sender, final String symbol) {
|
||||
try {
|
||||
final HttpClient client = new HttpClient();
|
||||
client.getHttpConnectionManager().getParams().setConnectionTimeout(Mobibot.CONNECT_TIMEOUT);
|
||||
client.getHttpConnectionManager().getParams().setSoTimeout(Mobibot.CONNECT_TIMEOUT);
|
||||
|
||||
final GetMethod getMethod = new GetMethod(YAHOO_URL + symbol.toUpperCase());
|
||||
client.executeMethod(getMethod);
|
||||
final OkHttpClient client = new OkHttpClient();
|
||||
final Request request = new Request.Builder().url(YAHOO_URL + symbol.toUpperCase()).build();
|
||||
final Response response = client.newCall(request).execute();
|
||||
|
||||
final String[][] lines = CSVParser.parse(getMethod.getResponseBodyAsString());
|
||||
final String[][] lines = CSVParser.parse(response.body().string());
|
||||
|
||||
if (lines.length > 0) {
|
||||
final String[] quote = lines[0];
|
||||
|
@ -133,7 +132,7 @@ final public class StockQuote extends AbstractModule {
|
|||
} else {
|
||||
bot.send(sender, "No data returned.");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} catch (NullPointerException | IOException e) {
|
||||
bot.getLogger().debug("Unable to retrieve stock quote for: " + symbol, e);
|
||||
bot.send(sender, "An error has occurred retrieving a stock quote: " + e.getMessage());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue