Class SortQueryBuilder

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

public class SortQueryBuilder extends Object implements QueryBuilder
Builder for sorting .list() call responses by sortable fields.

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

     SortQueryBuilder sort = new SortQueryBuilder();
     sort.ascending("invoice_date");
     assertEquals("&sort=invoice_date_asc", sort.build(ResourceType.ACCOUNTING_LIKE));

     ArrayList<QueryBuilder> builders = new ArrayList<QueryBuilder>();
     builders.add(sort);
     ClientList clientListResponse = clients.list(accountId, builders);
 
  • Constructor Details

    • SortQueryBuilder

      public SortQueryBuilder()
  • Method Details

    • ascending

      public void ascending(String key)
      Add a sort by the field in ascending order.
      Parameters:
      key - The field for the resource list to be sorted by
    • descending

      public void descending(String key)
      Add a sort by the field in descending order.
      Parameters:
      key - The field for the resource list to be sorted by
    • toString

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

      public String build(ResourceType resourceType)
      Build the query string parameters for the list call. As different FreshBooks resources use different structure for sort parameters, a resource type is required.
      Specified by:
      build in interface QueryBuilder
      Parameters:
      resourceType - The resource type.
      Returns:
      The composed query string parameters.