|
@@ -23,15 +23,28 @@
|
23
|
23
|
package com.dmdirc.addons.parser_twitter.api;
|
24
|
24
|
|
25
|
25
|
import java.io.BufferedReader;
|
|
26
|
+import java.io.ByteArrayInputStream;
|
26
|
27
|
import java.io.IOException;
|
|
28
|
+import java.io.InputStreamReader;
|
|
29
|
+import java.io.UnsupportedEncodingException;
|
27
|
30
|
import java.net.HttpURLConnection;
|
28
|
31
|
import java.net.MalformedURLException;
|
|
32
|
+import java.net.NoRouteToHostException;
|
29
|
33
|
import java.net.ProtocolException;
|
30
|
34
|
import java.net.URL;
|
|
35
|
+import java.net.URLEncoder;
|
|
36
|
+import java.text.ParseException;
|
|
37
|
+import java.text.SimpleDateFormat;
|
|
38
|
+import java.util.ArrayList;
|
31
|
39
|
import java.util.HashMap;
|
|
40
|
+import java.util.LinkedList;
|
32
|
41
|
import java.util.List;
|
33
|
42
|
import java.util.Map;
|
|
43
|
+
|
|
44
|
+import javax.xml.parsers.DocumentBuilder;
|
|
45
|
+import javax.xml.parsers.DocumentBuilderFactory;
|
34
|
46
|
import javax.xml.parsers.ParserConfigurationException;
|
|
47
|
+
|
35
|
48
|
import oauth.signpost.OAuth;
|
36
|
49
|
import oauth.signpost.OAuthConsumer;
|
37
|
50
|
import oauth.signpost.OAuthProvider;
|
|
@@ -43,19 +56,6 @@ import oauth.signpost.exception.OAuthMessageSignerException;
|
43
|
56
|
import oauth.signpost.exception.OAuthNotAuthorizedException;
|
44
|
57
|
import oauth.signpost.signature.SignatureMethod;
|
45
|
58
|
|
46
|
|
-import java.io.ByteArrayInputStream;
|
47
|
|
-
|
48
|
|
-import java.io.InputStreamReader;
|
49
|
|
-import java.io.UnsupportedEncodingException;
|
50
|
|
-import java.net.NoRouteToHostException;
|
51
|
|
-import java.net.URLEncoder;
|
52
|
|
-import java.text.ParseException;
|
53
|
|
-import java.text.SimpleDateFormat;
|
54
|
|
-import java.util.ArrayList;
|
55
|
|
-import java.util.LinkedList;
|
56
|
|
-import javax.xml.parsers.DocumentBuilder;
|
57
|
|
-import javax.xml.parsers.DocumentBuilderFactory;
|
58
|
|
-
|
59
|
59
|
import org.w3c.dom.Document;
|
60
|
60
|
import org.w3c.dom.Element;
|
61
|
61
|
import org.w3c.dom.NodeList;
|
|
@@ -1123,6 +1123,57 @@ public class TwitterAPI {
|
1123
|
1123
|
return result;
|
1124
|
1124
|
}
|
1125
|
1125
|
|
|
1126
|
+ /**
|
|
1127
|
+ * Retrieves the search results for the specified term.
|
|
1128
|
+ *
|
|
1129
|
+ * @param term The term to be searched for
|
|
1130
|
+ * @return A list of matching statuses
|
|
1131
|
+ */
|
|
1132
|
+ public List<TwitterStatus> getSearchResults(final String term) {
|
|
1133
|
+ return getSearchResults(term, -1);
|
|
1134
|
+ }
|
|
1135
|
+
|
|
1136
|
+ /**
|
|
1137
|
+ * Retrieves the search results for the specified term, requesting only
|
|
1138
|
+ * statuses newer than the specified lastStatusId.
|
|
1139
|
+ *
|
|
1140
|
+ * @param term The term to be searched for
|
|
1141
|
+ * @param lastStatusId Maximum status ID to not be returned
|
|
1142
|
+ * @return A list of matching statuses
|
|
1143
|
+ */
|
|
1144
|
+ public List<TwitterStatus> getSearchResults(final String term, final long lastStatusId) {
|
|
1145
|
+ final List<TwitterStatus> result = new ArrayList<TwitterStatus>();
|
|
1146
|
+
|
|
1147
|
+ try {
|
|
1148
|
+ final XMLResponse doc = getXML("http://search.twitter.com/search.atom?since_id="
|
|
1149
|
+ +lastStatusId + "&rpp=100&q=" + URLEncoder.encode(term, "utf-8"));
|
|
1150
|
+
|
|
1151
|
+ if (doc.isGood()) {
|
|
1152
|
+ final NodeList nodes = doc.getElementsByTagName("entry");
|
|
1153
|
+ for (int i = 0; i < nodes.getLength(); i++) {
|
|
1154
|
+ final Element element = (Element) nodes.item(i);
|
|
1155
|
+ final String message = TwitterAPI.getElementContents(element, "title", "");
|
|
1156
|
+ final long id = Long.parseLong(TwitterAPI.getElementContents(element, "id", "::-1").split(":")[2]);
|
|
1157
|
+ final String user = TwitterAPI.getElementContents((Element) element.getElementsByTagName("author").item(0), "name", "").split(" ")[0];
|
|
1158
|
+
|
|
1159
|
+ final long time = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").parse(TwitterAPI.getElementContents(element, "published", "")).getTime();
|
|
1160
|
+
|
|
1161
|
+ result.add(0, new TwitterStatus(this, message, -1, id, user, time));
|
|
1162
|
+ }
|
|
1163
|
+ }
|
|
1164
|
+ } catch (UnsupportedEncodingException ex) {
|
|
1165
|
+ if (isDebug()) {
|
|
1166
|
+ handleError(ex, "* (1) getSearchResults: "+term+" | "+lastStatusId, apiInput, apiOutput);
|
|
1167
|
+ }
|
|
1168
|
+ } catch (ParseException ex) {
|
|
1169
|
+ if (isDebug()) {
|
|
1170
|
+ handleError(ex, "* (2) getSearchResults: "+term+" | "+lastStatusId, apiInput, apiOutput);
|
|
1171
|
+ }
|
|
1172
|
+ }
|
|
1173
|
+
|
|
1174
|
+ return result;
|
|
1175
|
+ }
|
|
1176
|
+
|
1126
|
1177
|
/**
|
1127
|
1178
|
* Get a list of TwitterUsers who we are following.
|
1128
|
1179
|
*
|