private AccountSettingsJSONImpl(HttpResponse res, JSONObject json) throws TwitterException {
   super(res);
   try {
     JSONObject sleepTime = json.getJSONObject("sleep_time");
     SLEEP_TIME_ENABLED = getBoolean("enabled", sleepTime);
     SLEEP_START_TIME = sleepTime.getString("start_time");
     SLEEP_END_TIME = sleepTime.getString("end_time");
     if (json.isNull("trend_location")) {
       TREND_LOCATION = new Location[0];
     } else {
       JSONArray locations = json.getJSONArray("trend_location");
       TREND_LOCATION = new Location[locations.length()];
       for (int i = 0; i < locations.length(); i++) {
         TREND_LOCATION[i] = new LocationJSONImpl(locations.getJSONObject(i));
       }
     }
     GEO_ENABLED = getBoolean("geo_enabled", json);
     LANGUAGE = json.getString("language");
     ALWAYS_USE_HTTPS = getBoolean("always_use_https", json);
     DISCOVERABLE_BY_EMAIL = getBoolean("discoverable_by_email", json);
     TIMEZONE = new TimeZoneJSONImpl(json.getJSONObject("time_zone"));
     SCREEN_NAME = json.getString("screen_name");
   } catch (JSONException e) {
     throw new TwitterException(e);
   }
 }
Пример #2
0
  private static String parseText(String tweet) throws JSONException {
    JSONObject json = new JSONObject(tweet);

    JSONObject jsonText = json.getJSONObject("text");
    String text = jsonText.getString("text");
    return text;
  }
Пример #3
0
  public MediaEntityJSONImpl(JSONObject json) throws TwitterException {
    try {
      JSONArray indicesArray = json.getJSONArray("indices");
      this.start = indicesArray.getInt(0);
      this.end = indicesArray.getInt(1);
      this.id = getLong("id", json);

      try {
        this.url = new URL(json.getString("url"));
      } catch (MalformedURLException ignore) {
      }

      if (!json.isNull("expanded_url")) {
        try {
          this.expandedURL = new URL(json.getString("expanded_url"));
        } catch (MalformedURLException ignore) {
        }
      }
      if (!json.isNull("media_url")) {
        try {
          this.mediaURL = new URL(json.getString("media_url"));
        } catch (MalformedURLException ignore) {
        }
      }
      if (!json.isNull("media_url_https")) {
        try {
          this.mediaURLHttps = new URL(json.getString("media_url_https"));
        } catch (MalformedURLException ignore) {
        }
      }
      if (!json.isNull("display_url")) {
        this.displayURL = json.getString("display_url");
      }
      JSONObject sizes = json.getJSONObject("sizes");
      this.sizes = new HashMap<Integer, MediaEntity.Size>(4);
      this.sizes.put(MediaEntity.Size.LARGE, new Size(sizes.getJSONObject("large")));
      this.sizes.put(MediaEntity.Size.MEDIUM, new Size(sizes.getJSONObject("medium")));
      this.sizes.put(MediaEntity.Size.SMALL, new Size(sizes.getJSONObject("small")));
      this.sizes.put(MediaEntity.Size.THUMB, new Size(sizes.getJSONObject("thumb")));
      if (!json.isNull("type")) {
        this.type = json.getString("type");
      }
    } catch (JSONException jsone) {
      throw new TwitterException(jsone);
    }
  }
Пример #4
0
 /*package*/ RelationshipJSONImpl(HttpResponse res, JSONObject json) throws TwitterException {
   super(res);
   try {
     JSONObject relationship = json.getJSONObject("relationship");
     JSONObject sourceJson = relationship.getJSONObject("source");
     JSONObject targetJson = relationship.getJSONObject("target");
     sourceUserId = getLong("id", sourceJson);
     targetUserId = getLong("id", targetJson);
     sourceUserScreenName = getUnescapedString("screen_name", sourceJson);
     targetUserScreenName = getUnescapedString("screen_name", targetJson);
     sourceBlockingTarget = getBoolean("blocking", sourceJson);
     sourceFollowingTarget = getBoolean("following", sourceJson);
     sourceFollowedByTarget = getBoolean("followed_by", sourceJson);
     sourceNotificationsEnabled = getBoolean("notifications_enabled", sourceJson);
   } catch (JSONException jsone) {
     throw new TwitterException(jsone.getMessage() + ":" + json.toString(), jsone);
   }
 }
Пример #5
0
  private void init(JSONObject json) throws TwitterException {
    id = getLong("id", json);
    text = getUnescapedString("text", json);
    source = getUnescapedString("source", json);
    createdAt = getDate("created_at", json);
    isTruncated = getBoolean("truncated", json);
    inReplyToStatusId = getLong("in_reply_to_status_id", json);
    inReplyToUserId = getLong("in_reply_to_user_id", json);
    isFavorited = getBoolean("favorited", json);
    inReplyToScreenName = getUnescapedString("in_reply_to_screen_name", json);
    retweetCount = getLong("retweet_count", json);
    try {
      if (!json.isNull("user")) {
        user = new UserJSONImpl(json.getJSONObject("user"));
      }
    } catch (JSONException jsone) {
      throw new TwitterException(jsone);
    }
    geoLocation = z_T4JInternalJSONImplFactory.createGeoLocation(json);
    if (!json.isNull("place")) {
      try {
        place = new PlaceJSONImpl(json.getJSONObject("place"));
      } catch (JSONException ignore) {
        ignore.printStackTrace();
        logger.warn("failed to parse place:" + json);
      }
    }

    if (!json.isNull("retweeted_status")) {
      try {
        retweetedStatus = new StatusJSONImpl(json.getJSONObject("retweeted_status"));
      } catch (JSONException ignore) {
        ignore.printStackTrace();
        logger.warn("failed to parse retweeted_status:" + json);
      }
    }
    if (!json.isNull("contributors")) {
      try {
        JSONArray contributorsArray = json.getJSONArray("contributors");
        contributorsIDs = new long[contributorsArray.length()];
        for (int i = 0; i < contributorsArray.length(); i++) {
          contributorsIDs[i] = Long.parseLong(contributorsArray.getString(i));
        }
      } catch (NumberFormatException ignore) {
        ignore.printStackTrace();
        logger.warn("failed to parse contributors:" + json);
      } catch (JSONException ignore) {
        ignore.printStackTrace();
        logger.warn("failed to parse contributors:" + json);
      }
    } else {
      contributors = null;
    }
    if (!json.isNull("entities")) {
      try {
        JSONObject entities = json.getJSONObject("entities");
        int len;
        if (!entities.isNull("user_mentions")) {
          JSONArray userMentionsArray = entities.getJSONArray("user_mentions");
          len = userMentionsArray.length();
          userMentionEntities = new UserMentionEntity[len];
          for (int i = 0; i < len; i++) {
            userMentionEntities[i] =
                new UserMentionEntityJSONImpl(userMentionsArray.getJSONObject(i));
          }
        }
        if (!entities.isNull("urls")) {
          JSONArray urlsArray = entities.getJSONArray("urls");
          len = urlsArray.length();
          urlEntities = new URLEntity[len];
          for (int i = 0; i < len; i++) {
            urlEntities[i] = new URLEntityJSONImpl(urlsArray.getJSONObject(i));
          }
        }

        if (!entities.isNull("hashtags")) {
          JSONArray hashtagsArray = entities.getJSONArray("hashtags");
          len = hashtagsArray.length();
          hashtagEntities = new HashtagEntity[len];
          for (int i = 0; i < len; i++) {
            hashtagEntities[i] = new HashtagEntityJSONImpl(hashtagsArray.getJSONObject(i));
          }
        }

        if (!entities.isNull("media")) {
          JSONArray mediaArray = entities.getJSONArray("media");
          len = mediaArray.length();
          mediaEntities = new MediaEntity[len];
          for (int i = 0; i < len; i++) {
            mediaEntities[i] = new MediaEntityJSONImpl(mediaArray.getJSONObject(i));
          }
        }
      } catch (JSONException jsone) {
        throw new TwitterException(jsone);
      }
    }
    if (!json.isNull("annotations")) {
      try {
        JSONArray annotationsArray = json.getJSONArray("annotations");
        annotations = new Annotations(annotationsArray);
      } catch (JSONException ignore) {
      }
    }
    if (!json.isNull("current_user_retweet")) {
      try {
        myRetweetedStatus = new StatusJSONImpl(json.getJSONObject("current_user_retweet"));
      } catch (JSONException ignore) {
        ignore.printStackTrace();
        logger.warn("failed to parse current_user_retweet:" + json);
      }
    }
  }