Skip to content

Commit

Permalink
Merge pull request #56 from CallFire/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
vmalinovskiy authored Dec 30, 2016
2 parents 5b05804 + d411f06 commit 49916a7
Show file tree
Hide file tree
Showing 42 changed files with 1,166 additions and 255 deletions.
6 changes: 6 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Callfire API client Changelog
=============================
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
- temporary turning dnc api off due to full remake of callfire dnc apis

Version 1.7.11 - Nov 17 2016
- added deleteCampaignSound api
- added getCreditsHistory api
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.11
version = 1.7.12
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public void testCrudOperations() throws Exception {

AgentGroup agentGroup1 = new AgentGroup();
agentGroup1.setId(2L);
agentGroup1.setName("test-group01");
agentGroup1.setName("test-group001");
ResourceId groupId1 = agentGroupsApi.create(agentGroup1);
AgentGroup savedGroup1 = agentGroupsApi.get(groupId1.getId());
assertEquals(groupId1.getId(), savedGroup1.getId());
assertEquals(agentGroup1.getName(), savedGroup1.getName());
assertThat(agentGroup1.getAgents(), is(empty()));

AgentGroup agentGroup2 = new AgentGroup();
agentGroup2.setName("test-group02");
agentGroup2.setName("test-group002");
ResourceId groupId2 = agentGroupsApi.create(agentGroup2);
AgentGroup savedGroup2 = agentGroupsApi.get(groupId2.getId(), "name,campaignIds");
assertNull(savedGroup2.getId());
Expand All @@ -53,7 +53,7 @@ public void testCrudOperations() throws Exception {
.limit(100L)
.offset(0L)
.fields("items(id)")
.name("test-group0")
.name("test-group00")
.build();
Page<AgentGroup> agentGroupPage = agentGroupsApi.find(request);
List<AgentGroup> items = agentGroupPage.getItems();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public void testFind() throws Exception {
FindSoundsRequest request = FindSoundsRequest.create()
.limit(3L)
.filter("sample")
.includeArchived(true)
.includeScrubbed(true)
.includePending(true)
.build();
Page<CampaignSound> campaignSounds = callfireClient.campaignSoundsApi().find(request);
assertEquals(Long.valueOf(4), campaignSounds.getTotalCount());
Expand Down Expand Up @@ -73,7 +76,11 @@ public void testUploadMp3WavFilesAndGetThem() throws Exception {
assertNotNull(mp3ResourceId.getId());
assertNotNull(wavResourceId.getId());

CampaignSound mp3Sound = campaignSoundsApi.uploadAndGetSoundDetails(mp3File, soundName);
CampaignSound mp3Sound = campaignSoundsApi.uploadAndGetSoundDetails(mp3File, soundName, "id,name,created,lengthInSeconds,status,duplicate");
assertTrue(mp3Sound.getDuplicate());
mp3Sound = campaignSoundsApi.uploadAndGetSoundDetails(mp3File);
assertTrue(mp3Sound.getDuplicate());
mp3Sound = campaignSoundsApi.uploadAndGetSoundDetails(mp3File, soundName);
assertTrue(mp3Sound.getDuplicate());
// get sound metadata
CampaignSound campaignSound = campaignSoundsApi.get(mp3ResourceId.getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void testContactsCRUD() throws Exception {
}

@Test
public void testGetContactHistory() throws Exception {
public void testDeprecatedGetContactHistory() throws Exception {
CallfireClient client = getCallfireClient();
GetByIdRequest request = GetByIdRequest.create()
.id(1L)
Expand All @@ -93,4 +93,13 @@ public void testGetContactHistory() 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
@@ -1,39 +1,103 @@
package com.callfire.api.client.integration.contacts;

import com.callfire.api.client.CallfireClient;
import com.callfire.api.client.api.common.model.Page;
import com.callfire.api.client.api.contacts.model.DoNotContact;
import com.callfire.api.client.api.contacts.model.request.FindDncContactsRequest;
import com.callfire.api.client.integration.AbstractIntegrationTest;
import org.junit.Assert;
import org.junit.Test;

/**
* integration tests for /contacts/dncs api endpoint
*/
public class DncApiTest extends AbstractIntegrationTest {

@Test
// TODO vmalinovskiy: uncomment when dnc apis will be tested and available on docs site
/*@Test
public void testFind() throws Exception {
FindDncContactsRequest request = FindDncContactsRequest.create()
.textDnc(true)
CallfireClient client = getCallfireClient();
FindDncNumbersRequest request = FindDncNumbersRequest.create()
.text(true)
.limit(1L)
.numbers(Arrays.asList("12135551189"))
.build();
CallfireClient client = getCallfireClient();
Page<DoNotContact> dncContacts = client.dncApi().find(request);
System.out.println(dncContacts);
Assert.assertEquals(1, dncContacts.getItems().size());
}
@Test
public void testUpdate() throws Exception {
public void testCrudAndGetDnc() throws Exception {
CallfireClient client = getCallfireClient();
CreateDncsRequest crRequest = CreateDncsRequest.create()
.call(true)
.text(true)
.numbers(Arrays.asList("12135551188"))
.source("testSource")
.build();
client.dncApi().create(crRequest);
DoNotContact dnc = client.dncApi().get("12135551188");
Assert.assertEquals(dnc.getNumber(), "12135551188");
Assert.assertEquals(dnc.getCall(), true);
Assert.assertEquals(dnc.getText(), true);
UpdateDncRequest updRequest = UpdateDncRequest.create()
.call(true)
.text(false)
.number("12135551188")
.build();
client.dncApi().update(updRequest);
dnc = client.dncApi().get("12135551188");
Assert.assertEquals(dnc.getCall(), true);
Assert.assertEquals(dnc.getText(), false);
client.dncApi().delete("12135551188");
dnc = client.dncApi().get("12135551188");
Assert.assertEquals(dnc.getCall(), false);
Assert.assertEquals(dnc.getText(), false);
}
@Test
public void testDeleteDncsFromSource() throws Exception {
CallfireClient client = getCallfireClient();
DoNotContact number = new DoNotContact();
number.setListId(2109601003L);
number.setNumber("12234565432");
number.setCall(true);
number.setText(true);
client.dncApi().update(number);
CreateDncsRequest crRequest = CreateDncsRequest.create()
.call(true)
.text(true)
.numbers(Arrays.asList("12135551189"))
.source("testSourceForDeleteDncs")
.build();
client.dncApi().create(crRequest);
FindDncNumbersRequest request = FindDncNumbersRequest.create()
.source("testSourceForDeleteDncs")
.build();
Page<DoNotContact> dncContacts = client.dncApi().find(request);
Assert.assertTrue(dncContacts.getItems().size() > 0);
client.dncApi().deleteDncsFromSource("testSourceForDeleteDncs");
dncContacts = client.dncApi().find(request);
Assert.assertTrue(dncContacts.getItems().size() == 0);
}
@Test
public void testFindUniversalDncs() throws Exception {
CallfireClient client = getCallfireClient();
FindUniversalDncsRequest request = FindUniversalDncsRequest.create()
.toNumber("12135551188")
.fromNumber("18442800143")
.build();
List<UniversalDnc> uDncs = client.dncApi().findUniversalDncs(request);
Assert.assertEquals("18442800143", uDncs.get(0).getFromNumber());
Assert.assertEquals("12135551188", uDncs.get(0).getToNumber());
Assert.assertNotNull(uDncs.get(0).isInboundCall());
Assert.assertNotNull(uDncs.get(0).isOutboundCall());
Assert.assertNotNull(uDncs.get(0).isInboundText());
Assert.assertNotNull(uDncs.get(0).isOutboundText());
}*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

/**
* integration tests for /numbers api endpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void testCrudOperations() throws Exception {
ResourceType.ResourceEvent[] ev = {ResourceType.ResourceEvent.STARTED};
webhook.setEvents(new TreeSet<>(Arrays.asList(ev)));
webhook.setName("test_name1");
webhook.setSingleUse(true);
ResourceId resourceId1 = api.create(webhook);
assertNotNull(resourceId1.getId());
webhook.setName("test_name2");
Expand All @@ -45,7 +46,7 @@ public void testCrudOperations() throws Exception {
FindWebhooksRequest findRequest = FindWebhooksRequest.create()
.limit(30L)
.name("test_name1")
.fields("items(id,callback,name,resource,events)")
.fields("items(id,callback,name,resource,events,singleUse)")
.build();
Page<Webhook> page = api.find(findRequest);
assertTrue(page.getItems().size() > 0);
Expand All @@ -54,6 +55,7 @@ public void testCrudOperations() throws Exception {
assertNotNull(page.getItems().get(0).getId());
assertEquals(ResourceType.TEXT_BROADCAST, page.getItems().get(0).getResource());
assertEquals(1, page.getItems().get(0).getEvents().size());
assertTrue(page.getItems().get(0).getSingleUse());

findRequest = FindWebhooksRequest.create()
.limit(30L)
Expand All @@ -63,9 +65,11 @@ public void testCrudOperations() throws Exception {

webhook = page.getItems().get(0);
webhook.setName("test_name2");
webhook.setSingleUse(false);
api.update(webhook);
Webhook updated = api.get(webhook.getId());
assertEquals(webhook.getResource(), updated.getResource());
assertFalse(page.getItems().get(0).getSingleUse());

api.delete(resourceId1.getId());
api.delete(resourceId2.getId());
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/callfire/api/client/CallfireClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ public class CallfireClient {
// contacts
private ContactsApi contactsApi;
private ContactListsApi contactListsApi;

// TODO vmalinovskiy: uncomment when dnc apis will be tested and available on docs site
private DncApi dncApi;

// webhooks
private SubscriptionsApi subscriptionsApi;
private WebhooksApi webhooksApi;
Expand Down Expand Up @@ -398,17 +401,18 @@ public BatchesApi batchesApi() {
return batchesApi;
}

// TODO vmalinovskiy: uncomment when dnc apis will be tested and available on docs site
/**
* Get /contacts/do-not-calls api endpoint
*
* @return endpoint object
*/
*//*
public DncApi dncApi() {
if (dncApi == null) {
dncApi = new DncApi(restApiClient);
}
return dncApi;
}
}*/

/**
* Get /contacts/lists api endpoint
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/callfire/api/client/ModelType.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ private static void initSimpleTypes() {
SIMPLE_TYPES.put(Webhook.class, new TypeReference<Webhook>() {});
SIMPLE_TYPES.put(WebhookResource.class, new TypeReference<WebhookResource>() {});
SIMPLE_TYPES.put(CallRecording.class, new TypeReference<CallRecording>() {});
SIMPLE_TYPES.put(UniversalDnc.class, new TypeReference<UniversalDnc>() {});
SIMPLE_TYPES.put(DoNotContact.class, new TypeReference<DoNotContact>() {});
// @formatter:on
}

Expand Down
51 changes: 45 additions & 6 deletions src/main/java/com/callfire/api/client/RestApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public <T> T post(String path, TypeReference<T> type) {
*
* @param path request path
* @param type response entity type
* @param params request parameters
* @param fileDataParams request parameters
* @param <T> response entity type
* @return pojo mapped from json
* @throws BadRequestException in case HTTP response code is 400 - Bad request, the request was formatted improperly.
Expand All @@ -196,19 +196,58 @@ public <T> T post(String path, TypeReference<T> type) {
* @throws CallfireApiException in case HTTP response code is something different from codes listed above.
* @throws CallfireClientException in case error has occurred in client.
*/
public <T> T postFile(String path, TypeReference<T> type, Map<String, ?> params) {
public <T> T postFile(String path, TypeReference<T> type, Map<String, ?> fileDataParams) {
try {
String uri = getApiBasePath() + path;
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
File file = (File) params.get("file");
File file = (File) fileDataParams.get("file");
String mimeType = MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(file.getName());
entityBuilder.addBinaryBody("file", file, ContentType.create(mimeType), file.getName());
if (params.get("name") != null) {
entityBuilder.addTextBody("name", (String) params.get("name"));
if (fileDataParams.get("name") != null) {
entityBuilder.addTextBody("name", (String) fileDataParams.get("name"));
}
RequestBuilder requestBuilder = RequestBuilder.post(uri).setEntity(entityBuilder.build());
LOGGER.debug("POST file upload request to {} with params {}", uri, params);
LOGGER.debug("POST file upload request to {} with params {}", uri, fileDataParams);

return doRequest(requestBuilder, type);
} catch (IOException e) {
throw new CallfireClientException(e);
}
}

/**
* Performs POST request with binary body to specified path
*
* @param path request path
* @param type response entity type
* @param fileDataParams request parameters
* @param queryParams query parameters
* @param <T> response entity type
* @return pojo mapped from json
* @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 <T> T postFile(String path, TypeReference<T> type, Map<String, ?> fileDataParams, List<NameValuePair> queryParams) {
try {
String uri = getApiBasePath() + path;
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
File file = (File) fileDataParams.get("file");
String mimeType = MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(file.getName());
entityBuilder.addBinaryBody("file", file, ContentType.create(mimeType), file.getName());
if (fileDataParams.get("name") != null) {
entityBuilder.addTextBody("name", (String) fileDataParams.get("name"));
}
RequestBuilder requestBuilder = RequestBuilder.post(uri)
.setEntity(entityBuilder.build())
.addParameters(queryParams.toArray(new NameValuePair[queryParams.size()]));;
LOGGER.debug("POST file upload request to {} with params {}", uri, fileDataParams);

return doRequest(requestBuilder, type);
} catch (IOException e) {
Expand Down
Loading

0 comments on commit 49916a7

Please sign in to comment.