public static JSONObject user2json(User user) throws IOException { String jsonstring = TwitterObjectFactory.getRawJSON(user); JSONObject json = new JSONObject(jsonstring); json.put("retrieval_date", AbstractObjectEntry.utcFormatter.print(System.currentTimeMillis())); Object status = json.remove("status"); // we don't need to store the latest status update in the user dump // TODO: store the latest status in our message database return json; }
/*package*/ RelationshipJSONImpl(HttpResponse res, Configuration conf) throws TwitterException { this(res, res.asJSONObject()); if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.clearThreadLocalMap(); TwitterObjectFactory.registerJSONObject(this, res.asJSONObject()); } }
/*package*/StatusJSONImpl(JSONObject json, Configuration conf) throws TwitterException { super(); init(json); if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.registerJSONObject(this, json); } }
static ResponseList<Location> createLocationList(HttpResponse res, Configuration conf) throws TwitterException { if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.clearThreadLocalMap(); } return createLocationList(res.asJSONArray(), conf.isJSONStoreEnabled()); }
/** * Constructs a Status object from rawJSON string. * * @param rawJSON raw JSON form as String * @return Status * @throws TwitterException when provided string is not a valid JSON string. * @since Twitter4J 2.1.7 */ public static Status createStatus(String rawJSON) throws TwitterException { return TwitterObjectFactory.createStatus(rawJSON); }
/** * Constructs an AccountTotals object from rawJSON string. * * @param rawJSON raw JSON form as String * @return AccountTotals * @throws TwitterException when provided string is not a valid JSON string. * @since Twitter4J 2.1.9 */ public static AccountTotals createAccountTotals(String rawJSON) throws TwitterException { return TwitterObjectFactory.createAccountTotals(rawJSON); }
/** * Constructs a Category object from rawJSON string. * * @param rawJSON raw JSON form as String * @return Category * @throws TwitterException when provided string is not a valid JSON string. * @since Twitter4J 2.1.7 */ public static Category createCategory(String rawJSON) throws TwitterException { return TwitterObjectFactory.createCategory(rawJSON); }
/*package*/ AccountTotalsJSONImpl(HttpResponse res, Configuration conf) throws TwitterException { this(res, res.asJSONObject()); if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.clearThreadLocalMap(); TwitterObjectFactory.registerJSONObject(this, res.asJSONObject()); } }
User asUser(JSONObject json) throws TwitterException { User user = new UserJSONImpl(json); if (CONF.isJSONStoreEnabled()) { TwitterObjectFactory.registerJSONObject(user, json); } return user; }
/*package*/ QueryResultJSONImpl(HttpResponse res, Configuration conf) throws TwitterException { super(res); JSONObject json = res.asJSONObject(); try { JSONObject searchMetaData = json.getJSONObject("search_metadata"); completedIn = ParseUtil.getDouble("completed_in", searchMetaData); count = ParseUtil.getInt("count", searchMetaData); maxId = ParseUtil.getLong("max_id", searchMetaData); nextResults = searchMetaData.has("next_results") ? searchMetaData.getString("next_results") : null; query = ParseUtil.getURLDecodedString("query", searchMetaData); refreshUrl = ParseUtil.getUnescapedString("refresh_url", searchMetaData); sinceId = ParseUtil.getLong("since_id", searchMetaData); JSONArray array = json.getJSONArray("statuses"); tweets = new ArrayList<Status>(array.length()); if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.clearThreadLocalMap(); } for (int i = 0; i < array.length(); i++) { JSONObject tweet = array.getJSONObject(i); tweets.add(new StatusJSONImpl(tweet, conf)); } } catch (JSONException jsone) { throw new TwitterException(jsone.getMessage() + ":" + json.toString(), jsone); } }
private void subjectFromStatus(String tweet, Datasource datasource) { try { status = TwitterObjectFactory.createStatus(tweet); } catch (TwitterException e) { log.error("Not a valid json string: {}, {}", tweet, e.getErrorMessage());
/*package*/ PlaceJSONImpl(HttpResponse res, Configuration conf) throws TwitterException { super(res); JSONObject json = res.asJSONObject(); init(json); if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.clearThreadLocalMap(); TwitterObjectFactory.registerJSONObject(this, json); } }
/** * Returns a raw JSON form of the provided object.<br> * Note that raw JSON forms can be retrieved only from the same thread invoked the last method call and will become inaccessible once another method call * * @param obj target object to retrieve JSON * @return raw JSON * @since Twitter4J 2.1.7 */ public static String getRawJSON(Object obj) { return TwitterObjectFactory.getRawJSON(obj); }
Status asStatus(JSONObject json) throws TwitterException { Status status = new StatusJSONImpl(json); if (CONF.isJSONStoreEnabled()) { TwitterObjectFactory.registerJSONObject(status, json); } return status; }
TwitterObjectFactory.clearThreadLocalMap();
/*package*/ OEmbedJSONImpl(HttpResponse res, Configuration conf) throws TwitterException { super(res); JSONObject json = res.asJSONObject(); init(json); if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.clearThreadLocalMap(); TwitterObjectFactory.registerJSONObject(this, json); } }
@Override public void onStatus(Status tweet) { String jsonTweet = TwitterObjectFactory.getRawJSON(tweet); inputQ.add(jsonTweet); }
UserList asUserList(JSONObject json) throws TwitterException { UserList userList = new UserListJSONImpl(json); if (CONF.isJSONStoreEnabled()) { TwitterObjectFactory.registerJSONObject(userList, json); } return userList; }
/*package*/ AccountSettingsJSONImpl(HttpResponse res, Configuration conf) throws TwitterException { this(res, res.asJSONObject()); if (conf.isJSONStoreEnabled()) { TwitterObjectFactory.clearThreadLocalMap(); TwitterObjectFactory.registerJSONObject(this, res.asJSONObject()); } }
@Override public void onStatus(Status status) { String jsonTweet = TwitterObjectFactory.getRawJSON(status); inputQ.add(jsonTweet); }