Example usage for twitter4j StatusUpdate placeId

List of usage examples for twitter4j StatusUpdate placeId

Introduction

In this page you can find the example usage for twitter4j StatusUpdate placeId.

Prototype

String placeId

To view the source code for twitter4j StatusUpdate placeId.

Click Source Link

Usage

From source file:org.springframework.integration.twitter.StatusUpdateSupport.java

License:Apache License

/**
 * {@link StatusUpdate} instances are used to drive status updates.
 *
 * @param message the inbound messages/*  w ww. ja v a 2s  . c  o  m*/
 * @return a {@link StatusUpdate}  that's been materialized from the inbound message
 * @throws Throwable thrown if something goes wrong
 */
public StatusUpdate fromMessage(Message<?> message) throws Throwable {
    Object payload = message.getPayload();
    StatusUpdate statusUpdate = null;

    if (payload instanceof String) {
        statusUpdate = new StatusUpdate((String) payload);

        if (message.getHeaders().containsKey(TwitterHeaders.TWITTER_IN_REPLY_TO_STATUS_ID)) {
            Long replyId = (Long) message.getHeaders().get(TwitterHeaders.TWITTER_IN_REPLY_TO_STATUS_ID);

            if ((replyId != null) && (replyId > 0)) {
                statusUpdate.inReplyToStatusId(replyId);
            }
        }

        if (message.getHeaders().containsKey(TwitterHeaders.TWITTER_PLACE_ID)) {
            String placeId = (String) message.getHeaders().get(TwitterHeaders.TWITTER_PLACE_ID);

            if (StringUtils.hasText(placeId)) {
                statusUpdate.placeId(placeId);
            }
        }

        if (message.getHeaders().containsKey(TwitterHeaders.TWITTER_GEOLOCATION)) {
            GeoLocation geoLocation = (GeoLocation) message.getHeaders()
                    .get(TwitterHeaders.TWITTER_GEOLOCATION);

            if (null != geoLocation) {
                statusUpdate.location(geoLocation);
            }
        }

        if (message.getHeaders().containsKey(TwitterHeaders.TWITTER_DISPLAY_COORDINATES)) {
            Boolean displayCoords = (Boolean) message.getHeaders()
                    .get(TwitterHeaders.TWITTER_DISPLAY_COORDINATES);

            if (displayCoords != null) {
                statusUpdate.displayCoordinates(displayCoords);
            }
        }
    }

    if (payload instanceof StatusUpdate) {
        statusUpdate = (StatusUpdate) payload;
    }

    return statusUpdate;
}