Example #1
0
  public NewsBlurResponse markFeedsAsRead(FeedSet fs, Long includeOlder, Long includeNewer) {
    ValueMultimap values = new ValueMultimap();

    if (fs.getSingleFeed() != null) {
      values.put(APIConstants.PARAMETER_FEEDID, fs.getSingleFeed());
    } else if (fs.getMultipleFeeds() != null) {
      for (String feedId : fs.getMultipleFeeds()) values.put(APIConstants.PARAMETER_FEEDID, feedId);
    } else if (fs.getSingleSocialFeed() != null) {
      values.put(
          APIConstants.PARAMETER_FEEDID,
          APIConstants.VALUE_PREFIX_SOCIAL + fs.getSingleSocialFeed().getKey());
    } else if (fs.getMultipleSocialFeeds() != null) {
      for (Map.Entry<String, String> entry : fs.getMultipleSocialFeeds().entrySet()) {
        values.put(
            APIConstants.PARAMETER_FEEDID, APIConstants.VALUE_PREFIX_SOCIAL + entry.getKey());
      }
    } else if (fs.isAllNormal()) {
      // all stories uses a special API call
      return markAllAsRead();
    } else if (fs.isAllSocial()) {
      values.put(APIConstants.PARAMETER_FEEDID, APIConstants.VALUE_ALLSOCIAL);
    } else {
      throw new IllegalStateException("Asked to get stories for FeedSet of unknown type.");
    }

    if (includeOlder != null) {
      // the app uses  milliseconds but the API wants seconds
      long cut = includeOlder.longValue();
      values.put(APIConstants.PARAMETER_CUTOFF_TIME, Long.toString(cut / 1000L));
      values.put(APIConstants.PARAMETER_DIRECTION, APIConstants.VALUE_OLDER);
    }
    if (includeNewer != null) {
      // the app uses  milliseconds but the API wants seconds
      long cut = includeNewer.longValue();
      values.put(APIConstants.PARAMETER_CUTOFF_TIME, Long.toString(cut / 1000L));
      values.put(APIConstants.PARAMETER_DIRECTION, APIConstants.VALUE_NEWER);
    }

    APIResponse response = post(APIConstants.URL_MARK_FEED_AS_READ, values, false);
    // TODO: these calls use a different return format than others: the errors field is an array,
    // not an object
    // return response.getResponse(gson, NewsBlurResponse.class);
    NewsBlurResponse nbr = new NewsBlurResponse();
    if (response.isError()) nbr.message = "err";
    return nbr;
  }
 @Override
 protected FeedSet createFeedSet() {
   return FeedSet.allSocialFeeds();
 }
Example #3
0
  /**
   * Fetches stories for the given FeedSet, choosing the correct API and the right request
   * parameters as needed.
   */
  public StoriesResponse getStories(
      FeedSet fs, int pageNumber, StoryOrder order, ReadFilter filter) {
    Uri uri = null;
    ValueMultimap values = new ValueMultimap();

    // create the URI and populate request params depending on what kind of stories we want
    if (fs.getSingleFeed() != null) {
      uri =
          Uri.parse(APIConstants.URL_FEED_STORIES)
              .buildUpon()
              .appendPath(fs.getSingleFeed())
              .build();
      values.put(APIConstants.PARAMETER_FEEDS, fs.getSingleFeed());
    } else if (fs.getMultipleFeeds() != null) {
      uri = Uri.parse(APIConstants.URL_RIVER_STORIES);
      for (String feedId : fs.getMultipleFeeds()) values.put(APIConstants.PARAMETER_FEEDS, feedId);
    } else if (fs.getSingleSocialFeed() != null) {
      String feedId = fs.getSingleSocialFeed().getKey();
      String username = fs.getSingleSocialFeed().getValue();
      uri =
          Uri.parse(APIConstants.URL_SOCIALFEED_STORIES)
              .buildUpon()
              .appendPath(feedId)
              .appendPath(username)
              .build();
      values.put(APIConstants.PARAMETER_USER_ID, feedId);
      values.put(APIConstants.PARAMETER_USERNAME, username);
    } else if (fs.getMultipleSocialFeeds() != null) {
      uri = Uri.parse(APIConstants.URL_SHARED_RIVER_STORIES);
      for (Map.Entry<String, String> entry : fs.getMultipleSocialFeeds().entrySet()) {
        values.put(APIConstants.PARAMETER_FEEDS, entry.getKey());
      }
    } else if (fs.isAllNormal()) {
      uri = Uri.parse(APIConstants.URL_RIVER_STORIES);
    } else if (fs.isAllSocial()) {
      uri = Uri.parse(APIConstants.URL_SHARED_RIVER_STORIES);
    } else if (fs.isAllSaved()) {
      uri = Uri.parse(APIConstants.URL_STARRED_STORIES);
    } else {
      throw new IllegalStateException("Asked to get stories for FeedSet of unknown type.");
    }

    // request params common to all stories
    values.put(APIConstants.PARAMETER_PAGE_NUMBER, Integer.toString(pageNumber));
    values.put(APIConstants.PARAMETER_ORDER, order.getParameterValue());
    values.put(APIConstants.PARAMETER_READ_FILTER, filter.getParameterValue());

    APIResponse response = get(uri.toString(), values);
    return (StoriesResponse) response.getResponse(gson, StoriesResponse.class);
  }