From 4d1a6d02ac2270b8c6f700b9da7812e837e43a25 Mon Sep 17 00:00:00 2001 From: vmalinovskiy Date: Fri, 30 Dec 2016 20:04:44 +0200 Subject: [PATCH] vmalinovskiy: minor fixes for get contacts history api --- Changelog.txt | 5 +- gradle.properties | 2 +- .../integration/contacts/ContactsApiTest.java | 10 +-- .../integration/numbers/NumbersApiTest.java | 19 ++++++ .../api/client/api/contacts/ContactsApi.java | 63 ------------------- .../api/client/api/numbers/NumbersApi.java | 21 +++++++ .../request/FindTollfreeNumbersRequest.java | 50 +++++++++++++++ .../client/api/contacts/ContactsApiTest.java | 45 +------------ .../client/api/numbers/NumbersApiTest.java | 19 ++++++ 9 files changed, 117 insertions(+), 117 deletions(-) create mode 100644 src/main/java/com/callfire/api/client/api/numbers/model/request/FindTollfreeNumbersRequest.java diff --git a/Changelog.txt b/Changelog.txt index d340a7c..bd23581 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,9 +1,12 @@ Callfire API client Changelog ============================= +Version 1.7.13 - Dec 30 2016 +- minor fixes for get contacts history api + Version 1.7.12 - Dec 28 2016 - updated CallRecord dto to include originateTime, answerTime, duration, callerName and switchId fields - updated Webhook dto to include singleUse parameter -- minor extension of requests objects for upload and find sounds api, get contacts history api and find tollfree numbers api +- minor extension of requests objects for upload and find sounds api, find tollfree numbers api - temporary turning dnc api off due to full remake of callfire dnc apis Version 1.7.11 - Nov 17 2016 diff --git a/gradle.properties b/gradle.properties index 85ae0f4..f0c4db1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group = com.callfire baseName = callfire-api-client -version = 1.7.12 +version = 1.7.13 diff --git a/src/itest/java/com/callfire/api/client/integration/contacts/ContactsApiTest.java b/src/itest/java/com/callfire/api/client/integration/contacts/ContactsApiTest.java index d3b4fa9..88e74bd 100644 --- a/src/itest/java/com/callfire/api/client/integration/contacts/ContactsApiTest.java +++ b/src/itest/java/com/callfire/api/client/integration/contacts/ContactsApiTest.java @@ -83,7 +83,7 @@ public void testContactsCRUD() throws Exception { } @Test - public void testDeprecatedGetContactHistory() throws Exception { + public void testGetContactHistory() throws Exception { CallfireClient client = getCallfireClient(); GetByIdRequest request = GetByIdRequest.create() .id(1L) @@ -94,12 +94,4 @@ public void testDeprecatedGetContactHistory() throws Exception { System.out.println(contactHistory); } - @Test - public void testGetContactHistory() throws Exception { - CallfireClient client = getCallfireClient(); - ContactHistory contactHistory = client.contactsApi().getHistory(1L); - assertFalse(contactHistory.getCalls().isEmpty()); - - System.out.println(contactHistory); - } } diff --git a/src/itest/java/com/callfire/api/client/integration/numbers/NumbersApiTest.java b/src/itest/java/com/callfire/api/client/integration/numbers/NumbersApiTest.java index 741d6d9..5661ef6 100644 --- a/src/itest/java/com/callfire/api/client/integration/numbers/NumbersApiTest.java +++ b/src/itest/java/com/callfire/api/client/integration/numbers/NumbersApiTest.java @@ -7,6 +7,7 @@ import com.callfire.api.client.api.numbers.model.Region; import com.callfire.api.client.api.numbers.model.request.FindNumberRegionsRequest; import com.callfire.api.client.api.numbers.model.request.FindNumbersLocalRequest; +import com.callfire.api.client.api.numbers.model.request.FindTollfreeNumbersRequest; import com.callfire.api.client.integration.AbstractIntegrationTest; import org.junit.Test; @@ -34,6 +35,24 @@ public void testFindTollfreeNumbers() throws Exception { System.out.println(numbers); } + @Test + public void testFindTollfreeNumbersWithPattern() throws Exception { + CallfireClient callfireClient = getCallfireClient(); + + FindTollfreeNumbersRequest request = FindTollfreeNumbersRequest.create() + .limit(2L) + .pattern("84*") + .fields("items(number)") + .build(); + List numbers = callfireClient.numbersApi().findNumbersTollfree(request); + assertEquals(2, numbers.size()); + assertTrue(numbers.get(0).getNumber().contains("84")); + assertTrue(numbers.get(1).getNumber().contains("84")); + assertNull(numbers.get(0).getNationalFormat()); + assertNull(numbers.get(1).getRegion()); + System.out.println(numbers); + } + @Test public void testFindNumbersLocal() throws Exception { CallfireClient callfireClient = getCallfireClient(); diff --git a/src/main/java/com/callfire/api/client/api/contacts/ContactsApi.java b/src/main/java/com/callfire/api/client/api/contacts/ContactsApi.java index 13af9d6..c0e5d00 100644 --- a/src/main/java/com/callfire/api/client/api/contacts/ContactsApi.java +++ b/src/main/java/com/callfire/api/client/api/contacts/ContactsApi.java @@ -144,8 +144,6 @@ public void delete(Long id) { } /** - * @deprecated this method doesn't work with fields parameter in request, please use getHistory method with id, limit and offset parameters - * * Find all texts and calls attributed to a contact. * * @param request request to get particular contact's history @@ -158,71 +156,10 @@ public void delete(Long id) { * @throws CallfireApiException in case HTTP response code is something different from codes listed above. * @throws CallfireClientException in case error has occurred in client. */ - @Deprecated public ContactHistory getHistory(GetByIdRequest request) { Validate.notNull(request.getId(), "request.id cannot be null"); String path = CONTACTS_ITEM_HISTORY_PATH.replaceFirst(PLACEHOLDER, request.getId().toString()); return client.get(path, of(ContactHistory.class), request); } - /** - * Find all texts and calls attributed to a contact. - * - * @param id contact id to get history for - * @return returns a list of calls and texts a contact has been involved with. - * @throws BadRequestException in case HTTP response code is 400 - Bad request, the request was formatted improperly. - * @throws UnauthorizedException in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. - * @throws AccessForbiddenException in case HTTP response code is 403 - Forbidden, insufficient permissions. - * @throws ResourceNotFoundException in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. - * @throws InternalServerErrorException in case HTTP response code is 500 - Internal Server Error. - * @throws CallfireApiException in case HTTP response code is something different from codes listed above. - * @throws CallfireClientException in case error has occurred in client. - */ - public ContactHistory getHistory(Long id) { - return getHistory(id, null, null); - } - - /** - * Find all texts and calls attributed to a contact. - * - * @param id contact id to get history for - * @param limit maximum number of calls/texts records to return in response - * @return returns a list of calls and texts a contact has been involved with. - * @throws BadRequestException in case HTTP response code is 400 - Bad request, the request was formatted improperly. - * @throws UnauthorizedException in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. - * @throws AccessForbiddenException in case HTTP response code is 403 - Forbidden, insufficient permissions. - * @throws ResourceNotFoundException in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. - * @throws InternalServerErrorException in case HTTP response code is 500 - Internal Server Error. - * @throws CallfireApiException in case HTTP response code is something different from codes listed above. - * @throws CallfireClientException in case error has occurred in client. - */ - public ContactHistory getHistory(Long id, Long limit) { - return getHistory(id, limit, null); - } - - /** - * Find all texts and calls attributed to a contact. - * - * @param id contact id to get history for - * @param limit maximum number of calls/texts records to return in response - * @param offset offset to the start of a given page - * @return returns a list of calls and texts a contact has been involved with. - * @throws BadRequestException in case HTTP response code is 400 - Bad request, the request was formatted improperly. - * @throws UnauthorizedException in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. - * @throws AccessForbiddenException in case HTTP response code is 403 - Forbidden, insufficient permissions. - * @throws ResourceNotFoundException in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. - * @throws InternalServerErrorException in case HTTP response code is 500 - Internal Server Error. - * @throws CallfireApiException in case HTTP response code is something different from codes listed above. - * @throws CallfireClientException in case error has occurred in client. - */ - public ContactHistory getHistory(Long id, Long limit, Long offset) { - Validate.notNull(id, "id cannot be null"); - - List queryParams = new ArrayList<>(1); - addQueryParamIfSet("limit", limit, queryParams); - addQueryParamIfSet("offset", offset, queryParams); - - String path = CONTACTS_ITEM_HISTORY_PATH.replaceFirst(PLACEHOLDER, id.toString()); - return client.get(path, of(ContactHistory.class), queryParams); - } } diff --git a/src/main/java/com/callfire/api/client/api/numbers/NumbersApi.java b/src/main/java/com/callfire/api/client/api/numbers/NumbersApi.java index 8e75a58..5c473bd 100644 --- a/src/main/java/com/callfire/api/client/api/numbers/NumbersApi.java +++ b/src/main/java/com/callfire/api/client/api/numbers/NumbersApi.java @@ -7,6 +7,7 @@ import com.callfire.api.client.api.numbers.model.Region; import com.callfire.api.client.api.numbers.model.request.FindNumberRegionsRequest; import com.callfire.api.client.api.numbers.model.request.FindNumbersLocalRequest; +import com.callfire.api.client.api.numbers.model.request.FindTollfreeNumbersRequest; import java.util.List; @@ -65,6 +66,8 @@ public Page findNumberRegions(FindNumberRegionsRequest request) { } /** + * @deprecated this method doesn't work with offset parameter in request, please use findNumbersTollfree method with FindTollfreeNumbersRequest instead + * * Find numbers in the CallFire tollfree numbers catalog that are available for purchase. * * @param request request payload @@ -77,7 +80,25 @@ public Page findNumberRegions(FindNumberRegionsRequest request) { * @throws CallfireApiException in case HTTP response code is something different from codes listed above. * @throws CallfireClientException in case error has occurred in client. */ + @Deprecated public List findNumbersTollfree(CommonFindRequest request) { return client.get(NUMBERS_TOLLFREE_PATH, listHolderOf(Number.class), request).getItems(); } + + /** + * Find numbers in the CallFire tollfree numbers catalog that are available for purchase. + * + * @param request request payload + * @return list of {@link Number} + * @throws BadRequestException in case HTTP response code is 400 - Bad request, the request was formatted improperly. + * @throws UnauthorizedException in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. + * @throws AccessForbiddenException in case HTTP response code is 403 - Forbidden, insufficient permissions. + * @throws ResourceNotFoundException in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. + * @throws InternalServerErrorException in case HTTP response code is 500 - Internal Server Error. + * @throws CallfireApiException in case HTTP response code is something different from codes listed above. + * @throws CallfireClientException in case error has occurred in client. + */ + public List findNumbersTollfree(FindTollfreeNumbersRequest request) { + return client.get(NUMBERS_TOLLFREE_PATH, listHolderOf(Number.class), request).getItems(); + } } diff --git a/src/main/java/com/callfire/api/client/api/numbers/model/request/FindTollfreeNumbersRequest.java b/src/main/java/com/callfire/api/client/api/numbers/model/request/FindTollfreeNumbersRequest.java new file mode 100644 index 0000000..7791a76 --- /dev/null +++ b/src/main/java/com/callfire/api/client/api/numbers/model/request/FindTollfreeNumbersRequest.java @@ -0,0 +1,50 @@ +package com.callfire.api.client.api.numbers.model.request; + +import com.callfire.api.client.api.common.model.CallfireModel; +import com.callfire.api.client.api.common.model.request.AbstractBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; + +public class FindTollfreeNumbersRequest extends CallfireModel { + private String pattern; + private Long limit; + private String fields; + + private FindTollfreeNumbersRequest() { + } + + public static Builder create() { + return new Builder(); + } + + + @Override + public String toString() { + return new ToStringBuilder(this) + .append("pattern", pattern) + .append("limit", limit) + .append("fields", fields) + .toString(); + } + + public static class Builder extends AbstractBuilder { + + private Builder() { + super(new FindTollfreeNumbersRequest()); + } + + public Builder pattern(String pattern) { + request.pattern = pattern; + return this; + } + + public Builder limit(Long limit) { + request.limit = limit; + return this; + } + + public Builder fields(String fields) { + request.fields = fields; + return this; + } + } +} diff --git a/src/test/java/com/callfire/api/client/api/contacts/ContactsApiTest.java b/src/test/java/com/callfire/api/client/api/contacts/ContactsApiTest.java index ea53bb2..b4575ac 100644 --- a/src/test/java/com/callfire/api/client/api/contacts/ContactsApiTest.java +++ b/src/test/java/com/callfire/api/client/api/contacts/ContactsApiTest.java @@ -137,14 +137,14 @@ public void testDelete() throws Exception { } @Test - public void testDeprecatedGetContactHistoryByNullId() throws Exception { + public void testGetContactHistoryByNullId() throws Exception { ex.expectMessage(EMPTY_REQUEST_ID_MSG); ex.expect(NullPointerException.class); client.contactsApi().getHistory(GetByIdRequest.create().build()); } @Test - public void testDeprecatedGetContactHistory() throws Exception { + public void testGetContactHistory() throws Exception { String expectedJson = getJsonPayload(BASE_PATH + RESPONSES_PATH + "getContactHistory.json"); ArgumentCaptor captor = mockHttpResponse(expectedJson); @@ -163,45 +163,4 @@ public void testDeprecatedGetContactHistory() throws Exception { assertThat(arg.getURI().toString(), containsString("offset=5")); } - @Test - public void testGetContactHistoryById() throws Exception { - String expectedJson = getJsonPayload(BASE_PATH + RESPONSES_PATH + "getContactHistory.json"); - ArgumentCaptor captor = mockHttpResponse(expectedJson); - - ContactHistory contactHistory = client.contactsApi().getHistory(100500L); - assertThat(jsonConverter.serialize(contactHistory), equalToIgnoringWhiteSpace(expectedJson)); - - HttpUriRequest arg = captor.getValue(); - assertEquals(HttpGet.METHOD_NAME, arg.getMethod()); - assertNull(extractHttpEntity(arg)); - } - - @Test - public void testGetContactHistoryByIdAndLimit() throws Exception { - String expectedJson = getJsonPayload(BASE_PATH + RESPONSES_PATH + "getContactHistory.json"); - ArgumentCaptor captor = mockHttpResponse(expectedJson); - - ContactHistory contactHistory = client.contactsApi().getHistory(100500L, 1L); - assertThat(jsonConverter.serialize(contactHistory), equalToIgnoringWhiteSpace(expectedJson)); - - HttpUriRequest arg = captor.getValue(); - assertEquals(HttpGet.METHOD_NAME, arg.getMethod()); - assertNull(extractHttpEntity(arg)); - assertThat(arg.getURI().toString(), containsString("limit=1")); - } - - @Test - public void testGetContactHistoryByIdAndAllFilters() throws Exception { - String expectedJson = getJsonPayload(BASE_PATH + RESPONSES_PATH + "getContactHistory.json"); - ArgumentCaptor captor = mockHttpResponse(expectedJson); - - ContactHistory contactHistory = client.contactsApi().getHistory(100500L, 1L, 5L); - assertThat(jsonConverter.serialize(contactHistory), equalToIgnoringWhiteSpace(expectedJson)); - - HttpUriRequest arg = captor.getValue(); - assertEquals(HttpGet.METHOD_NAME, arg.getMethod()); - assertNull(extractHttpEntity(arg)); - assertThat(arg.getURI().toString(), containsString("limit=1")); - assertThat(arg.getURI().toString(), containsString("offset=5")); - } } diff --git a/src/test/java/com/callfire/api/client/api/numbers/NumbersApiTest.java b/src/test/java/com/callfire/api/client/api/numbers/NumbersApiTest.java index 6942441..f6c9ff6 100644 --- a/src/test/java/com/callfire/api/client/api/numbers/NumbersApiTest.java +++ b/src/test/java/com/callfire/api/client/api/numbers/NumbersApiTest.java @@ -8,6 +8,7 @@ import com.callfire.api.client.api.numbers.model.Region; import com.callfire.api.client.api.numbers.model.request.FindNumberRegionsRequest; import com.callfire.api.client.api.numbers.model.request.FindNumbersLocalRequest; +import com.callfire.api.client.api.numbers.model.request.FindTollfreeNumbersRequest; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpUriRequest; import org.junit.Test; @@ -79,4 +80,22 @@ public void testFindNumbersTollfree() throws Exception { assertUriContainsQueryParams(arg.getURI(), "limit=1", "offset=2"); } + @Test + public void testFindNumbersTollfreeWithPattern() throws Exception { + String expectedJson = getJsonPayload(JSON_PATH + "/response/findNumbersTollfree.json"); + ArgumentCaptor captor = mockHttpResponse(expectedJson); + + FindTollfreeNumbersRequest request = FindTollfreeNumbersRequest.create() + .limit(1L) + .pattern("86*") + .build(); + List numbers = client.numbersApi().findNumbersTollfree(request); + assertThat(jsonConverter.serialize(new ListHolder<>(numbers)), equalToIgnoringWhiteSpace(expectedJson)); + + HttpUriRequest arg = captor.getValue(); + assertEquals(HttpGet.METHOD_NAME, arg.getMethod()); + assertNull(extractHttpEntity(arg)); + assertUriContainsQueryParams(arg.getURI(), "pattern=86*", "limit=1"); + } + }