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