Skip to content

Commit a790836

Browse files
authored
Merge pull request #57 from CallFire/develop
vmalinovskiy: minor fixes for get contacts history api
2 parents 49916a7 + 4d1a6d0 commit a790836

9 files changed

Lines changed: 117 additions & 117 deletions

File tree

Changelog.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
Callfire API client Changelog
22
=============================
3+
Version 1.7.13 - Dec 30 2016
4+
- minor fixes for get contacts history api
5+
36
Version 1.7.12 - Dec 28 2016
47
- updated CallRecord dto to include originateTime, answerTime, duration, callerName and switchId fields
58
- updated Webhook dto to include singleUse parameter
6-
- minor extension of requests objects for upload and find sounds api, get contacts history api and find tollfree numbers api
9+
- minor extension of requests objects for upload and find sounds api, find tollfree numbers api
710
- temporary turning dnc api off due to full remake of callfire dnc apis
811

912
Version 1.7.11 - Nov 17 2016

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
group = com.callfire
22
baseName = callfire-api-client
3-
version = 1.7.12
3+
version = 1.7.13

src/itest/java/com/callfire/api/client/integration/contacts/ContactsApiTest.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void testContactsCRUD() throws Exception {
8383
}
8484

8585
@Test
86-
public void testDeprecatedGetContactHistory() throws Exception {
86+
public void testGetContactHistory() throws Exception {
8787
CallfireClient client = getCallfireClient();
8888
GetByIdRequest request = GetByIdRequest.create()
8989
.id(1L)
@@ -94,12 +94,4 @@ public void testDeprecatedGetContactHistory() throws Exception {
9494
System.out.println(contactHistory);
9595
}
9696

97-
@Test
98-
public void testGetContactHistory() throws Exception {
99-
CallfireClient client = getCallfireClient();
100-
ContactHistory contactHistory = client.contactsApi().getHistory(1L);
101-
assertFalse(contactHistory.getCalls().isEmpty());
102-
103-
System.out.println(contactHistory);
104-
}
10597
}

src/itest/java/com/callfire/api/client/integration/numbers/NumbersApiTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.callfire.api.client.api.numbers.model.Region;
88
import com.callfire.api.client.api.numbers.model.request.FindNumberRegionsRequest;
99
import com.callfire.api.client.api.numbers.model.request.FindNumbersLocalRequest;
10+
import com.callfire.api.client.api.numbers.model.request.FindTollfreeNumbersRequest;
1011
import com.callfire.api.client.integration.AbstractIntegrationTest;
1112
import org.junit.Test;
1213

@@ -34,6 +35,24 @@ public void testFindTollfreeNumbers() throws Exception {
3435
System.out.println(numbers);
3536
}
3637

38+
@Test
39+
public void testFindTollfreeNumbersWithPattern() throws Exception {
40+
CallfireClient callfireClient = getCallfireClient();
41+
42+
FindTollfreeNumbersRequest request = FindTollfreeNumbersRequest.create()
43+
.limit(2L)
44+
.pattern("84*")
45+
.fields("items(number)")
46+
.build();
47+
List<Number> numbers = callfireClient.numbersApi().findNumbersTollfree(request);
48+
assertEquals(2, numbers.size());
49+
assertTrue(numbers.get(0).getNumber().contains("84"));
50+
assertTrue(numbers.get(1).getNumber().contains("84"));
51+
assertNull(numbers.get(0).getNationalFormat());
52+
assertNull(numbers.get(1).getRegion());
53+
System.out.println(numbers);
54+
}
55+
3756
@Test
3857
public void testFindNumbersLocal() throws Exception {
3958
CallfireClient callfireClient = getCallfireClient();

src/main/java/com/callfire/api/client/api/contacts/ContactsApi.java

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ public void delete(Long id) {
144144
}
145145

146146
/**
147-
* @deprecated this method doesn't work with fields parameter in request, please use getHistory method with id, limit and offset parameters
148-
*
149147
* Find all texts and calls attributed to a contact.
150148
*
151149
* @param request request to get particular contact's history
@@ -158,71 +156,10 @@ public void delete(Long id) {
158156
* @throws CallfireApiException in case HTTP response code is something different from codes listed above.
159157
* @throws CallfireClientException in case error has occurred in client.
160158
*/
161-
@Deprecated
162159
public ContactHistory getHistory(GetByIdRequest request) {
163160
Validate.notNull(request.getId(), "request.id cannot be null");
164161
String path = CONTACTS_ITEM_HISTORY_PATH.replaceFirst(PLACEHOLDER, request.getId().toString());
165162
return client.get(path, of(ContactHistory.class), request);
166163
}
167164

168-
/**
169-
* Find all texts and calls attributed to a contact.
170-
*
171-
* @param id contact id to get history for
172-
* @return returns a list of calls and texts a contact has been involved with.
173-
* @throws BadRequestException in case HTTP response code is 400 - Bad request, the request was formatted improperly.
174-
* @throws UnauthorizedException in case HTTP response code is 401 - Unauthorized, API Key missing or invalid.
175-
* @throws AccessForbiddenException in case HTTP response code is 403 - Forbidden, insufficient permissions.
176-
* @throws ResourceNotFoundException in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist.
177-
* @throws InternalServerErrorException in case HTTP response code is 500 - Internal Server Error.
178-
* @throws CallfireApiException in case HTTP response code is something different from codes listed above.
179-
* @throws CallfireClientException in case error has occurred in client.
180-
*/
181-
public ContactHistory getHistory(Long id) {
182-
return getHistory(id, null, null);
183-
}
184-
185-
/**
186-
* Find all texts and calls attributed to a contact.
187-
*
188-
* @param id contact id to get history for
189-
* @param limit maximum number of calls/texts records to return in response
190-
* @return returns a list of calls and texts a contact has been involved with.
191-
* @throws BadRequestException in case HTTP response code is 400 - Bad request, the request was formatted improperly.
192-
* @throws UnauthorizedException in case HTTP response code is 401 - Unauthorized, API Key missing or invalid.
193-
* @throws AccessForbiddenException in case HTTP response code is 403 - Forbidden, insufficient permissions.
194-
* @throws ResourceNotFoundException in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist.
195-
* @throws InternalServerErrorException in case HTTP response code is 500 - Internal Server Error.
196-
* @throws CallfireApiException in case HTTP response code is something different from codes listed above.
197-
* @throws CallfireClientException in case error has occurred in client.
198-
*/
199-
public ContactHistory getHistory(Long id, Long limit) {
200-
return getHistory(id, limit, null);
201-
}
202-
203-
/**
204-
* Find all texts and calls attributed to a contact.
205-
*
206-
* @param id contact id to get history for
207-
* @param limit maximum number of calls/texts records to return in response
208-
* @param offset offset to the start of a given page
209-
* @return returns a list of calls and texts a contact has been involved with.
210-
* @throws BadRequestException in case HTTP response code is 400 - Bad request, the request was formatted improperly.
211-
* @throws UnauthorizedException in case HTTP response code is 401 - Unauthorized, API Key missing or invalid.
212-
* @throws AccessForbiddenException in case HTTP response code is 403 - Forbidden, insufficient permissions.
213-
* @throws ResourceNotFoundException in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist.
214-
* @throws InternalServerErrorException in case HTTP response code is 500 - Internal Server Error.
215-
* @throws CallfireApiException in case HTTP response code is something different from codes listed above.
216-
* @throws CallfireClientException in case error has occurred in client.
217-
*/
218-
public ContactHistory getHistory(Long id, Long limit, Long offset) {
219-
Validate.notNull(id, "id cannot be null");
220-
221-
List<NameValuePair> queryParams = new ArrayList<>(1);
222-
addQueryParamIfSet("limit", limit, queryParams);
223-
addQueryParamIfSet("offset", offset, queryParams);
224-
225-
String path = CONTACTS_ITEM_HISTORY_PATH.replaceFirst(PLACEHOLDER, id.toString());
226-
return client.get(path, of(ContactHistory.class), queryParams);
227-
}
228165
}

src/main/java/com/callfire/api/client/api/numbers/NumbersApi.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.callfire.api.client.api.numbers.model.Region;
88
import com.callfire.api.client.api.numbers.model.request.FindNumberRegionsRequest;
99
import com.callfire.api.client.api.numbers.model.request.FindNumbersLocalRequest;
10+
import com.callfire.api.client.api.numbers.model.request.FindTollfreeNumbersRequest;
1011

1112
import java.util.List;
1213

@@ -65,6 +66,8 @@ public Page<Region> findNumberRegions(FindNumberRegionsRequest request) {
6566
}
6667

6768
/**
69+
* @deprecated this method doesn't work with offset parameter in request, please use findNumbersTollfree method with FindTollfreeNumbersRequest instead
70+
*
6871
* Find numbers in the CallFire tollfree numbers catalog that are available for purchase.
6972
*
7073
* @param request request payload
@@ -77,7 +80,25 @@ public Page<Region> findNumberRegions(FindNumberRegionsRequest request) {
7780
* @throws CallfireApiException in case HTTP response code is something different from codes listed above.
7881
* @throws CallfireClientException in case error has occurred in client.
7982
*/
83+
@Deprecated
8084
public List<Number> findNumbersTollfree(CommonFindRequest request) {
8185
return client.get(NUMBERS_TOLLFREE_PATH, listHolderOf(Number.class), request).getItems();
8286
}
87+
88+
/**
89+
* Find numbers in the CallFire tollfree numbers catalog that are available for purchase.
90+
*
91+
* @param request request payload
92+
* @return list of {@link Number}
93+
* @throws BadRequestException in case HTTP response code is 400 - Bad request, the request was formatted improperly.
94+
* @throws UnauthorizedException in case HTTP response code is 401 - Unauthorized, API Key missing or invalid.
95+
* @throws AccessForbiddenException in case HTTP response code is 403 - Forbidden, insufficient permissions.
96+
* @throws ResourceNotFoundException in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist.
97+
* @throws InternalServerErrorException in case HTTP response code is 500 - Internal Server Error.
98+
* @throws CallfireApiException in case HTTP response code is something different from codes listed above.
99+
* @throws CallfireClientException in case error has occurred in client.
100+
*/
101+
public List<Number> findNumbersTollfree(FindTollfreeNumbersRequest request) {
102+
return client.get(NUMBERS_TOLLFREE_PATH, listHolderOf(Number.class), request).getItems();
103+
}
83104
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.callfire.api.client.api.numbers.model.request;
2+
3+
import com.callfire.api.client.api.common.model.CallfireModel;
4+
import com.callfire.api.client.api.common.model.request.AbstractBuilder;
5+
import org.apache.commons.lang3.builder.ToStringBuilder;
6+
7+
public class FindTollfreeNumbersRequest extends CallfireModel {
8+
private String pattern;
9+
private Long limit;
10+
private String fields;
11+
12+
private FindTollfreeNumbersRequest() {
13+
}
14+
15+
public static Builder create() {
16+
return new Builder();
17+
}
18+
19+
20+
@Override
21+
public String toString() {
22+
return new ToStringBuilder(this)
23+
.append("pattern", pattern)
24+
.append("limit", limit)
25+
.append("fields", fields)
26+
.toString();
27+
}
28+
29+
public static class Builder extends AbstractBuilder<FindTollfreeNumbersRequest> {
30+
31+
private Builder() {
32+
super(new FindTollfreeNumbersRequest());
33+
}
34+
35+
public Builder pattern(String pattern) {
36+
request.pattern = pattern;
37+
return this;
38+
}
39+
40+
public Builder limit(Long limit) {
41+
request.limit = limit;
42+
return this;
43+
}
44+
45+
public Builder fields(String fields) {
46+
request.fields = fields;
47+
return this;
48+
}
49+
}
50+
}

src/test/java/com/callfire/api/client/api/contacts/ContactsApiTest.java

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ public void testDelete() throws Exception {
137137
}
138138

139139
@Test
140-
public void testDeprecatedGetContactHistoryByNullId() throws Exception {
140+
public void testGetContactHistoryByNullId() throws Exception {
141141
ex.expectMessage(EMPTY_REQUEST_ID_MSG);
142142
ex.expect(NullPointerException.class);
143143
client.contactsApi().getHistory(GetByIdRequest.create().build());
144144
}
145145

146146
@Test
147-
public void testDeprecatedGetContactHistory() throws Exception {
147+
public void testGetContactHistory() throws Exception {
148148
String expectedJson = getJsonPayload(BASE_PATH + RESPONSES_PATH + "getContactHistory.json");
149149
ArgumentCaptor<HttpUriRequest> captor = mockHttpResponse(expectedJson);
150150

@@ -163,45 +163,4 @@ public void testDeprecatedGetContactHistory() throws Exception {
163163
assertThat(arg.getURI().toString(), containsString("offset=5"));
164164
}
165165

166-
@Test
167-
public void testGetContactHistoryById() throws Exception {
168-
String expectedJson = getJsonPayload(BASE_PATH + RESPONSES_PATH + "getContactHistory.json");
169-
ArgumentCaptor<HttpUriRequest> captor = mockHttpResponse(expectedJson);
170-
171-
ContactHistory contactHistory = client.contactsApi().getHistory(100500L);
172-
assertThat(jsonConverter.serialize(contactHistory), equalToIgnoringWhiteSpace(expectedJson));
173-
174-
HttpUriRequest arg = captor.getValue();
175-
assertEquals(HttpGet.METHOD_NAME, arg.getMethod());
176-
assertNull(extractHttpEntity(arg));
177-
}
178-
179-
@Test
180-
public void testGetContactHistoryByIdAndLimit() throws Exception {
181-
String expectedJson = getJsonPayload(BASE_PATH + RESPONSES_PATH + "getContactHistory.json");
182-
ArgumentCaptor<HttpUriRequest> captor = mockHttpResponse(expectedJson);
183-
184-
ContactHistory contactHistory = client.contactsApi().getHistory(100500L, 1L);
185-
assertThat(jsonConverter.serialize(contactHistory), equalToIgnoringWhiteSpace(expectedJson));
186-
187-
HttpUriRequest arg = captor.getValue();
188-
assertEquals(HttpGet.METHOD_NAME, arg.getMethod());
189-
assertNull(extractHttpEntity(arg));
190-
assertThat(arg.getURI().toString(), containsString("limit=1"));
191-
}
192-
193-
@Test
194-
public void testGetContactHistoryByIdAndAllFilters() throws Exception {
195-
String expectedJson = getJsonPayload(BASE_PATH + RESPONSES_PATH + "getContactHistory.json");
196-
ArgumentCaptor<HttpUriRequest> captor = mockHttpResponse(expectedJson);
197-
198-
ContactHistory contactHistory = client.contactsApi().getHistory(100500L, 1L, 5L);
199-
assertThat(jsonConverter.serialize(contactHistory), equalToIgnoringWhiteSpace(expectedJson));
200-
201-
HttpUriRequest arg = captor.getValue();
202-
assertEquals(HttpGet.METHOD_NAME, arg.getMethod());
203-
assertNull(extractHttpEntity(arg));
204-
assertThat(arg.getURI().toString(), containsString("limit=1"));
205-
assertThat(arg.getURI().toString(), containsString("offset=5"));
206-
}
207166
}

src/test/java/com/callfire/api/client/api/numbers/NumbersApiTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.callfire.api.client.api.numbers.model.Region;
99
import com.callfire.api.client.api.numbers.model.request.FindNumberRegionsRequest;
1010
import com.callfire.api.client.api.numbers.model.request.FindNumbersLocalRequest;
11+
import com.callfire.api.client.api.numbers.model.request.FindTollfreeNumbersRequest;
1112
import org.apache.http.client.methods.HttpGet;
1213
import org.apache.http.client.methods.HttpUriRequest;
1314
import org.junit.Test;
@@ -79,4 +80,22 @@ public void testFindNumbersTollfree() throws Exception {
7980
assertUriContainsQueryParams(arg.getURI(), "limit=1", "offset=2");
8081
}
8182

83+
@Test
84+
public void testFindNumbersTollfreeWithPattern() throws Exception {
85+
String expectedJson = getJsonPayload(JSON_PATH + "/response/findNumbersTollfree.json");
86+
ArgumentCaptor<HttpUriRequest> captor = mockHttpResponse(expectedJson);
87+
88+
FindTollfreeNumbersRequest request = FindTollfreeNumbersRequest.create()
89+
.limit(1L)
90+
.pattern("86*")
91+
.build();
92+
List<Number> numbers = client.numbersApi().findNumbersTollfree(request);
93+
assertThat(jsonConverter.serialize(new ListHolder<>(numbers)), equalToIgnoringWhiteSpace(expectedJson));
94+
95+
HttpUriRequest arg = captor.getValue();
96+
assertEquals(HttpGet.METHOD_NAME, arg.getMethod());
97+
assertNull(extractHttpEntity(arg));
98+
assertUriContainsQueryParams(arg.getURI(), "pattern=86*", "limit=1");
99+
}
100+
82101
}

0 commit comments

Comments
 (0)