package com.proxerme.library.connection.notifications.request;

import android.support.annotation.IntRange;
import android.support.annotation.NonNull;

import com.afollestad.bridge.Form;
import com.afollestad.bridge.Response;
import com.proxerme.library.connection.ProxerRequest;
import com.proxerme.library.connection.notifications.result.NewsResult;
import com.proxerme.library.info.ProxerTag;
import com.proxerme.library.info.ProxerUrlHolder;

/**
 * The Request for obtaining the latest News. This API uses pagination.
 *
 * @author Ruben Gees
 */
public class NewsRequest extends ProxerRequest<NewsResult> {

    private static final String NEWS_URL = "/api/v1/notifications/news";

    private static final String PAGE_FORM = "p";

    private int page;

    /**
     * The constructor.
     *
     * @param page The page to load. The first page is 0. If the page is greater than the available
     *             pages, the API will return an empty answer.
     */
    public NewsRequest(@IntRange(from = 0) int page) {
        this.page = page;
    }

    @Override
    protected int getTag() {
        return ProxerTag.NEWS;
    }

    @Override
    protected NewsResult parse(@NonNull Response response) throws Exception {
        return response.asClass(NewsResult.class);
    }

    @NonNull
    @Override
    protected String getURL() {
        return ProxerUrlHolder.getHost() + NEWS_URL;
    }

    @Override
    protected void appendToBody(@NonNull Form form) {
        form.add(PAGE_FORM, page);
    }
}

@@ -143,16 +143,60 @@
 NonNull;
+%0Aimport android.support.annotation.Nullable;
 %0A%0Aimport
@@ -778,29 +778,124 @@
 p%22;%0A
-%0A    private int page
+    private static final String LIMIT_FORM = %22limit%22;%0A%0A    private int page;%0A    @Nullable%0A    private Integer limit
 ;%0A%0A 
@@ -1183,32 +1183,327 @@
  = page;%0A    %7D%0A%0A
+    /**%0A     * Builder method for setting the maximum amount of entries retrieved.%0A     *%0A     * @param limit The limit.%0A     * @return This request.%0A     */%0A    public NewsRequest withLimit(@IntRange(from = 1) @Nullable Integer limit) %7B%0A        this.limit = limit;%0A%0A        return this;%0A    %7D%0A%0A
     @Override%0A  
@@ -1938,16 +1938,97 @@
 , page);
+%0A%0A        if (limit != null) %7B%0A            form.add(LIMIT_FORM, limit);%0A        %7D
 %0A    %7D%0A%7D

Add ability to set limit for NewsRequests