Class PaginationQueryBuilder

java.lang.Object
net.amcintosh.freshbooks.models.builders.PaginationQueryBuilder
All Implemented Interfaces:
QueryBuilder

public class PaginationQueryBuilder extends Object implements QueryBuilder
Builder for making paginated list queries. Has two attributes, page and perPage. When a PaginationQueryBuilder is passed to a .list() call, the call will fetch only the perPage number of results and will fetch the results offset by page.

     FreshBooksClient freshBooksClient = new FreshBooksClient.FreshBooksClientBuilder("some_client_id")
         .withAccessToken("some_token")
         .build();
     Clients clients = new Clients(freshBooksClient);

     PaginationQueryBuilder p = new PaginationQueryBuilder(2, 4);
     assertEquals("&page=2&per_page=4", p.build(ResourceType.ACCOUNTING_LIKE));

     ArrayList<QueryBuilder> builders = new ArrayList<QueryBuilder>();
     builders.add(p);

     ClientList clientListResponse = clients.list(accountId, builders);
 
  • Constructor Details

    • PaginationQueryBuilder

      public PaginationQueryBuilder()
      Create an uninitialized pagination query builder (page=1, perPage=100).
    • PaginationQueryBuilder

      public PaginationQueryBuilder(int page, int perPage)
      Create an pagination query builder.
      Parameters:
      page - Page of results to return
      perPage - Number of results to return
  • Method Details

    • page

      public PaginationQueryBuilder page(int page)
      Set the page number to query.
      Parameters:
      page - Page of results to return
      Returns:
      The PaginationQueryBuilder instance.
    • perPage

      public PaginationQueryBuilder perPage(int perPage)
      Set the number of results per page.
      Parameters:
      perPage - Number of results to return
      Returns:
      The PaginationQueryBuilder instance.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • build

      public String build(ResourceType resourceType)
      Build the query string parameters for the list call. While all FreshBooks resources use the same structure of page paramters, a resource type is still required for interface consistency.
      Specified by:
      build in interface QueryBuilder
      Parameters:
      resourceType - The resource type.
      Returns:
      The composed query string parameters.