Skip to content

Commit

Permalink
Merge pull request #57 from CallFire/develop
Browse files Browse the repository at this point in the history
vmalinovskiy: minor fixes for get contacts history api
  • Loading branch information
vmalinovskiy authored Dec 30, 2016
2 parents 49916a7 + 4d1a6d0 commit a790836
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 117 deletions.
5 changes: 4 additions & 1 deletion Changelog.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
group = com.callfire
baseName = callfire-api-client
version = 1.7.12
version = 1.7.13
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Number> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<NameValuePair> 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);
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/callfire/api/client/api/numbers/NumbersApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -65,6 +66,8 @@ public Page<Region> 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
Expand All @@ -77,7 +80,25 @@ public Page<Region> 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<Number> 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<Number> findNumbersTollfree(FindTollfreeNumbersRequest request) {
return client.get(NUMBERS_TOLLFREE_PATH, listHolderOf(Number.class), request).getItems();
}
}
Original file line number Diff line number Diff line change
@@ -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<FindTollfreeNumbersRequest> {

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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpUriRequest> captor = mockHttpResponse(expectedJson);

Expand All @@ -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<HttpUriRequest> 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<HttpUriRequest> 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<HttpUriRequest> 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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<HttpUriRequest> captor = mockHttpResponse(expectedJson);

FindTollfreeNumbersRequest request = FindTollfreeNumbersRequest.create()
.limit(1L)
.pattern("86*")
.build();
List<Number> 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");
}

}

0 comments on commit a790836

Please sign in to comment.