Esempio n. 1
0
  public StoriesResponse getStarredStories(String pageNumber) {
    final APIClient client = new APIClient(context);
    final ValueMultimap values = new ValueMultimap();
    if (!TextUtils.isEmpty(pageNumber)) {
      values.put(APIConstants.PARAMETER_PAGE_NUMBER, "" + pageNumber);
    }
    final APIResponse response = client.get(APIConstants.URL_STARRED_STORIES, values);

    StoriesResponse storiesResponse = gson.fromJson(response.responseString, StoriesResponse.class);
    if (response.responseCode == HttpStatus.SC_OK && !response.hasRedirected) {
      if (TextUtils.equals(pageNumber, "1")) {
        contentResolver.delete(FeedProvider.STARRED_STORIES_URI, null, null);
      }
      for (Story story : storiesResponse.stories) {
        contentResolver.insert(FeedProvider.STARRED_STORIES_URI, story.getValues());
        insertComments(story);
      }
      for (UserProfile user : storiesResponse.users) {
        contentResolver.insert(FeedProvider.USERS_URI, user.getValues());
      }
      return storiesResponse;
    } else {
      return null;
    }
  }
Esempio n. 2
0
 public boolean addCategories(ArrayList<String> categories) {
   final ValueMultimap values = new ValueMultimap();
   for (String category : categories) {
     values.put(APIConstants.PARAMETER_CATEGORY, URLEncoder.encode(category));
   }
   final APIResponse response = post(APIConstants.URL_ADD_CATEGORIES, values, false);
   return (!response.isError());
 }
Esempio n. 3
0
 public StoriesResponse getStoriesByHash(List<String> storyHashes) {
   ValueMultimap values = new ValueMultimap();
   for (String hash : storyHashes) {
     values.put(APIConstants.PARAMETER_H, hash);
   }
   APIResponse response = get(APIConstants.URL_RIVER_STORIES, values);
   return (StoriesResponse) response.getResponse(gson, StoriesResponse.class);
 }
Esempio n. 4
0
 public UnreadCountResponse getFeedUnreadCounts(Set<String> apiIds) {
   ValueMultimap values = new ValueMultimap();
   for (String id : apiIds) {
     values.put(APIConstants.PARAMETER_FEEDID, id);
   }
   APIResponse response = get(APIConstants.URL_FEED_UNREAD_COUNT, values);
   return (UnreadCountResponse) response.getResponse(gson, UnreadCountResponse.class);
 }
Esempio n. 5
0
 public boolean addCategories(ArrayList<String> categories) {
   final APIClient client = new APIClient(context);
   final ValueMultimap values = new ValueMultimap();
   for (String category : categories) {
     values.put(APIConstants.PARAMETER_CATEGORY, URLEncoder.encode(category));
   }
   final APIResponse response = client.post(APIConstants.URL_ADD_CATEGORIES, values, false);
   return (response.responseCode == HttpStatus.SC_OK && !response.hasRedirected);
 }
Esempio n. 6
0
 private NewsBlurResponse markAllAsRead() {
   ValueMultimap values = new ValueMultimap();
   values.put(APIConstants.PARAMETER_DAYS, "0");
   APIResponse response = post(APIConstants.URL_MARK_ALL_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;
 }
Esempio n. 7
0
 public boolean markAllAsRead() {
   final APIClient client = new APIClient(context);
   final ValueMultimap values = new ValueMultimap();
   values.put(APIConstants.PARAMETER_DAYS, "0");
   final APIResponse response = client.post(APIConstants.URL_MARK_ALL_AS_READ, values, false);
   if (!response.isOffline
       && response.responseCode == HttpStatus.SC_OK
       && !response.hasRedirected) {
     return true;
   } else {
     return false;
   }
 }
Esempio n. 8
0
  public SocialFeedResponse getSharedStoriesForFeeds(String[] feedIds, String pageNumber) {
    final APIClient client = new APIClient(context);
    final ValueMultimap values = new ValueMultimap();
    for (String feedId : feedIds) {
      values.put(APIConstants.PARAMETER_FEEDS, feedId);
    }
    if (!TextUtils.isEmpty(pageNumber)) {
      values.put(APIConstants.PARAMETER_PAGE_NUMBER, "" + pageNumber);
    }

    final APIResponse response = client.get(APIConstants.URL_SHARED_RIVER_STORIES, values);

    SocialFeedResponse storiesResponse =
        gson.fromJson(response.responseString, SocialFeedResponse.class);
    if (response.responseCode == HttpStatus.SC_OK && !response.hasRedirected) {

      // If we've successfully retrieved the latest stories for all shared feeds (the first page),
      // delete all previous shared feeds
      if (TextUtils.equals(pageNumber, "1")) {
        Uri storyUri = FeedProvider.ALL_STORIES_URI;
        contentResolver.delete(storyUri, null, null);
      }

      for (Story story : storiesResponse.stories) {
        for (String userId : story.sharedUserIds) {
          Uri storySocialUri =
              FeedProvider.SOCIALFEED_STORIES_URI.buildUpon().appendPath(userId).build();
          contentResolver.insert(storySocialUri, story.getValues());
        }

        Uri storyUri = FeedProvider.FEED_STORIES_URI.buildUpon().appendPath(story.feedId).build();
        contentResolver.insert(storyUri, story.getValues());

        insertComments(story);
      }

      for (UserProfile user : storiesResponse.userProfiles) {
        contentResolver.insert(FeedProvider.USERS_URI, user.getValues());
      }

      if (storiesResponse != null && storiesResponse.feeds != null) {
        for (Feed feed : storiesResponse.feeds) {
          contentResolver.insert(FeedProvider.FEEDS_URI, feed.getValues());
        }
      }

      return storiesResponse;
    } else {
      return null;
    }
  }
Esempio n. 9
0
 public boolean markStoryAsStarred(final String feedId, final String storyId) {
   final APIClient client = new APIClient(context);
   final ValueMultimap values = new ValueMultimap();
   values.put(APIConstants.PARAMETER_FEEDID, feedId);
   values.put(APIConstants.PARAMETER_STORYID, storyId);
   final APIResponse response = client.post(APIConstants.URL_MARK_STORY_AS_STARRED, values, false);
   if (!response.isOffline
       && response.responseCode == HttpStatus.SC_OK
       && !response.hasRedirected) {
     return true;
   } else {
     return false;
   }
 }
Esempio n. 10
0
 public boolean markFeedAsRead(final String[] feedIds) {
   final APIClient client = new APIClient(context);
   final ValueMultimap values = new ValueMultimap();
   for (String feedId : feedIds) {
     values.put(APIConstants.PARAMETER_FEEDID, feedId);
   }
   final APIResponse response = client.post(APIConstants.URL_MARK_FEED_AS_READ, values, false);
   if (!response.isOffline
       && response.responseCode == HttpStatus.SC_OK
       && !response.hasRedirected) {
     return true;
   } else {
     return false;
   }
 }
Esempio n. 11
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;
  }
Esempio n. 12
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);
  }
Esempio n. 13
0
  public StoriesResponse getStoriesForFeeds(
      String[] feedIds, String pageNumber, StoryOrder order, ReadFilter filter) {
    final APIClient client = new APIClient(context);
    final ValueMultimap values = new ValueMultimap();
    for (String feedId : feedIds) {
      values.put(APIConstants.PARAMETER_FEEDS, feedId);
    }
    if (!TextUtils.isEmpty(pageNumber)) {
      values.put(APIConstants.PARAMETER_PAGE_NUMBER, "" + pageNumber);
    }
    values.put(APIConstants.PARAMETER_ORDER, order.getParameterValue());
    values.put(APIConstants.PARAMETER_READ_FILTER, filter.getParameterValue());
    final APIResponse response = client.get(APIConstants.URL_RIVER_STORIES, values);

    StoriesResponse storiesResponse = gson.fromJson(response.responseString, StoriesResponse.class);
    if (response.responseCode == HttpStatus.SC_OK && !response.hasRedirected) {
      if (TextUtils.equals(pageNumber, "1")) {
        Uri storyUri = FeedProvider.ALL_STORIES_URI;
        contentResolver.delete(storyUri, null, null);
      }

      for (Story story : storiesResponse.stories) {
        Uri storyUri = FeedProvider.FEED_STORIES_URI.buildUpon().appendPath(story.feedId).build();
        contentResolver.insert(storyUri, story.getValues());
        insertComments(story);
      }

      for (UserProfile user : storiesResponse.users) {
        contentResolver.insert(FeedProvider.USERS_URI, user.getValues());
      }

      return storiesResponse;
    } else {
      return null;
    }
  }
Esempio n. 14
0
 public NewsBlurResponse markStoryHashUnread(String hash) {
   final ValueMultimap values = new ValueMultimap();
   values.put(APIConstants.PARAMETER_STORY_HASH, hash);
   APIResponse response = post(APIConstants.URL_MARK_STORY_HASH_UNREAD, values, false);
   return response.getResponse(gson, NewsBlurResponse.class);
 }
Esempio n. 15
0
 public NewsBlurResponse markStoryAsUnstarred(String storyHash) {
   ValueMultimap values = new ValueMultimap();
   values.put(APIConstants.PARAMETER_STORY_HASH, storyHash);
   APIResponse response = post(APIConstants.URL_MARK_STORY_AS_UNSTARRED, values, false);
   return response.getResponse(gson, NewsBlurResponse.class);
 }
Esempio n. 16
0
 private NewsBlurResponse markAllAsRead() {
   ValueMultimap values = new ValueMultimap();
   values.put(APIConstants.PARAMETER_DAYS, "0");
   APIResponse response = post(APIConstants.URL_MARK_ALL_AS_READ, values);
   return response.getResponse(gson, NewsBlurResponse.class);
 }
Esempio n. 17
0
 public NewsBlurResponse markStoryAsRead(String storyHash) {
   ValueMultimap values = new ValueMultimap();
   values.put(APIConstants.PARAMETER_STORY_HASH, storyHash);
   APIResponse response = post(APIConstants.URL_MARK_STORIES_READ, values);
   return response.getResponse(gson, NewsBlurResponse.class);
 }
Esempio n. 18
0
 private APIResponse post(final String urlString, final ValueMultimap valueMap) {
   return this.post(urlString, valueMap.asFormEncodedRequestBody());
 }
Esempio n. 19
0
 private APIResponse get(final String urlString, final ValueMultimap valueMap) {
   return this.get(urlString + "?" + valueMap.getParameterString());
 }
Esempio n. 20
0
 private APIResponse post(final String urlString, final ValueMultimap valueMap, boolean jsonIfy) {
   String parameterString = jsonIfy ? valueMap.getJsonString() : valueMap.getParameterString();
   return this.post(urlString, parameterString);
 }
Esempio n. 21
0
 public UnreadStoryHashesResponse getUnreadStoryHashes() {
   ValueMultimap values = new ValueMultimap();
   values.put(APIConstants.PARAMETER_INCLUDE_TIMESTAMPS, "1");
   APIResponse response = get(APIConstants.URL_UNREAD_HASHES, values);
   return (UnreadStoryHashesResponse) response.getResponse(gson, UnreadStoryHashesResponse.class);
 }