|
| 1 | +package com.darksci.pardot.api.request.prospect; |
| 2 | + |
| 3 | +import com.darksci.pardot.api.request.BaseQueryRequest; |
| 4 | +import com.darksci.pardot.api.request.DateParameter; |
| 5 | +import org.slf4j.Logger; |
| 6 | +import org.slf4j.LoggerFactory; |
| 7 | + |
| 8 | +import java.util.Collection; |
| 9 | +import java.util.stream.Collectors; |
| 10 | + |
| 11 | +/** |
| 12 | + * Defines a Prospect Query Request. |
| 13 | + */ |
| 14 | +public class ProspectQueryRequest extends BaseQueryRequest<ProspectQueryRequest> { |
| 15 | + |
| 16 | + @Override |
| 17 | + public String getApiEndpoint() { |
| 18 | + return "prospect/do/query"; |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * Specifies the fields to be returned. Note: If this parameter isn't present, all default fields and custom fields |
| 23 | + * for which the prospect has a value will be returned; |
| 24 | + * id field will always be returned. |
| 25 | + * |
| 26 | + * Each call will append the field argument to the list of previously passed fields. |
| 27 | + * |
| 28 | + * @param fields Collection of fields to be selected by the request. |
| 29 | + * @return RequestBuilder |
| 30 | + */ |
| 31 | + public ProspectQueryRequest withFields(Collection<String> fields) { |
| 32 | + final String fieldsStr = fields.stream().collect(Collectors.joining( "," )); |
| 33 | + final String currentValue = getParam("fields"); |
| 34 | + if (currentValue == null) { |
| 35 | + // set |
| 36 | + return setParam("fields", fieldsStr); |
| 37 | + } else { |
| 38 | + // Append |
| 39 | + return setParam("fields", currentValue + "," + fieldsStr); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Specifies the fields to be returned. Note: If this parameter isn't present, all default fields and custom fields |
| 45 | + * for which the prospect has a value will be returned; |
| 46 | + * id field will always be returned. |
| 47 | + * |
| 48 | + * Each call will append the field argument to the list of previously passed fields. |
| 49 | + * |
| 50 | + * @param field Field to be selected by request. |
| 51 | + * @return RequestBuilder |
| 52 | + */ |
| 53 | + public ProspectQueryRequest withField(final String field) { |
| 54 | + final String currentValue = getParam("fields"); |
| 55 | + if (currentValue == null) { |
| 56 | + // set |
| 57 | + return setParam("fields", field); |
| 58 | + } else { |
| 59 | + // Append |
| 60 | + return setParam("fields", currentValue + "," + field); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Only select prospects who are assigned. |
| 66 | + * @return RequestBuilder |
| 67 | + */ |
| 68 | + public ProspectQueryRequest withAssignedOnly() { |
| 69 | + return setBooleanParam("assigned", true); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Only select prospects who are NOT assigned. |
| 74 | + * @return RequestBuilder |
| 75 | + */ |
| 76 | + public ProspectQueryRequest withUnassignedOnly() { |
| 77 | + return setBooleanParam("assigned", false); |
| 78 | + } |
| 79 | + |
| 80 | + /** |
| 81 | + * Only select prospects who are assigned to the specified user, by Id. |
| 82 | + * @param userId The userId to filter by. |
| 83 | + * @return RequestBuilder |
| 84 | + */ |
| 85 | + public ProspectQueryRequest withAssignedUser(final Long userId) { |
| 86 | + return setParam("assigned_to_user", userId); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Only select prospects who are assigned to the specified user, by email address. |
| 91 | + * @param userEmail The user to filter by, as defined by their Email address. |
| 92 | + * @return RequestBuilder |
| 93 | + */ |
| 94 | + public ProspectQueryRequest withAssignUser(final String userEmail) { |
| 95 | + return setParam("assigned_to_user", userEmail); |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Only select prospects who are archived. |
| 100 | + * @return RequestBuilder |
| 101 | + */ |
| 102 | + public ProspectQueryRequest withArchivedOnly() { |
| 103 | + return super.withArchivedOnly(true); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * Only select prospects who are NOT archived. (Default value) |
| 108 | + * @return RequestBuilder |
| 109 | + */ |
| 110 | + public ProspectQueryRequest withNotArchivedOnly() { |
| 111 | + return super.withArchivedOnly(false); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Only select prospects who have a grade equal to the specified grade. |
| 116 | + * @param grade Grade in format of "A", "A+", "B", "C-" |
| 117 | + * @return RequestBuilder |
| 118 | + */ |
| 119 | + public ProspectQueryRequest withGradeEqualTo(final String grade) { |
| 120 | + return setParam("grade_equal_to", grade); |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * Only select prospects who have a grade greater than to the specified grade. |
| 125 | + * @param grade Grade in format of "A", "A+", "B", "C-" |
| 126 | + * @return RequestBuilder |
| 127 | + */ |
| 128 | + public ProspectQueryRequest withGradeGreaterThan(final String grade) { |
| 129 | + return setParam("grade_greater_than", grade); |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * Only select prospects who have a grade less than the specified grade. |
| 134 | + * @param grade Grade in format of "A", "A+", "B", "C-" |
| 135 | + * @return RequestBuilder |
| 136 | + */ |
| 137 | + public ProspectQueryRequest withGradeLessThan(final String grade) { |
| 138 | + return setParam("grade_less_than", grade); |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * Only select prospects who have been starred. |
| 143 | + * @return RequestBuilder |
| 144 | + */ |
| 145 | + public ProspectQueryRequest withStarredOnly() { |
| 146 | + return setBooleanParam("is_starred", true); |
| 147 | + } |
| 148 | + |
| 149 | + /** |
| 150 | + * Only select prospects who have NOT been starred. |
| 151 | + * @return RequestBuilder |
| 152 | + */ |
| 153 | + public ProspectQueryRequest withNotStarredOnly() { |
| 154 | + return setBooleanParam("is_starred", false); |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * Only select prospects who have a last activity date after a specified value. |
| 159 | + * @param lastActivityAfter The date to filter. |
| 160 | + * @return RequestBuilder |
| 161 | + */ |
| 162 | + public ProspectQueryRequest withLastActivityAfter(DateParameter lastActivityAfter) { |
| 163 | + return setParam("last_activity_after", lastActivityAfter); |
| 164 | + } |
| 165 | + |
| 166 | + /** |
| 167 | + * Only select prospects who have no activity. |
| 168 | + * @return RequestBuilder |
| 169 | + */ |
| 170 | + public ProspectQueryRequest withNonActiveOnly() { |
| 171 | + return setBooleanParam("last_activity_never", true); |
| 172 | + } |
| 173 | + |
| 174 | + /** |
| 175 | + * Only select prospects who are member's of the specified list Id. |
| 176 | + * @param listId Id of List to filter prospects by. |
| 177 | + * @return RequestBuilder |
| 178 | + */ |
| 179 | + public ProspectQueryRequest withListId(final Long listId) { |
| 180 | + return setParam("list_id", listId); |
| 181 | + } |
| 182 | + |
| 183 | + /** |
| 184 | + * Only select prospects who are considered 'new'. |
| 185 | + * @return RequestBuilder |
| 186 | + */ |
| 187 | + public ProspectQueryRequest withNewOnly() { |
| 188 | + return setBooleanParam("new", true); |
| 189 | + } |
| 190 | + |
| 191 | + /** |
| 192 | + * Only select prospects who are NOT considered 'new'. |
| 193 | + * @return RequestBuilder |
| 194 | + */ |
| 195 | + public ProspectQueryRequest withNotNewOnly() { |
| 196 | + return setBooleanParam("new", false); |
| 197 | + } |
| 198 | + |
| 199 | + /** |
| 200 | + * Only select prospects who have have a score equal to the specified value. |
| 201 | + * @param score Score value to filter by. |
| 202 | + * @return RequestBuilder |
| 203 | + */ |
| 204 | + public ProspectQueryRequest withScoreEqualTo(final Integer score) { |
| 205 | + return setParam("score_equal_to", score); |
| 206 | + } |
| 207 | + |
| 208 | + /** |
| 209 | + * Only select prospects who have have a score greater than the specified value. |
| 210 | + * @param score Score value to filter by. |
| 211 | + * @return RequestBuilder |
| 212 | + */ |
| 213 | + public ProspectQueryRequest withScoreGreaterThan(final Integer score) { |
| 214 | + return setParam("score_greater_than", score); |
| 215 | + } |
| 216 | + |
| 217 | + /** |
| 218 | + * Only select prospects who have have a score less than the specified value. |
| 219 | + * @param score Score value to filter by. |
| 220 | + * @return RequestBuilder |
| 221 | + */ |
| 222 | + public ProspectQueryRequest withScoreLessThan(final Integer score) { |
| 223 | + return setParam("score_less_than", score); |
| 224 | + } |
| 225 | + |
| 226 | + /** |
| 227 | + * Sort by CreatedAt. |
| 228 | + * @return BaseQueryRequest |
| 229 | + */ |
| 230 | + public ProspectQueryRequest withSortByCreatedAt() { |
| 231 | + return super.withSortByCreatedAt(); |
| 232 | + } |
| 233 | + |
| 234 | + /** |
| 235 | + * Sort results by UpdatedAt. |
| 236 | + * @return BaseQueryRequest |
| 237 | + */ |
| 238 | + public ProspectQueryRequest withSortByUpdatedAt() { |
| 239 | + return super.withSortByUpdatedAt(); |
| 240 | + } |
| 241 | + |
| 242 | + /** |
| 243 | + * Sort results by Probability. |
| 244 | + * @return BaseQueryRequest |
| 245 | + */ |
| 246 | + public ProspectQueryRequest withSortByProbability() { |
| 247 | + return withSortBy("probability"); |
| 248 | + } |
| 249 | + |
| 250 | + |
| 251 | + /** |
| 252 | + * Sort results by Probability. |
| 253 | + * @return BaseQueryRequest |
| 254 | + */ |
| 255 | + public ProspectQueryRequest withSortByLastActivityAt() { |
| 256 | + return withSortBy("last_activity_at"); |
| 257 | + } |
| 258 | + |
| 259 | + |
| 260 | + /** |
| 261 | + * Sort results by Id. |
| 262 | + * @return BaseQueryRequest |
| 263 | + */ |
| 264 | + public ProspectQueryRequest withSortById() { |
| 265 | + return super.withSortById(); |
| 266 | + } |
| 267 | + |
| 268 | +} |
0 commit comments