Example usage for twitter4j JSONObject put

List of usage examples for twitter4j JSONObject put

Introduction

In this page you can find the example usage for twitter4j JSONObject put.

Prototype

public JSONObject put(String name, Object value) throws JSONException 

Source Link

Document

Maps name to value , clobbering any existing name/value mapping with the same name.

Usage

From source file:com.marpies.ane.twitter.functions.FollowUserFunction.java

License:Apache License

@Override
public void createdFriendship(User user) {
    AIR.log("Success following user: " + user.getScreenName());
    try {//from ww  w.  j  a  v a 2 s  .  c  om
        JSONObject userJSON = UserUtils.getJSON(user);
        userJSON.put("listenerID", mCallbackID);
        userJSON.put("success", "true");
        AIR.dispatchEvent(AIRTwitterEvent.USER_QUERY_SUCCESS, userJSON.toString());
    } catch (JSONException e) {
        e.printStackTrace();
        AIR.dispatchEvent(AIRTwitterEvent.USER_QUERY_SUCCESS,
                StringUtils.getEventErrorJSON(mCallbackID, e.getMessage()));
    }
}

From source file:com.marpies.ane.twitter.functions.GetLoggedInUserFunction.java

License:Apache License

private void dispatchUser(User user) throws JSONException {
    JSONObject userJSON = UserUtils.getJSON(user);
    userJSON.put("listenerID", mCallbackID);
    userJSON.put("success", true);
    userJSON.put("loggedInUser", true); // So that we can cache the user object in AS3
    AIR.dispatchEvent(AIRTwitterEvent.USER_QUERY_SUCCESS, userJSON.toString());
}

From source file:com.marpies.ane.twitter.functions.GetUserFunction.java

License:Apache License

@Override
public void gotUserDetail(User user) {
    AIR.log("Successfully retrieved user info");
    try {/*from   www . j a v a 2s  .c  o  m*/
        JSONObject userJSON = UserUtils.getJSON(user);
        userJSON.put("listenerID", mCallbackID);
        userJSON.put("success", true);
        AIR.dispatchEvent(AIRTwitterEvent.USER_QUERY_SUCCESS, userJSON.toString());
    } catch (JSONException e) {
        AIR.dispatchEvent(AIRTwitterEvent.USER_QUERY_SUCCESS,
                StringUtils.getEventErrorJSON(mCallbackID, "Error parsing returned user info."));
    }
}

From source file:com.marpies.ane.twitter.functions.SendDirectMessageFunction.java

License:Apache License

@Override
public void sentDirectMessage(DirectMessage message) {
    AIR.log("Success sending DM '" + message.getText() + "'");
    try {//from  w ww . j av a  2s  . c  om
        JSONObject dmJSON = DirectMessageUtils.getJSON(message);
        dmJSON.put("listenerID", mCallbackID);
        dmJSON.put("success", "true");
        AIR.dispatchEvent(AIRTwitterEvent.DIRECT_MESSAGE_QUERY_SUCCESS, dmJSON.toString());
    } catch (JSONException e) {
        e.printStackTrace();
        AIR.dispatchEvent(AIRTwitterEvent.DIRECT_MESSAGE_QUERY_SUCCESS,
                StringUtils.getEventErrorJSON(mCallbackID, e.getMessage()));
    }
}

From source file:com.marpies.ane.twitter.functions.UnfollowUserFunction.java

License:Apache License

@Override
public void destroyedFriendship(User user) {
    AIR.log("Success unfollowing user: " + user.getScreenName());
    try {//from  w  w w.j  a  v  a 2s.  c o  m
        JSONObject userJSON = UserUtils.getJSON(user);
        userJSON.put("listenerID", mCallbackID);
        userJSON.put("success", "true");
        AIR.dispatchEvent(AIRTwitterEvent.USER_QUERY_SUCCESS, userJSON.toString());
    } catch (JSONException e) {
        e.printStackTrace();
        AIR.dispatchEvent(AIRTwitterEvent.USER_QUERY_SUCCESS,
                StringUtils.getEventErrorJSON(mCallbackID, e.getMessage()));
    }
}

From source file:com.marpies.ane.twitter.functions.UpdateStatusFunction.java

License:Apache License

@Override
public void updatedStatus(Status status) {
    AIR.log("Updated status w/ message " + status.getText());
    try {/*from  ww  w.  j a v  a 2  s  . c o m*/
        JSONObject statusJSON = StatusUtils.getJSON(status);
        statusJSON.put("listenerID", mCallbackID);
        statusJSON.put("success", true);
        AIR.dispatchEvent(AIRTwitterEvent.STATUS_QUERY_SUCCESS, statusJSON.toString());
    } catch (JSONException e) {
        e.printStackTrace();
        AIR.dispatchEvent(AIRTwitterEvent.STATUS_QUERY_SUCCESS, StringUtils.getEventErrorJSON(mCallbackID,
                "Status update succeeded but could not parse returned status."));
    }
}

From source file:com.marpies.ane.twitter.utils.DirectMessageUtils.java

License:Apache License

/**
 * Creates JSON from given response list and dispatches generic event.
 * Helper method for queries like getDirectMessages, getSentDirectMessages...
 * @param messages//www . j  a va 2s  . c o m
 * @param callbackID
 */
public static void dispatchDirectMessages(ResponseList<DirectMessage> messages, int callbackID) {
    try {
        AIR.log("Got response with " + messages.size() + " direct messages");
        /* Create array of messages */
        JSONArray dms = new JSONArray();
        for (DirectMessage message : messages) {
            /* Create JSON for the message and put it to the array */
            dms.put(getJSON(message).toString());
        }
        JSONObject result = new JSONObject();
        result.put("messages", dms);
        result.put("listenerID", callbackID);
        AIR.dispatchEvent(AIRTwitterEvent.DIRECT_MESSAGES_QUERY_SUCCESS, result.toString());
    } catch (JSONException e) {
        AIR.dispatchEvent(AIRTwitterEvent.DIRECT_MESSAGES_QUERY_ERROR,
                StringUtils.getEventErrorJSON(callbackID, "Error creating result JSON: " + e.getMessage()));
    }
}

From source file:com.marpies.ane.twitter.utils.DirectMessageUtils.java

License:Apache License

public static JSONObject getJSON(DirectMessage message) throws JSONException {
    JSONObject dmJSON = new twitter4j.JSONObject();
    dmJSON.put("id", message.getId());
    dmJSON.put("idStr", String.valueOf(message.getId()));
    dmJSON.put("text", message.getText());
    dmJSON.put("createdAt", message.getCreatedAt());
    dmJSON.put("recipient", UserUtils.getJSON(message.getRecipient()));
    dmJSON.put("sender", UserUtils.getJSON(message.getSender()));
    return dmJSON;
}

From source file:com.marpies.ane.twitter.utils.StatusUtils.java

License:Apache License

/**
 * Creates JSON from given response list and dispatches generic event.
 * Helper method for queries like getHomeTimeline, getLikes...
 * @param statuses//from   ww  w  .jav a 2  s .  c om
 * @param excludeReplies
 * @param callbackID
 */
public static void dispatchStatuses(ResponseList<Status> statuses, boolean excludeReplies,
        final int callbackID) {
    try {
        AIR.log("Got response with " + statuses.size() + " statuses"
                + (excludeReplies ? " (yet to filter out replies)" : ""));
        /* Create array of statuses (tweets) */
        JSONArray tweets = new JSONArray();
        for (Status status : statuses) {
            /* Exclude reply if requested */
            if (excludeReplies && status.getInReplyToUserId() >= 0)
                continue;
            /* Create JSON for the status and put it to the array */
            JSONObject statusJSON = getJSON(status);
            tweets.put(statusJSON.toString());
        }
        JSONObject result = new JSONObject();
        result.put("statuses", tweets);
        result.put("listenerID", callbackID);
        AIR.dispatchEvent(AIRTwitterEvent.TIMELINE_QUERY_SUCCESS, result.toString());
    } catch (JSONException e) {
        AIR.dispatchEvent(AIRTwitterEvent.TIMELINE_QUERY_ERROR,
                StringUtils.getEventErrorJSON(callbackID, "Error creating result JSON: " + e.getMessage()));
    }
}

From source file:com.marpies.ane.twitter.utils.StatusUtils.java

License:Apache License

public static JSONObject getJSON(Status status) throws JSONException {
    JSONObject statusJSON = new JSONObject();
    statusJSON.put("id", status.getId());
    statusJSON.put("idStr", String.valueOf(status.getId()));
    statusJSON.put("text", status.getText());
    statusJSON.put("replyToUserID", status.getInReplyToUserId());
    statusJSON.put("replyToStatusID", status.getInReplyToStatusId());
    statusJSON.put("likesCount", status.getFavoriteCount());
    statusJSON.put("retweetCount", status.getRetweetCount());
    statusJSON.put("isRetweet", status.isRetweet());
    statusJSON.put("isSensitive", status.isPossiblySensitive());
    statusJSON.put("createdAt", status.getCreatedAt());
    Status retweetedStatus = status.getRetweetedStatus();
    if (retweetedStatus != null) {
        statusJSON.put("retweetedStatus", getJSON(retweetedStatus));
    }//from  w  ww .  j  av  a 2  s  .  c o m
    User user = status.getUser();
    if (user != null) {
        statusJSON.put("user", UserUtils.getJSON(user));
    }
    return statusJSON;
}