Class FilterQueryBuilder
java.lang.Object
net.amcintosh.freshbooks.models.builders.FilterQueryBuilder
- All Implemented Interfaces:
QueryBuilder
Builder for making filtered list queries.
Filters can be chained together.
FreshBooksClient freshBooksClient = new FreshBooksClient.FreshBooksClientBuilder("some_client_id")
.withAccessToken("some_token")
.build();
Clients clients = new Clients(freshBooksClient);
FilterQueryBuilder filters = new FilterQueryBuilder();
filters.inList("clientids", [123, 456]);
assertEquals("&search[clientids][]=123&search[clientids][]=456", filters.build(ResourceType.ACCOUNTING_LIKE));
FilterQueryBuilder filters = new FilterQueryBuilder();
filters.like("email_like", "@freshbooks.com").boolean("active", false);
assertEquals("&search[email_like]=@freshbooks.com&active=False", filters.build(ResourceType.ACCOUNTING_LIKE));
ArrayList<QueryBuilder> builders = new ArrayList<QueryBuilder>();
builders.add(filters);
ClientList clientListResponse = clients.list(accountId, builders);
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddBetween
(String field, int value) Filters results where the provided field is either greater than or less than the value based on the filter field.addBetween
(String field, int min, int max) Filters results where the provided field is between two values.addBetween
(String field, String value) Filters results where the provided field is either greater than or less than the value based on the filter field.addBoolean
(String field, boolean value) Filters results where the field is equal to true or false.Filters for entries that come before or after a particular time, as specified by the field.addDateTime
(String field, ZonedDateTime value) Filters for entries that come before or after a particular time, as specified by the field.Filters results where the field is equal to the provided value.Filters results where the field is equal to the provided value.Filters for a match contained within the field being searched.build
(ResourceType resourceType) Build the query string parameters for the list.toString()
-
Constructor Details
-
FilterQueryBuilder
public FilterQueryBuilder()
-
-
Method Details
-
addBetween
Filters results where the provided field is between two values. In general 'between' filters in FreshBooks end in a '_min
' or '_max
' (as in 'amount_min
' or 'amount_max
') or '_date
' (as in 'start_date
', 'end_date
'). Thus for numerical values '_min
' and '_max
' will be appended to the 'field
' value.
Eg. 'addBetween("amount", 1, 10);
' will result in a filter of '&search[amount_min]=1&search[amount_max]=10
'.
For '_date
' fields, or non-standard between filters, they must be composed individually:
Eg. 'addBetween("start_date", "2022-01-19");
' will result in filters of '&search[start_date]=2022-01-19
'.- Parameters:
field
- The API response field to filter onmin
- The value the field should be greater than (or equal to)max
- The value the field should be less than (or equal to)- Returns:
- The FilterQueryBuilder instance.
-
addBetween
Filters results where the provided field is either greater than or less than the value based on the filter field.
Eg.- '
addBetween("amount_min", 1);
' will result in a filter of '&search[amount_min]=1
'. - '
addBetween("amount_max", 10);
' will result in a filter of '&search[amount_max]=10
'.
- Parameters:
field
- The API filter keyvalue
- The value the key should be compared to- Returns:
- The FilterQueryBuilder instance.
- '
-
addBetween
Filters results where the provided field is either greater than or less than the value based on the filter field.
Eg. 'addBetween("start_date", "2022-01-19");
' will result in a filter of '&search[start_date]=2022-01-19
'.- Parameters:
field
- The API filter keyvalue
- The value the key should be compared to- Returns:
- The FilterQueryBuilder instance.
-
addBoolean
Filters results where the field is equal to true or false.
Eg. 'addBoolean("active", false);
' will result in a filter of '&active=false
'.- Parameters:
field
- The API response field to filter onvalue
- true or false- Returns:
- The FilterQueryBuilder instance.
-
addDate
Filters for entries that come before or after a particular time, as specified by the field. Eg. "updated_since" on Time Entries will return time entries updated after the provided date.
Eg. 'addDateTime("updated_since", LocalDate.now())
' will yield '&updated_since=2022-01-28
'.- Parameters:
field
- The API response field to filter onvalue
- The date object- Returns:
- The FilterQueryBuilder instance.
-
addDateTime
Filters for entries that come before or after a particular time, as specified by the field. Eg. "updated_since" on Time Entries will return time entries updated after the provided time.
Eg. 'addDateTime("updated_since", ZonedDateTime.now())
' will yield '&updated_since=2022-01-28T13:14:07
'.- Parameters:
field
- The API response field to filter onvalue
- The timezone-aware date time object- Returns:
- The FilterQueryBuilder instance.
-
addEquals
Filters results where the field is equal to the provided value.
Eg. 'addEquals("username", "Bob")
' will yield '&search[username]=Bob
' for an accounting-like resource and '&username=Bob
' for a project-like resource.- Parameters:
field
- The API response field to filter onvalue
- The value the field should equal- Returns:
- The FilterQueryBuilder instance.
-
addEquals
Filters results where the field is equal to the provided value.
Eg. 'addEquals("username", "Bob")
' will yield '&search[username]=Bob
' for an accounting-like resource and '&username=Bob
' for a project-like resource.- Parameters:
field
- The API response field to filter onvalue
- The value the field should equal- Returns:
- The FilterQueryBuilder instance.
-
addInList
-
addLike
Filters for a match contained within the field being searched. For example, "leaf" will Like-match "aleaf" and "leafy", but not "leav", and "leafs" would not Like-match "leaf".
Eg. 'addLike("organization_like", "fresh")
' will yield '&search[organization_like]=fresh
'.- Parameters:
field
- The API response field to filter onvalue
- The value the field should equal- Returns:
- The FilterQueryBuilder instance.
-
toString
-
build
Build the query string parameters for the list. As different FreshBooks resources use different structure for filter parameters, a resource type is required.- Specified by:
build
in interfaceQueryBuilder
- Parameters:
resourceType
- The resource type.- Returns:
- The composed query string parameters.
-