001package com.box.sdk;
002
003import com.eclipsesource.json.JsonObject;
004
005/**
006 * Utility class to retrieve list of recent items.
007 *
008 * @see <a href="http://google.com">https://developer.box.com/reference#get-recent-items</a>
009 */
010public final class BoxRecents {
011
012  /** Recents URL Template. */
013  public static final URLTemplate RECENTS_URL_TEMPLATE = new URLTemplate("recent_items");
014
015  // Constructor is not allowed
016  private BoxRecents() {}
017
018  /**
019   * Used to retrieve all collaborations associated with the item.
020   *
021   * @param api BoxAPIConnection from the associated file.
022   * @param limit limit of items to be retrieved. Default is 100. Maximum is 1000
023   * @param fields the optional fields to retrieve.
024   * @return An iterable of BoxCollaboration.Info instances associated with the item.
025   * @see <a href="http://google.com">https://developer.box.com/reference#get-recent-items</a>
026   */
027  public static BoxResourceIterable<BoxRecentItem> getRecentItems(
028      final BoxAPIConnection api, int limit, String... fields) {
029    QueryStringBuilder builder = new QueryStringBuilder();
030    if (fields.length > 0) {
031      builder.appendParam("fields", fields);
032    }
033    return new BoxResourceIterable<BoxRecentItem>(
034        api, RECENTS_URL_TEMPLATE.buildWithQuery(api.getBaseURL(), builder.toString()), limit) {
035
036      @Override
037      protected BoxRecentItem factory(JsonObject jsonObject) {
038        return new BoxRecentItem(jsonObject, api);
039      }
040    };
041  }
042}