Example usage for twitter4j TwitterAPIConfiguration getShortURLLength

List of usage examples for twitter4j TwitterAPIConfiguration getShortURLLength

Introduction

In this page you can find the example usage for twitter4j TwitterAPIConfiguration getShortURLLength.

Prototype

int getShortURLLength();

Source Link

Usage

From source file:com.appdynamics.alerts.twitter.TwitterAlert.java

License:Apache License

/**
 * Generate <=140 character Twitter status (URL treated as shortened)
 *
 * @param doAPICall     fetch short URL length from Twitter if true, use preset length if false
 * @return  Twitter status/*w ww  .j a  va  2s .  c om*/
 * @throws TwitterException
 */
private static String createStatus(boolean doAPICall) throws TwitterException {
    int urlLength = 22; //shortened URL length for http
    if (doAPICall) {
        TwitterAPIConfiguration apiConfiguration = twitter.help().getAPIConfiguration();
        urlLength = apiConfiguration.getShortURLLength();
    }

    String status;
    if (event instanceof HealthRuleViolation) {
        status = "Health rule violation. ";
        status += "P" + event.priority + " ";
        status += event.severity + " ";

        String msg;
        msg = "Incident ID:" + ((HealthRuleViolation) event).incidentID + " ";
        if (status.length() + urlLength + msg.length() <= STATUS_LENGTH) {
            status += msg;
        }

        msg = ((HealthRuleViolation) event).healthRuleName + " ";
        if (status.length() + urlLength + msg.length() <= STATUS_LENGTH) {
            status += msg;
        }

        status += getShortenedURL(event.deepLinkUrl + ((HealthRuleViolation) event).incidentID);
    } else {
        status = "Event. ";
        status += "P" + event.priority + " ";
        status += event.severity + " ";

        String msg;
        msg = "Event ID:" + ((OtherEvent) event).eventID + " ";
        if (status.length() + urlLength + msg.length() <= STATUS_LENGTH) {
            status += msg;
        }

        msg = ((OtherEvent) event).eventName + " ";
        if (status.length() + urlLength + msg.length() <= STATUS_LENGTH) {
            status += msg;
        }

        status += getShortenedURL(event.deepLinkUrl + ((OtherEvent) event).eventID);
    }
    return status;
}

From source file:com.freshdigitable.udonroad.module.realm.TwitterAPIConfigurationRealm.java

License:Apache License

TwitterAPIConfigurationRealm(TwitterAPIConfiguration configuration) {
    this.photoSizeLimit = configuration.getPhotoSizeLimit();
    this.shortURLLength = configuration.getShortURLLength();
    this.shortURLLengthHttps = configuration.getShortURLLengthHttps();
    this.charactersReservedPerMedia = configuration.getCharactersReservedPerMedia();
    this.maxMediaPerUpload = configuration.getMaxMediaPerUpload();
}

From source file:com.freshdigitable.udonroad.util.TwitterResponseMock.java

License:Apache License

public static TwitterAPIConfiguration createTwitterAPIConfigMock() {
    final TwitterAPIConfiguration mock = mock(TwitterAPIConfiguration.class);
    when(mock.getShortURLLength()).thenReturn(23);
    when(mock.getShortURLLengthHttps()).thenReturn(23);
    return mock;/*from w ww . ja v  a2  s.  co m*/
}

From source file:com.javielinux.utils.Utils.java

License:Apache License

static public void saveApiConfiguration(Context cnt) {
    boolean todo = false;
    long time = PreferenceUtils.getDateApiConfiguration(cnt);
    if (time < 0) {
        PreferenceUtils.setDateApiConfiguration(cnt, new Date().getTime());
        todo = true;/*from  ww w . j  av  a  2 s .  c o  m*/
    } else {
        Date dateToday = new Date();
        Date dateRefresh = new Date(time);
        if (dateToday.after(dateRefresh)) {
            todo = true;
            Calendar calToday = Calendar.getInstance();
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd H:m");
            String tomorrow = Utils.getTomorrow(calToday.get(Calendar.YEAR), (calToday.get(Calendar.MONTH) + 1),
                    calToday.get(Calendar.DATE));
            try {
                Date nextDate = format.parse(tomorrow + " 10:00");
                PreferenceUtils.setDateApiConfiguration(cnt, nextDate.getTime());
            } catch (ParseException e) {
                e.printStackTrace();
            }

        }
    }

    if (todo) {

        Log.d(Utils.TAG, "Cargar configuracin");

        ConnectionManager.getInstance().open(cnt);

        try {
            TwitterAPIConfiguration api = ConnectionManager.getInstance().getUserForSearchesTwitter()
                    .getAPIConfiguration();
            PreferenceUtils.setShortURLLength(cnt, api.getShortURLLength());
            PreferenceUtils.setShortURLLengthHttps(cnt, api.getShortURLLengthHttps());
        } catch (TwitterException e1) {
            e1.printStackTrace();
        } catch (Exception e1) {
            e1.printStackTrace();
        }

    }
}