Skip to content

Commit 5c8b935

Browse files
committed
vmalinovskiy: added dnc apis
1 parent 744d3d5 commit 5c8b935

File tree

8 files changed

+89
-45
lines changed

8 files changed

+89
-45
lines changed

Changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Callfire API client Changelog
22
=============================
3+
Version 1.7.14 - Jan 27 2017
4+
- added dnc apis
5+
36
Version 1.7.13 - Dec 30 2016
47
- minor fixes for get contacts history api
58

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.13
3+
version = 1.7.14

src/itest/java/com/callfire/api/client/integration/campaigns/TextAutoRepliesApiTest.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,10 @@ public void testCrudOperations() throws Exception {
3838
.build();
3939
Page<TextAutoReply> textAutoReplies = api.find(request);
4040
System.out.println(textAutoReplies);
41-
4241
assertTrue(textAutoReplies.getTotalCount() > 0);
4342
assertTrue(textAutoReplies.getItems().size() > 0);
44-
TextAutoReply savedTextAutoReply = textAutoReplies.getItems().get(textAutoReplies.getItems().size() - 1);
45-
assertEquals(resourceId.getId(), savedTextAutoReply.getId());
46-
assertEquals(textAutoReply.getNumber(), savedTextAutoReply.getNumber());
47-
assertEquals(textAutoReply.getMessage(), savedTextAutoReply.getMessage());
48-
assertEquals(textAutoReply.getMatch(), savedTextAutoReply.getMatch());
4943

50-
savedTextAutoReply = api.get(resourceId.getId(), "number,message");
44+
TextAutoReply savedTextAutoReply = api.get(resourceId.getId(), "number,message");
5145
System.out.println(savedTextAutoReply);
5246

5347
assertNull(savedTextAutoReply.getId());

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
package com.callfire.api.client.integration.contacts;
22

3+
import com.callfire.api.client.CallfireClient;
4+
import com.callfire.api.client.api.common.model.Page;
5+
import com.callfire.api.client.api.contacts.model.DoNotContact;
6+
import com.callfire.api.client.api.contacts.model.UniversalDnc;
7+
import com.callfire.api.client.api.contacts.model.request.CreateDncsRequest;
8+
import com.callfire.api.client.api.contacts.model.request.FindDncNumbersRequest;
9+
import com.callfire.api.client.api.contacts.model.request.FindUniversalDncsRequest;
10+
import com.callfire.api.client.api.contacts.model.request.UpdateDncRequest;
311
import com.callfire.api.client.integration.AbstractIntegrationTest;
12+
import org.junit.Assert;
13+
import org.junit.Test;
14+
15+
import java.util.Arrays;
16+
import java.util.List;
417

518
/**
619
* integration tests for /contacts/dncs api endpoint
720
*/
821
public class DncApiTest extends AbstractIntegrationTest {
922

10-
// TODO vmalinovskiy: uncomment when dnc apis will be tested and available on docs site
11-
/*@Test
23+
@Test
1224
public void testFind() throws Exception {
1325
CallfireClient client = getCallfireClient();
1426
FindDncNumbersRequest request = FindDncNumbersRequest.create()
@@ -98,6 +110,6 @@ public void testFindUniversalDncs() throws Exception {
98110
Assert.assertNotNull(uDncs.get(0).isOutboundCall());
99111
Assert.assertNotNull(uDncs.get(0).isInboundText());
100112
Assert.assertNotNull(uDncs.get(0).isOutboundText());
101-
}*/
113+
}
102114

103115
}

src/main/java/com/callfire/api/client/CallfireClient.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ public class CallfireClient {
9393
// contacts
9494
private ContactsApi contactsApi;
9595
private ContactListsApi contactListsApi;
96-
97-
// TODO vmalinovskiy: uncomment when dnc apis will be tested and available on docs site
9896
private DncApi dncApi;
99-
10097
// webhooks
10198
private SubscriptionsApi subscriptionsApi;
10299
private WebhooksApi webhooksApi;
@@ -401,18 +398,17 @@ public BatchesApi batchesApi() {
401398
return batchesApi;
402399
}
403400

404-
// TODO vmalinovskiy: uncomment when dnc apis will be tested and available on docs site
405401
/**
406402
* Get /contacts/do-not-calls api endpoint
407403
*
408404
* @return endpoint object
409-
*//*
405+
*/
410406
public DncApi dncApi() {
411407
if (dncApi == null) {
412408
dncApi = new DncApi(restApiClient);
413409
}
414410
return dncApi;
415-
}*/
411+
}
416412

417413
/**
418414
* Get /contacts/lists api endpoint

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

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
package com.callfire.api.client.api.contacts;
22

33
import com.callfire.api.client.*;
4+
import com.callfire.api.client.api.common.model.Page;
5+
import com.callfire.api.client.api.contacts.model.DoNotContact;
6+
import com.callfire.api.client.api.contacts.model.UniversalDnc;
7+
import com.callfire.api.client.api.contacts.model.request.CreateDncsRequest;
8+
import com.callfire.api.client.api.contacts.model.request.FindDncNumbersRequest;
9+
import com.callfire.api.client.api.contacts.model.request.FindUniversalDncsRequest;
10+
import com.callfire.api.client.api.contacts.model.request.UpdateDncRequest;
11+
import org.apache.commons.lang3.Validate;
12+
13+
import java.util.List;
14+
15+
import static com.callfire.api.client.ClientConstants.PLACEHOLDER;
16+
import static com.callfire.api.client.ModelType.*;
417

518
/**
619
* Represents /contacts/dncs endpoint
@@ -9,8 +22,7 @@
922
*/
1023
public class DncApi {
1124

12-
// TODO vmalinovskiy: uncomment when dnc apis will be tested and available on docs site
13-
/*private static final String DNC_PATH = "/contacts/dncs";
25+
private static final String DNC_PATH = "/contacts/dncs";
1426
private static final String DNC_SOURCES_PATH = "/contacts/dncs/sources/{}";
1527
private static final String UNIVERSAL_DNC_PATH = "/contacts/dncs/universals/{}";
1628
private static final String DNC_NUMBER_PATH = "/contacts/dncs/{}";
@@ -21,7 +33,7 @@ public DncApi(RestApiClient client) {
2133
this.client = client;
2234
}
2335

24-
*//**
36+
/**
2537
* Find all Do Not Contact (DNC) objects created by the user.
2638
* These DoNotContact entries only affect calls/texts/campaigns on this account.
2739
*
@@ -34,12 +46,12 @@ public DncApi(RestApiClient client) {
3446
* @throws InternalServerErrorException in case HTTP response code is 500 - Internal Server Error.
3547
* @throws CallfireApiException in case HTTP response code is something different from codes listed above.
3648
* @throws CallfireClientException in case error has occurred in client.
37-
*//*
49+
*/
3850
public Page<DoNotContact> find(FindDncNumbersRequest request) {
3951
return client.get(DNC_PATH, pageOf(DoNotContact.class), request);
4052
}
4153

42-
*//**
54+
/**
4355
* Get do not contact (dnc).
4456
*
4557
* @param number DNC number to get dnc for
@@ -51,12 +63,12 @@ public Page<DoNotContact> find(FindDncNumbersRequest request) {
5163
* @throws InternalServerErrorException in case HTTP response code is 500 - Internal Server Error.
5264
* @throws CallfireApiException in case HTTP response code is something different from codes listed above.
5365
* @throws CallfireClientException in case error has occurred in client.
54-
*//*
66+
*/
5567
public DoNotContact get(String number) {
5668
return client.get(DNC_NUMBER_PATH.replaceFirst(PLACEHOLDER, number), of(DoNotContact.class));
5769
}
5870

59-
*//**
71+
/**
6072
* Add Do Not Contact (DNC) entries.
6173
*
6274
* @param request DNC items to create
@@ -67,12 +79,12 @@ public DoNotContact get(String number) {
6779
* @throws InternalServerErrorException in case HTTP response code is 500 - Internal Server Error.
6880
* @throws CallfireApiException in case HTTP response code is something different from codes listed above.
6981
* @throws CallfireClientException in case error has occurred in client.
70-
*//*
82+
*/
7183
public void create(CreateDncsRequest request) {
7284
client.post(DNC_PATH, null, request);
7385
}
7486

75-
*//**
87+
/**
7688
* Update a Do Not Contact (DNC) value. Can toggle whether the DNC is enabled for calls/texts.
7789
*
7890
* @param request DNC update request
@@ -83,12 +95,12 @@ public void create(CreateDncsRequest request) {
8395
* @throws InternalServerErrorException in case HTTP response code is 500 - Internal Server Error.
8496
* @throws CallfireApiException in case HTTP response code is something different from codes listed above.
8597
* @throws CallfireClientException in case error has occurred in client.
86-
*//*
98+
*/
8799
public void update(UpdateDncRequest request) {
88100
client.put(DNC_NUMBER_PATH.replaceFirst(PLACEHOLDER, request.getNumber()), null, request);
89101
}
90102

91-
*//**
103+
/**
92104
* Delete a Do Not Contact (DNC) value.
93105
*
94106
* @param number DNC number to remove dnc for
@@ -99,13 +111,13 @@ public void update(UpdateDncRequest request) {
99111
* @throws InternalServerErrorException in case HTTP response code is 500 - Internal Server Error.
100112
* @throws CallfireApiException in case HTTP response code is something different from codes listed above.
101113
* @throws CallfireClientException in case error has occurred in client.
102-
*//*
114+
*/
103115
public void delete(String number) {
104116
Validate.notNull(number, "number cannot be null");
105117
client.delete(DNC_NUMBER_PATH.replaceFirst(PLACEHOLDER, number));
106118
}
107119

108-
*//**
120+
/**
109121
* Find universal do not contacts (udnc) associated with toNumber
110122
*
111123
* @param request find request with different properties to filter
@@ -117,12 +129,12 @@ public void delete(String number) {
117129
* @throws InternalServerErrorException in case HTTP response code is 500 - Internal Server Error.
118130
* @throws CallfireApiException in case HTTP response code is something different from codes listed above.
119131
* @throws CallfireClientException in case error has occurred in client.
120-
*//*
132+
*/
121133
public List<UniversalDnc> findUniversalDncs(FindUniversalDncsRequest request) {
122134
return client.get(UNIVERSAL_DNC_PATH.replaceFirst(PLACEHOLDER, request.getToNumber()), listHolderOf(UniversalDnc.class), request).getItems();
123135
}
124136

125-
*//**
137+
/**
126138
* Delete do not contact (dnc) numbers contained in source.
127139
*
128140
* @param source Source associated with Do Not Contact (DNC) entry.
@@ -133,10 +145,10 @@ public List<UniversalDnc> findUniversalDncs(FindUniversalDncsRequest request) {
133145
* @throws InternalServerErrorException in case HTTP response code is 500 - Internal Server Error.
134146
* @throws CallfireApiException in case HTTP response code is something different from codes listed above.
135147
* @throws CallfireClientException in case error has occurred in client.
136-
*//*
148+
*/
137149
public void deleteDncsFromSource(String source) {
138150
Validate.notNull(source, "number cannot be null");
139151
client.delete(DNC_SOURCES_PATH.replaceFirst(PLACEHOLDER, source));
140-
}*/
152+
}
141153

142154
}

src/main/java/com/callfire/api/client/api/contacts/model/DoNotContact.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
import com.callfire.api.client.api.common.model.CallfireModel;
44
import org.apache.commons.lang3.builder.ToStringBuilder;
55

6+
import java.util.Date;
7+
68
public class DoNotContact extends CallfireModel {
79
private String number;
810
private Boolean call;
911
private Boolean text;
10-
//private String source;
11-
//private Long campaignId;
12-
//private Date created;
13-
12+
private String source;
13+
private Long campaignId;
14+
private Date created;
1415

1516
public String getNumber() {
1617
return number;
@@ -24,12 +25,16 @@ public Boolean getText() {
2425
return text;
2526
}
2627

27-
public void setCall(Boolean call) {
28-
this.call = call;
28+
public String getSource() {
29+
return source;
30+
}
31+
32+
public Long getCampaignId() {
33+
return campaignId;
2934
}
3035

31-
public void setText(Boolean text) {
32-
this.text = text;
36+
public Date getCreated() {
37+
return created;
3338
}
3439

3540
@Override
@@ -39,6 +44,9 @@ public String toString() {
3944
.append("number", number)
4045
.append("call", call)
4146
.append("text", text)
47+
.append("source", source)
48+
.append("campaignId", campaignId)
49+
.append("created", created)
4250
.toString();
4351
}
4452
}

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
package com.callfire.api.client.api.contacts;
22

33
import com.callfire.api.client.api.AbstractApiTest;
4+
import com.callfire.api.client.api.common.model.ListHolder;
5+
import com.callfire.api.client.api.common.model.Page;
6+
import com.callfire.api.client.api.contacts.model.DoNotContact;
7+
import com.callfire.api.client.api.contacts.model.UniversalDnc;
8+
import com.callfire.api.client.api.contacts.model.request.CreateDncsRequest;
9+
import com.callfire.api.client.api.contacts.model.request.FindDncNumbersRequest;
10+
import com.callfire.api.client.api.contacts.model.request.FindUniversalDncsRequest;
11+
import com.callfire.api.client.api.contacts.model.request.UpdateDncRequest;
12+
import org.apache.http.client.methods.*;
13+
import org.junit.Before;
14+
import org.junit.Test;
15+
import org.mockito.ArgumentCaptor;
16+
import org.mockito.MockitoAnnotations;
17+
18+
import java.util.Arrays;
19+
import java.util.List;
20+
21+
import static org.hamcrest.Matchers.containsString;
22+
import static org.hamcrest.Matchers.equalToIgnoringWhiteSpace;
23+
import static org.junit.Assert.*;
424

525
public class DncApiTest extends AbstractApiTest {
626

7-
// TODO vmalinovskiy: uncomment when dnc apis will be tested and available on docs site
8-
/* protected static final String RESPONSES_PATH = "/contacts/dncApi/response/";
27+
protected static final String RESPONSES_PATH = "/contacts/dncApi/response/";
928
protected static final String REQUESTS_PATH = "/contacts/dncApi/request/";
1029

1130
@Before
@@ -146,5 +165,5 @@ public void testFindUniversalDncs() throws Exception {
146165
assertThat(arg.getURI().toString(), containsString("toNumber=12135551188"));
147166
assertThat(arg.getURI().toString(), containsString("fromNumber=18442800143"));
148167
assertThat(arg.getURI().toString(), containsString(ENCODED_FIELDS));
149-
}*/
168+
}
150169
}

0 commit comments

Comments
 (0)