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    private static final URLTemplate RECENTS_URL_TEMPLATE = new URLTemplate("recent_items");
012
013    //Constructor is not allowed
014    private BoxRecents() {
015    }
016
017    /**
018     * Used to retrieve all collaborations associated with the item.
019     *
020     * @see <a href="http://google.com">https://developer.box.com/reference#get-recent-items</a>
021     *
022     * @param api    BoxAPIConnection from the associated file.
023     * @param limit  limit of items to be retrieved. Default is 100. Maximum is 1000
024     * @param fields the optional fields to retrieve.
025     * @return An iterable of BoxCollaboration.Info instances associated with the item.
026     */
027    public static BoxResourceIterable<BoxRecentItem> getRecentItems(final BoxAPIConnection api,
028                                                                    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()),
035                limit) {
036
037            @Override
038            protected BoxRecentItem factory(JsonObject jsonObject) {
039                return new BoxRecentItem(jsonObject, api);
040            }
041        };
042    }
043}