use of twitter4j.JSONObject in project twitter4j by yusuke.
the class JSONObjectTypeTest method testDetermine.
public void testDetermine() throws Exception {
JSONObject json;
json = new JSONObject(statusJsonText);
if (JSONObjectType.determine(json) != JSONObjectType.Type.STATUS) {
throw new Exception("JSONObjectType.determine failed for STATUS");
}
json = new JSONObject(deleteJsonText);
if (JSONObjectType.determine(json) != JSONObjectType.Type.DELETE) {
throw new Exception("JSONObjectType.determine failed for DELETE");
}
json = new JSONObject(scrubGeoJsonText);
if (JSONObjectType.determine(json) != JSONObjectType.Type.SCRUB_GEO) {
throw new Exception("JSONObjectType.determine failed for SCRUB_GEO");
}
json = new JSONObject(limitJsonText);
if (JSONObjectType.determine(json) != JSONObjectType.Type.LIMIT) {
throw new Exception("JSONObjectType.determine failed for LIMIT");
}
json = new JSONObject(randomJsonText);
if (JSONObjectType.determine(json) != JSONObjectType.Type.UNKNOWN) {
throw new Exception("JSONObjectType.determine failed for random");
}
String disconnectionNotice = "{\"disconnect\":{\"code\":3,\"stream_name\":\"yusuke-sitestream6139-yusuke\",\"reason\":\"control request for yusuke-sitestream6139 106.171.17.29 /1.1/site.json sitestream\"}}";
json = new JSONObject(disconnectionNotice);
if (JSONObjectType.determine(json) != JSONObjectType.Type.DISCONNECTION) {
throw new Exception("JSONObjectType.determine failed for random");
}
}
use of twitter4j.JSONObject in project twitter4j by yusuke.
the class MobypictureUpload method postUpload.
@Override
protected String postUpload() throws TwitterException {
int statusCode = httpResponse.getStatusCode();
if (statusCode != 200)
throw new TwitterException("Mobypic image upload returned invalid status code", httpResponse);
String response = httpResponse.asString();
try {
JSONObject json = new JSONObject(response);
if (!json.isNull("media")) {
return json.getJSONObject("media").getString("mediaurl");
}
} catch (JSONException e) {
throw new TwitterException("Invalid Mobypic response: " + response, e);
}
throw new TwitterException("Unknown Mobypic response", httpResponse);
}
use of twitter4j.JSONObject in project Anserini by castorini.
the class TopicPoller method writeTRECTopicToDisk.
public static void writeTRECTopicToDisk(TRECTopic trecTopic) throws JSONException, IOException {
// TODO Auto-generated method stub
JSONObject obj = new JSONObject();
obj.put("index", trecTopic.topid);
obj.put("query", trecTopic.title);
obj.put("narr", trecTopic.narrative);
obj.put("desc", trecTopic.description);
/*
* It is at participants' discretion on how to utilize the interest profile
* and implement proper query expansion module
*/
obj.put("expansion", new JSONArray());
try (FileWriter topicFile = new FileWriter(TRECSearcher.interestProfilePath + trecTopic.topid + ".json")) {
topicFile.write(obj.toString());
LOG.info("Successfully wrote interest profile " + trecTopic.topid + " to disk.");
topicFile.close();
}
}
use of twitter4j.JSONObject in project twitter4j by yusuke.
the class ImgLyUpload method postUpload.
@Override
protected String postUpload() throws TwitterException {
int statusCode = httpResponse.getStatusCode();
if (statusCode != 200)
throw new TwitterException("ImgLy image upload returned invalid status code", httpResponse);
String response = httpResponse.asString();
try {
JSONObject json = new JSONObject(response);
if (!json.isNull("url"))
return json.getString("url");
} catch (JSONException e) {
throw new TwitterException("Invalid ImgLy response: " + response, e);
}
throw new TwitterException("Unknown ImgLy response", httpResponse);
}
Aggregations