From 062845079856698ab332dbfb822fe59e4aa1ecef Mon Sep 17 00:00:00 2001 From: vmalinovskiy Date: Fri, 27 May 2016 12:43:22 +0300 Subject: [PATCH 1/2] vmalinovskiy - updated client to last api version --- CallfireApiClient.nuspec | 19 ++- Changelog.txt | 15 +- docs/api/callstexts/CallsApi.adoc | 80 +++++++++- docs/api/callstexts/TextsApi.adoc | 17 ++ docs/api/campaigns/CallBroadcastsApi.adoc | 11 +- docs/api/campaigns/CampaignSoundsApi.adoc | 26 ++- docs/api/campaigns/TextBroadcastsApi.adoc | 9 +- docs/api/webhooks/WebhooksApi.adoc | 20 ++- .../Api/CallsTexts/CallRecording.cs | 15 ++ .../Api/CallsTexts/CallsApiTest.cs | 151 +++++++++++++++++- .../Api/CallsTexts/TextsApiTest.cs | 30 ++++ .../Api/Campaigns/CallBroadcastsApiTest.cs | 34 +++- .../Api/Campaigns/CampaignSoundsApiTest.cs | 72 ++++++++- .../Api/Campaigns/TextBroadcastsApiTest.cs | 34 +++- .../Api/Webhooks/WebhooksApiTest.cs | 29 +++- .../CallfireApiClient.Tests.csproj | 10 ++ .../Integration/AbstractIntegrationTest.cs | 2 +- .../CallsTexts/CallsApiIntegrationTest.cs | 91 ++++++++++- .../CallsTexts/TextsApiIntegrationTest.cs | 13 ++ .../CallBroadcastsApiIntegrationTest.cs | 16 +- .../CampaignSoundsApiIntegrationTest.cs | 19 +++ .../TextBroadcastsApiIntegrationTest.cs | 13 +- .../Keywords/KeywordsApiIntegrationTest.cs | 2 +- .../Webhooks/WebhooksApiIntegrationTest.cs | 27 +++- .../callsApi/request/sendCalls.json | 5 +- .../callsApi/response/getCallRecording.json | 12 ++ .../callsApi/response/getCallRecordings.json | 28 ++++ .../request/createCallBroadcast.json | 1 + .../request/updateCallBroadcast.json | 1 + .../response/findCallBroadcasts.json | 2 + .../response/getCallBroadcast.json | 1 + .../response/uploadSoundWithDetails.json | 6 + .../request/createTextBroadcast.json | 1 + .../request/updateTextBroadcast.json | 1 + .../response/findTextBroadcasts.json | 2 + .../response/getTextBroadcast.json | 1 + .../webhooksApi/request/createWebhook.json | 6 +- .../webhooksApi/request/updateWebhook.json | 4 +- .../response/findSpecificWebhookResource.json | 8 + .../response/findWebhookResources.json | 66 ++++++++ .../webhooksApi/response/findWebhooks.json | 12 +- .../webhooksApi/response/getWebhook.json | 6 +- .../Api/CallsTexts/CallsApi.cs | 136 +++++++++++++++- .../Api/CallsTexts/Model/CallRecipient.cs | 8 +- .../Model/Request/SendCallsRequest.cs | 43 +++++ .../Model/Request/SendTextsRequest.cs | 35 ++++ .../Api/CallsTexts/TextsApi.cs | 22 +++ .../Api/Campaigns/CallBroadcastsApi.cs | 19 +++ .../Api/Campaigns/CampaignSoundsApi.cs | 62 +++++++ .../Api/Campaigns/Model/Broadcast.cs | 6 +- .../Api/Campaigns/Model/CampaignSound.cs | 7 +- .../Request/GetBroadcastCallsTextsRequest.cs | 17 ++ .../Api/Campaigns/TextBroadcastsApi.cs | 19 +++ .../Api/Webhooks/Model/ResourceType.cs | 35 ++-- .../Api/Webhooks/Model/Webhook.cs | 12 +- .../Api/Webhooks/Model/WebhookResource.cs | 19 +++ .../Api/Webhooks/WebhooksApi.cs | 45 +++++- .../CallfireApiClient.csproj | 4 + .../Properties/AssemblyInfo.cs | 2 +- 59 files changed, 1327 insertions(+), 82 deletions(-) create mode 100644 src/CallfireApiClient.Tests/Api/CallsTexts/CallRecording.cs create mode 100644 src/CallfireApiClient.Tests/JsonMocks/callstexts/callsApi/response/getCallRecording.json create mode 100644 src/CallfireApiClient.Tests/JsonMocks/callstexts/callsApi/response/getCallRecordings.json create mode 100644 src/CallfireApiClient.Tests/JsonMocks/campaigns/campaignSoundsApi/response/uploadSoundWithDetails.json create mode 100644 src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/response/findSpecificWebhookResource.json create mode 100644 src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/response/findWebhookResources.json create mode 100644 src/CallfireApiClient/Api/CallsTexts/Model/Request/SendCallsRequest.cs create mode 100644 src/CallfireApiClient/Api/CallsTexts/Model/Request/SendTextsRequest.cs create mode 100644 src/CallfireApiClient/Api/Campaigns/Model/Request/GetBroadcastCallsTextsRequest.cs create mode 100644 src/CallfireApiClient/Api/Webhooks/Model/WebhookResource.cs diff --git a/CallfireApiClient.nuspec b/CallfireApiClient.nuspec index 64c0740..bc4938b 100644 --- a/CallfireApiClient.nuspec +++ b/CallfireApiClient.nuspec @@ -1,7 +1,7 @@ CallfireApiClient - 1.1.7 + 1.1.8 CallFire API v2 client Vladimir Mikhailov @@ -15,9 +15,22 @@ C# client library for integration with Callfire REST API v2 services Callfire API client Changelog ============================= +Version 1.1.8 - May 27 2016 + - defaultLiveMessage, defaultMachineMessage, defaultLiveMessageSoundId, defaultMachineMessageSoundId, defaultVoice params added to send calls api + - added batch id filter parameter for get broadcast calls/texts + - added fields filter parameter for add sound via call, returns CampaignSound object + - added fields filter parameter for add sound via text-to-speech, returns CampaignSound object + - defaultMessage parameter added to send texts function + - added findWebhookResource and findWebhookResources methods to use new webhooks apis + - resumeNextDay parameter added to CallBroadcast object + - transferMessage, transferMessageSoundId, transferDigit, transferNumber params added to CallRecipient object for sending calls and texts + - added questionResponses parameter to CallRecord object + - added duplicate parameter to CampaignSound object + - get call recordings api functions implemented in CallsApi + Version 1.1.7 - Apr 18 2016 - migration to 4.5 net framework - - migration to gradle + - migration to gradle Version 1.1.6 - Mar 25 2016 - added mono debug files generation on Windows platform @@ -60,5 +73,7 @@ Version 1.0.0 - Dec 29 2015 + + diff --git a/Changelog.txt b/Changelog.txt index b58a6f7..adb8518 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,8 +1,21 @@ Callfire API client Changelog ============================= +Version 1.1.8 - May 27 2016 + - defaultLiveMessage, defaultMachineMessage, defaultLiveMessageSoundId, defaultMachineMessageSoundId, defaultVoice params added to send calls api + - added batch id filter parameter for get broadcast calls/texts + - added fields filter parameter for add sound via call, returns CampaignSound object + - added fields filter parameter for add sound via text-to-speech, returns CampaignSound object + - defaultMessage parameter added to send texts function + - added findWebhookResource and findWebhookResources methods to use new webhooks apis + - resumeNextDay parameter added to CallBroadcast object + - transferMessage, transferMessageSoundId, transferDigit, transferNumber params added to CallRecipient object for sending calls and texts + - added questionResponses parameter to CallRecord object + - added duplicate parameter to CampaignSound object + - get call recordings api functions implemented in CallsApi + Version 1.1.7 - Apr 18 2016 - migration to 4.5 net framework - - migration to gradle + - migration to gradle Version 1.1.6 - Mar 25 2016 - added mono debug files generation on Windows platform diff --git a/docs/api/callstexts/CallsApi.adoc b/docs/api/callstexts/CallsApi.adoc index 817de6c..af556b3 100644 --- a/docs/api/callstexts/CallsApi.adoc +++ b/docs/api/callstexts/CallsApi.adoc @@ -25,8 +25,15 @@ Example how to use the /calls API to quickly send individual calls via default c [source,csharp] CallfireClient Client = new CallfireClient("api_login", "api_password"); //Only "recipients" param required - var recipient1 = new CallRecipient { ContactId = 463633187003, LiveMessage = "testMessage" }; - var recipient2 = new CallRecipient { ContactId = 463633187003, LiveMessage = "testMessage" }; + var recipient1 = new CallRecipient { ContactId = 463633187003, LiveMessage = "testMessage", TransferDigit = "1", TransferMessage = "transferTestMessage", TransferNumber = "14246525473" }; + var recipient2 = new CallRecipient { ContactId = 463633187003, LiveMessage = "testMessage", TransferDigit = "1", TransferMessageSoundId = 1, TransferNumber = "14246525473" }; + r1.setTransferMessage("transferTestMessage"); + //or you can use transfer sound id + r1.setTransferMessageSoundId(1123123L); + r1.setTransferNumber("14246525473"); + r1.setTransferDigit("1"); + + var recipients = new List { recipient1, recipient2 }; IList calls = Client.CallsApi.Send(recipients, null, "items(id,fromNumber,state)"); Console.WriteLine("Calls: " + calls); @@ -42,6 +49,35 @@ In case you want to send call via existing campaign provide campaign id as secon IList calls = Client.CallsApi.Send(recipients, 60000000003); Console.WriteLine("Calls: " + calls); +Also you can send call with some default parameters which will be used in case when recipient doesn't have that info specified, + see example below: +[source,csharp] + CallfireClient Client = new CallfireClient("api_login", "api_password"); + //Only "recipients" param required + var recipient1 = new CallRecipient { ContactId = 463633187003, LiveMessage = "testMessage" }; + var recipient2 = new CallRecipient { ContactId = 463633187003, LiveMessage = "testMessage" }; + var recipients = new List { recipient1, recipient2 }; + var request = new SendCallsRequest + { + Recipients = recipients, + CampaignId = 7373471003, + Fields = "items(id, fromNumber, state, campaignId)", + DefaultLiveMessage = "DefaultLiveMessage", + DefaultMachineMessage = "DefaultMachineMessage", + DefaultVoice = CallfireApiClient.Api.Campaigns.Model.Voice.FRENCHCANADIAN1 + }; + IList calls = Client.CallsApi.Send(request); + request = new SendCallsRequest + { + Recipients = recipients, + CampaignId = 7373471003, + Fields = "items(id, fromNumber, state, campaignId)", + DefaultLiveMessageSoundId = 1, + DefaultMachineMessageSoundId = 1, + DefaultVoice = CallfireApiClient.Api.Campaigns.Model.Voice.FRENCHCANADIAN1 + }; + calls = Client.CallsApi.Send(request); + === Get call ''' Example how to return a single Call instance for a given call id. @@ -50,3 +86,43 @@ Example how to return a single Call instance for a given call id. CallfireClient Client = new CallfireClient("api_login", "api_password"); Call call = Client.CallsApi.Get(617067920003, "id,toNumber,state"); Console.WriteLine("Call: " + call); + +=== Get call recordings +''' +Example how to return call recordings for a given call id. +[source,csharp] + //Only "id" param required + CallfireClient Client = new CallfireClient("api_login", "api_password"); + IList recs = Client.CallsApi.GetCallRecordings(1234, "items(callId)"); + +=== Get call recording by name and call id +''' +Example how to return call recording for a given call by recording name. +[source,csharp] + //"id" and "name" params are required + CallfireClient Client = new CallfireClient("api_login", "api_password"); + CallRecording recording = Client.CallsApi.GetCallRecordingByName(1234, "testName", "callId"); + +=== Get mp3 call recording by name and call id +''' +Example how to return mp3 call recording for a given call by recording name. +[source,csharp] + //"id" and "name" params are required + CallfireClient Client = new CallfireClient("api_login", "api_password"); + MemoryStream ms = (MemoryStream)Client.CallsApi.GetCallRecordingMp3ByName(1234, "testName"); + +=== Get call recording by id +''' +Example how to return call recording for a given recording id. +[source,csharp] + //Only "id" param required + CallfireClient Client = new CallfireClient("api_login", "api_password"); + CallRecording rec = Client.CallsApi.GetCallRecording(1234, "campaignId"); + +=== Get mp3 call recording by id +''' +Example how to return mp3 call recording for a given recording id. +[source,csharp] + //Only "id" param required + CallfireClient Client = new CallfireClient("api_login", "api_password"); + MemoryStream ms = (MemoryStream)Client.CallsApi.GetCallRecordingMp3(1234); diff --git a/docs/api/callstexts/TextsApi.adoc b/docs/api/callstexts/TextsApi.adoc index d98cf80..41510a7 100644 --- a/docs/api/callstexts/TextsApi.adoc +++ b/docs/api/callstexts/TextsApi.adoc @@ -30,6 +30,23 @@ Example how to use the /texts API to quickly send individual texts via existing In case you want to send text via default campaign use *Send(List recipients, long? campaignId)* method. +In case you want to send text with default text which will be used in case when recipient doesn't have that info specified, + see example below: +[source,csharp] + CallfireClient Client = new CallfireClient("api_login", "api_password"); + //Only "recipients" param required + var recipient1 = new TextRecipient { Message = "msg", PhoneNumber = "12132212384" }; + var recipient2 = new TextRecipient { Message = "msg", PhoneNumber = "12132212384" }; + var recipients = new List { recipient1, recipient2 }; + var request = new SendTextsRequest + { + Recipients = recipients, + CampaignId = 7415135003, + DefaultMessage = "DefaultLiveMessage", + Fields = "items(id,fromNumber,state)" + }; + IList texts = Client.TextsApi.Send(request); + === Get text ''' Example how to return a single Text instance for a given text id. diff --git a/docs/api/campaigns/CallBroadcastsApi.adoc b/docs/api/campaigns/CallBroadcastsApi.adoc index 704a735..e724e1d 100644 --- a/docs/api/campaigns/CallBroadcastsApi.adoc +++ b/docs/api/campaigns/CallBroadcastsApi.adoc @@ -37,7 +37,9 @@ Create a call broadcast campaign using the Call Broadcast API. Send a CallBroadc { new Recipient { PhoneNumber = "12132212384" }, new Recipient { PhoneNumber = "12132212385" } - } + }, + ResumeNextDay = true + }; // create broadcast with 'start' argument = true to start campaign immediately var id = client.CallBroadcastsApi.Create(broadcast, true); @@ -94,6 +96,13 @@ Get calls associated with call broadcast ordered by date. var calls = client.CallBroadcastsApi.GetCalls(request); Console.WriteLine(calls); +If you want to get calls filtered by batch id please use code like: +[source,csharp] + var client = new CallfireClient("api_login", "api_password"); + var request = new GetBroadcastCallsTextsRequest { Id = 1234, batchId = 12345 }; + var calls = client.CallBroadcastsApi.GetCalls(getCallsRequest); + Console.WriteLine(calls); + === Get broadcast stats Get broadcast statistics. [source,csharp] diff --git a/docs/api/campaigns/CampaignSoundsApi.adoc b/docs/api/campaigns/CampaignSoundsApi.adoc index 37eee9b..c8b4d2d 100644 --- a/docs/api/campaigns/CampaignSoundsApi.adoc +++ b/docs/api/campaigns/CampaignSoundsApi.adoc @@ -50,7 +50,17 @@ Use this API to create a sound via phone call. Supply the required phone number }; ResourceId resourceId = Client.CampaignSoundsApi.RecordViaPhone(callCreateSound); Console.WriteLine("Sound id: " + resourceId.Id); - + +If you want to see created sound details please use code like: +[source,csharp] + CallfireClient Client = new CallfireClient("api_login", "api_password"); + CallCreateSound callCreateSound = new CallCreateSound + { + Name = "call_in_sound_" + new DateTime().Millisecond, + ToNumber = "12132212384" + }; + CampaignSound sound = Client.CampaignSoundsApi.RecordViaPhoneAndGetSoundDetails(callCreateSound, "id,name"); + === Add sound via text-to-speech ''' Use this API to create a sound file via a supplied string of text. Send the required text in the @@ -62,3 +72,17 @@ Use this API to create a sound file via a supplied string of text. Send the requ ResourceId resourceId = Client.CampaignSoundsApi.CreateFromTts(tts); CampaignSound campaignSound = Client.CampaignSoundsApi.Get(resourceId.Id); Console.WriteLine("Campaign sound: " + campaignSound); + +If you want to see created sound details please use code like: +[source,csharp] + CallfireClient Client = new CallfireClient("api_login", "api_password"); + TextToSpeech tts = new TextToSpeech { Message = "this is TTS message from csharp client" }; + CampaignSound sound = Client.CampaignSoundsApi.CreateFromTtsAndGetSoundDetails(tts, "id,name"); + +=== Upload sound file +''' +Upload mp3 or wav sound file. +[source,csharp] + CallfireClient Client = new CallfireClient("api_login", "api_password"); + string mp3FilePath = "Resources/File-examples/train.mp3"; + CampaignSound mp3Resource = Client.CampaignSoundsApi.UploadAndGetSoundDetails(mp3FilePath, "fileName"); diff --git a/docs/api/campaigns/TextBroadcastsApi.adoc b/docs/api/campaigns/TextBroadcastsApi.adoc index c1635fe..ed71e78 100644 --- a/docs/api/campaigns/TextBroadcastsApi.adoc +++ b/docs/api/campaigns/TextBroadcastsApi.adoc @@ -38,7 +38,8 @@ Example how to create text broadcast and then start it. Broadcast will send mess { new TextRecipient { PhoneNumber = "12132212384" }, new TextRecipient { PhoneNumber = "12132212385" } - } + }, + ResumeNextDay = true }; // create broadcast var id = client.TextBroadcastsApi.Create(broadcast, true); @@ -87,6 +88,12 @@ This operation will enable the user to page through all of the texts for a parti var texts = client.TextBroadcastsApi.GetTexts(request); Console.WriteLine(texts); +If you want to get texts filtered by batch id please use code like: +[source,csharp] + var client = new CallfireClient("api_login", "api_password"); + var request = new GetBroadcastCallsTextsRequest { Id = 123, batchId = 1234 }; + var texts = client.TextBroadcastsApi.GetTexts(request); + === Get broadcast stats Get broadcast statistics. [source,csharp] diff --git a/docs/api/webhooks/WebhooksApi.adoc b/docs/api/webhooks/WebhooksApi.adoc index a458030..a663afa 100644 --- a/docs/api/webhooks/WebhooksApi.adoc +++ b/docs/api/webhooks/WebhooksApi.adoc @@ -11,7 +11,7 @@ Search for webhooks on name, resource, event, callback URL, or whether they are { Limit = 5, Enabled = true, - Resource = Webhook.ResourceType.TEXT_BROADCAST + Name = "test_name" }; Page webhooks = Client.WebhooksApi.Find(findRequest); Console.WriteLine(webhooks); @@ -33,7 +33,7 @@ Example how to create a webhook for voice campaign. Callfire will query your cal var webhook = new Webhook { Name = "new webhook", - Resource = ResourceType.VOICE_BROADCAST, + Resource = ResourceType.TEXT_BROADCAST, Events = new HashSet { ResourceEvent.STARTED, ResourceEvent.FINISHED }, Callback = "https://yoursite.com/callback" }; @@ -49,7 +49,7 @@ Example how to update the information in a currently existing webhook. Most fiel { Id = 12345678, Name = "new webhook", - Resource = ResourceType.VOICE_BROADCAST, + Resource = ResourceType.TEXT_BROADCAST, Events = new HashSet { ResourceEvent.STARTED, ResourceEvent.FINISHED }, Callback = "https://yoursite.com/callback" }; @@ -61,3 +61,17 @@ Example how to delete a webhook. Will be removed permenantly. [source,csharp] CallfireClient Client = new CallfireClient("api_login", "api_password"); Client.WebhooksApi.Delete(12345678); + +=== Find webhook resources +''' +Example how to find webhook resources. +[source,csharp] + CallfireClient Client = new CallfireClient("api_login", "api_password"); + var resources = Client.WebhooksApi.FindWebhookResources("items(resource)"); + +=== Find webhook resource +''' +Example how to find webhook resource. +[source,csharp] + CallfireClient Client = new CallfireClient("api_login", "api_password"); + var resource = Client.WebhooksApi.FindWebhookResource(ResourceType.CALL_BROADCAST, "resource"); diff --git a/src/CallfireApiClient.Tests/Api/CallsTexts/CallRecording.cs b/src/CallfireApiClient.Tests/Api/CallsTexts/CallRecording.cs new file mode 100644 index 0000000..fb93309 --- /dev/null +++ b/src/CallfireApiClient.Tests/Api/CallsTexts/CallRecording.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; +using CallfireApiClient.Api.Campaigns.Model; + +namespace CallfireApiClient.Tests.Api.CallsTexts +{ + internal class CallRecording + { + private IList callRecordings; + + public CallRecording(IList callRecordings) + { + this.callRecordings = callRecordings; + } + } +} \ No newline at end of file diff --git a/src/CallfireApiClient.Tests/Api/CallsTexts/CallsApiTest.cs b/src/CallfireApiClient.Tests/Api/CallsTexts/CallsApiTest.cs index 80ec8f7..a25a540 100644 --- a/src/CallfireApiClient.Tests/Api/CallsTexts/CallsApiTest.cs +++ b/src/CallfireApiClient.Tests/Api/CallsTexts/CallsApiTest.cs @@ -5,12 +5,17 @@ using CallfireApiClient.Api.CallsTexts.Model.Request; using RestSharp; using System.Linq; +using CallfireApiClient.Api.Common.Model.Request; +using CallfireApiClient.Api.Campaigns.Model; +using System; namespace CallfireApiClient.Tests.Api.CallsTexts { [TestFixture] public class CallsApiTest : AbstractApiTest { + private const string EMPTY_KEY_MSG = "recordingName cannot be blank"; + [Test] public void SendCalls() { @@ -18,9 +23,8 @@ public void SendCalls() string responseJson = GetJsonPayload("/callstexts/callsApi/response/sendCalls.json"); var restRequest = MockRestResponse(responseJson); - CallRecipient r1 = new CallRecipient { PhoneNumber = "12135551100", LiveMessage = "Why hello there!" }; + CallRecipient r1 = new CallRecipient { PhoneNumber = "12135551100", LiveMessage = "Why hello there!", TransferDigit = "1", TransferMessage = "testMessage", TransferNumber = "12135551101" }; CallRecipient r2 = new CallRecipient { PhoneNumber = "12135551101", LiveMessage = "And hello to you too." }; - IList calls = Client.CallsApi.Send(new List { r1, r2 }); Assert.That(Serializer.Serialize(new ListHolder(calls)), Is.EqualTo(responseJson)); @@ -28,11 +32,51 @@ public void SendCalls() var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); Assert.That(requestBodyParam.Value, Is.EqualTo(requestJson)); - calls = Client.CallsApi.Send(new List { r1, r2 }, 100, FIELDS); + calls = Client.CallsApi.Send(new List { r1, r2 }, 10, FIELDS); Assert.That(restRequest.Value.Resource, !Is.StringContaining("fields" + FIELDS)); Assert.That(restRequest.Value.Resource, !Is.StringContaining("campaignId=100")); } + [Test] + public void SendCallsUsingRequest() + { + string requestJson = GetJsonPayload("/callstexts/callsApi/request/sendCalls.json"); + string responseJson = GetJsonPayload("/callstexts/callsApi/response/sendCalls.json"); + var restRequest = MockRestResponse(responseJson); + + CallRecipient r1 = new CallRecipient { PhoneNumber = "12135551100", LiveMessage = "Why hello there!", TransferDigit = "1", TransferMessage = "testMessage", TransferNumber = "12135551101" }; + CallRecipient r2 = new CallRecipient { PhoneNumber = "12135551101", LiveMessage = "And hello to you too." }; + + var request = new SendCallsRequest + { + Recipients = new List { r1, r2 }, + CampaignId = 10, + Fields = FIELDS, + DefaultLiveMessage = "DefaultLiveMessage", + DefaultMachineMessage = "DefaultMachineMessage", + DefaultLiveMessageSoundId = 1, + DefaultMachineMessageSoundId = 1, + DefaultVoice = CallfireApiClient.Api.Campaigns.Model.Voice.FRENCHCANADIAN1 + }; + + IList calls = Client.CallsApi.Send(request); + + Assert.That(Serializer.Serialize(new ListHolder(calls)), Is.EqualTo(responseJson)); + Assert.AreEqual(Method.POST, restRequest.Value.Method); + var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); + Assert.That(requestBodyParam.Value, Is.EqualTo(requestJson)); + + calls = Client.CallsApi.Send(new List { r1, r2 }, 10, FIELDS); + Assert.That(restRequest.Value.Resource, !Is.StringContaining("fields" + FIELDS)); + Assert.That(restRequest.Value.Resource, !Is.StringContaining("campaignId=10")); + Assert.That(restRequest.Value.Resource, !Is.StringContaining("defaultLiveMessage=DefaultLiveMessage")); + Assert.That(restRequest.Value.Resource, !Is.StringContaining("defaultMachineMessage=DefaultMachineMessage")); + Assert.That(restRequest.Value.Resource, !Is.StringContaining("defaultLiveMessageSoundId=1")); + Assert.That(restRequest.Value.Resource, !Is.StringContaining("defaultMachineMessageSoundId=1")); + Assert.That(restRequest.Value.Resource, !Is.StringContaining("defaultMachineMessageSoundId=1")); + Assert.That(restRequest.Value.Resource, !Is.StringContaining("defaultVoice=FRENCHCANADIAN1")); + } + [Test] public void FindCalls() { @@ -75,6 +119,105 @@ public void GetCall() Assert.AreEqual(Method.GET, restRequest.Value.Method); Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("fields") && p.Value.Equals(FIELDS))); } + + [Test] + public void GetCallRecordings() + { + string expectedJson = GetJsonPayload("/callstexts/callsApi/response/getCallRecordings.json"); + var restRequest = MockRestResponse(expectedJson); + + IList callRecordings = Client.CallsApi.GetCallRecordings(10, null); + Assert.That(restRequest.Value.Parameters, Has.None.Matches(p => p.Name.Equals("fields"))); + Assert.That(Serializer.Serialize(new ListHolder(callRecordings)), Is.EqualTo(expectedJson)); + Assert.AreEqual(Method.GET, restRequest.Value.Method); + Assert.That(restRequest.Value.Resource, Is.StringContaining("/calls/10/recordings")); + } + + [Test] + public void GetCallRecordingsWithFieldsParam() + { + string expectedJson = GetJsonPayload("/callstexts/callsApi/response/getCallRecordings.json"); + var restRequest = MockRestResponse(expectedJson); + + IList callRecordings = Client.CallsApi.GetCallRecordings(10, FIELDS); + Assert.That(Serializer.Serialize(new ListHolder(callRecordings)), Is.EqualTo(expectedJson)); + Assert.AreEqual(Method.GET, restRequest.Value.Method); + Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("fields") && p.Value.Equals(FIELDS))); + Assert.That(restRequest.Value.Resource, Is.StringContaining("/calls/10/recordings")); + } + + [Test] + public void GetCallRecordingByName() + { + string expectedJson = GetJsonPayload("/callstexts/callsApi/response/getCallRecording.json"); + var restRequest = MockRestResponse(expectedJson); + + CallRecording callRecording = Client.CallsApi.GetCallRecordingByName(10, "testName", null); + Assert.That(Serializer.Serialize(callRecording), Is.EqualTo(expectedJson)); + Assert.AreEqual(Method.GET, restRequest.Value.Method); + Assert.That(restRequest.Value.Parameters, Has.None.Matches(p => p.Name.Equals("fields") && p.Value.Equals(FIELDS))); + Assert.That(restRequest.Value.Resource, Is.StringContaining("/10/recordings/testName")); + } + + [Test] + public void GetCallRecordingByNameWithFieldsParam() + { + string expectedJson = GetJsonPayload("/callstexts/callsApi/response/getCallRecording.json"); + var restRequest = MockRestResponse(expectedJson); + + CallRecording callRecording = Client.CallsApi.GetCallRecordingByName(10, "testName", FIELDS); + Console.WriteLine(Serializer.Serialize(callRecording)); + + Assert.That(Serializer.Serialize(callRecording), Is.EqualTo(expectedJson)); + Assert.AreEqual(Method.GET, restRequest.Value.Method); + Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("fields") && p.Value.Equals(FIELDS))); + Assert.That(restRequest.Value.Resource, Is.StringContaining("/calls/10/recordings/testName")); + } + + [Test] + public void GetCallRecordingByNameWithNullNameParameter() + { + var ex = Assert.Throws(() => Client.CallsApi.GetCallRecordingByName(10, null)); + Assert.That(ex.Message, Is.EqualTo(EMPTY_KEY_MSG)); + + ex = Assert.Throws(() => Client.CallsApi.GetCallRecordingByName(10, "")); + Assert.That(ex.Message, Is.EqualTo(EMPTY_KEY_MSG)); + } + + [Test] + public void GetMp3CallRecordingByNameWithNullNameParameter() + { + var ex = Assert.Throws(() => Client.CallsApi.GetCallRecordingMp3ByName(10, null)); + Assert.That(ex.Message, Is.EqualTo(EMPTY_KEY_MSG)); + + ex = Assert.Throws(() => Client.CallsApi.GetCallRecordingMp3ByName(10, "")); + Assert.That(ex.Message, Is.EqualTo(EMPTY_KEY_MSG)); + } + + [Test] + public void GetCallRecording() + { + string expectedJson = GetJsonPayload("/callstexts/callsApi/response/getCallRecording.json"); + var restRequest = MockRestResponse(expectedJson); + + CallRecording callRecording = Client.CallsApi.GetCallRecording(10, null); + Assert.That(restRequest.Value.Parameters, Has.None.Matches(p => p.Name.Equals("fields"))); + Assert.That(Serializer.Serialize(callRecording), Is.EqualTo(expectedJson)); + Assert.AreEqual(Method.GET, restRequest.Value.Method); + Assert.That(restRequest.Value.Resource, Is.StringContaining("/calls/recordings/10")); + } + + [Test] + public void GetCallRecordingWithFieldsParam() + { + string expectedJson = GetJsonPayload("/callstexts/callsApi/response/getCallRecording.json"); + var restRequest = MockRestResponse(expectedJson); + + CallRecording callRecording = Client.CallsApi.GetCallRecording(10, FIELDS); + Assert.That(Serializer.Serialize(callRecording), Is.EqualTo(expectedJson)); + Assert.AreEqual(Method.GET, restRequest.Value.Method); + Assert.That(restRequest.Value.Resource, Is.StringContaining("/calls/recordings/10")); + Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("fields") && p.Value.Equals(FIELDS))); + } } } - diff --git a/src/CallfireApiClient.Tests/Api/CallsTexts/TextsApiTest.cs b/src/CallfireApiClient.Tests/Api/CallsTexts/TextsApiTest.cs index 006f8d9..7e7c813 100644 --- a/src/CallfireApiClient.Tests/Api/CallsTexts/TextsApiTest.cs +++ b/src/CallfireApiClient.Tests/Api/CallsTexts/TextsApiTest.cs @@ -5,6 +5,7 @@ using CallfireApiClient.Api.CallsTexts.Model.Request; using RestSharp; using System.Linq; +using CallfireApiClient.Api.Common.Model.Request; namespace CallfireApiClient.Tests.Api.CallsTexts { @@ -33,6 +34,35 @@ public void SendTexts() Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("campaignId") && p.Value.Equals("100"))); } + [Test] + public void SendTextsUsingRequest() + { + string requestJson = GetJsonPayload("/callstexts/textsApi/request/sendTexts.json"); + string responseJson = GetJsonPayload("/callstexts/textsApi/response/sendTexts.json"); + var restRequest = MockRestResponse(responseJson); + + TextRecipient r1 = new TextRecipient { PhoneNumber = "12135551100", Message = "Hello World!" }; + TextRecipient r2 = new TextRecipient { PhoneNumber = "12135551101", Message = "Testing 1 2 3" }; + + var request = new SendTextsRequest + { + Recipients = new List { r1, r2 }, + CampaignId = 100, + Fields = FIELDS, + DefaultMessage = "defaultMessage" + }; + + IList texts = Client.TextsApi.Send(request); + + Assert.That(Serializer.Serialize(new ListHolder(texts)), Is.EqualTo(responseJson)); + Assert.AreEqual(Method.POST, restRequest.Value.Method); + var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); + Assert.That(requestBodyParam.Value, Is.EqualTo(requestJson)); + Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("fields") && p.Value.Equals(FIELDS))); + Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("campaignId") && p.Value.Equals("100"))); + Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("defaultMessage") && p.Value.Equals("defaultMessage"))); + } + [Test] public void FindTexts() { diff --git a/src/CallfireApiClient.Tests/Api/Campaigns/CallBroadcastsApiTest.cs b/src/CallfireApiClient.Tests/Api/Campaigns/CallBroadcastsApiTest.cs index 520129b..bdb5d85 100644 --- a/src/CallfireApiClient.Tests/Api/Campaigns/CallBroadcastsApiTest.cs +++ b/src/CallfireApiClient.Tests/Api/Campaigns/CallBroadcastsApiTest.cs @@ -37,7 +37,8 @@ public void CreateVoiceBroadcast() { new Recipient { PhoneNumber = "13233832214" }, new Recipient { PhoneNumber = "13233832215" }, - } + }, + ResumeNextDay = true }; var id = Client.CallBroadcastsApi.Create(callBroadcast, true); Assert.That(Serializer.Serialize(id), Is.EqualTo(responseJson)); @@ -116,7 +117,8 @@ public void UpdateVoiceBroadcast() { LiveSoundText = "Hello! This is an updated VB config tts", MachineSoundId = 1258704003 - } + }, + ResumeNextDay = true }; Client.CallBroadcastsApi.Update(callBroadcast); @@ -193,7 +195,7 @@ public void Archive() } [Test] - public void GetCalls() + public void GetCallsWithGetByIdRequest() { var expectedJson = GetJsonPayload("/campaigns/callBroadcastsApi/response/getCalls.json"); var restRequest = MockRestResponse(expectedJson); @@ -216,6 +218,32 @@ public void GetCalls() Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("fields") && p.Value.Equals(FIELDS))); } + [Test] + public void GetCallsWithGetByIdAndBatchIdRequest() + { + var expectedJson = GetJsonPayload("/campaigns/callBroadcastsApi/response/getCalls.json"); + var restRequest = MockRestResponse(expectedJson); + + var request = new GetBroadcastCallsTextsRequest + { + Offset = 5, + Fields = FIELDS, + Id = 11, + batchId = 13 + }; + var calls = Client.CallBroadcastsApi.GetCalls(request); + Assert.That(Serializer.Serialize(calls), Is.EqualTo(expectedJson)); + + Assert.AreEqual(Method.GET, restRequest.Value.Method); + var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); + Assert.IsNull(requestBodyParam); + Assert.That(restRequest.Value.Resource, Is.StringEnding("/11/calls")); + Assert.That(restRequest.Value.Parameters, Has.No.Some.Matches(p => p.Name.Equals("id"))); + Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("offset") && p.Value.Equals("5"))); + Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("fields") && p.Value.Equals(FIELDS))); + Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("batchId") && p.Value.Equals("13"))); + } + [Test] public void GetStats() { diff --git a/src/CallfireApiClient.Tests/Api/Campaigns/CampaignSoundsApiTest.cs b/src/CallfireApiClient.Tests/Api/Campaigns/CampaignSoundsApiTest.cs index 28b3116..6754dd4 100644 --- a/src/CallfireApiClient.Tests/Api/Campaigns/CampaignSoundsApiTest.cs +++ b/src/CallfireApiClient.Tests/Api/Campaigns/CampaignSoundsApiTest.cs @@ -34,7 +34,7 @@ public void TestFind() } [Test] - public void TestGet() + public void TestGetWithFieldsParam() { string expectedJson = GetJsonPayload("/campaigns/campaignSoundsApi/response/getCampaignSound.json"); var restRequest = MockRestResponse(expectedJson); @@ -45,9 +45,20 @@ public void TestGet() Assert.AreEqual(Method.GET, restRequest.Value.Method); Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("fields") && p.Value.Equals(FIELDS))); Assert.That(restRequest.Value.Resource, Is.StringEnding("/11")); + } + + [Test] + public void TestGet() + { + string expectedJson = GetJsonPayload("/campaigns/campaignSoundsApi/response/getCampaignSound.json"); + var restRequest = MockRestResponse(expectedJson); - Client.CampaignSoundsApi.Get(11); + CampaignSound campaignSound = Client.CampaignSoundsApi.Get(11); + + Assert.That(Serializer.Serialize(campaignSound), Is.EqualTo(expectedJson)); + Assert.AreEqual(Method.GET, restRequest.Value.Method); Assert.That(restRequest.Value.Parameters, Has.None.Matches(p => p.Name.Equals("FIELDS") && p.Value.Equals(FIELDS))); + Assert.That(restRequest.Value.Resource, Is.StringEnding("/11")); } [Test] @@ -63,6 +74,18 @@ public void TestUpload() Assert.AreEqual(Method.POST, restRequest.Value.Method); } + [Test] + public void TestUploadAndGetSoundDetails() + { + string expectedJson = GetJsonPayload("/campaigns/campaignSoundsApi/response/uploadSoundWithDetails.json"); + var restRequest = MockRestResponse(expectedJson); + + string mp3FilePath = "Resources/File-examples/train.mp3"; + CampaignSound sound = Client.CampaignSoundsApi.UploadAndGetSoundDetails(mp3FilePath, "fname"); + Assert.That(Serializer.Serialize(sound), Is.EqualTo(expectedJson)); + Assert.AreEqual(Method.POST, restRequest.Value.Method); + } + [Test] public void TestRecordViaPhone() { @@ -84,6 +107,29 @@ public void TestRecordViaPhone() Assert.That(requestBodyParam.Value, Is.EqualTo(requestJson)); } + [Test] + public void TestRecordViaPhoneAndGetSoundDetails() + { + string responseJson = GetJsonPayload("/campaigns/campaignSoundsApi/response/uploadSoundWithDetails.json"); + string requestJson = GetJsonPayload("/campaigns/campaignSoundsApi/request/recordViaPhone.json"); + var restRequest = MockRestResponse(responseJson); + + CallCreateSound callCreateSound = new CallCreateSound + { + Name = "My sound file", + ToNumber = "12135551122" + }; + + CampaignSound sound = Client.CampaignSoundsApi.RecordViaPhoneAndGetSoundDetails(callCreateSound, FIELDS); + + Assert.That(Serializer.Serialize(sound), Is.EqualTo(responseJson)); + Assert.AreEqual(Method.POST, restRequest.Value.Method); + var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); + Assert.That(requestBodyParam.Value, Is.EqualTo(requestJson)); + Assert.That(restRequest.Value.Parameters, Has.None.Matches(p => p.Name.Equals("FIELDS") && p.Value.Equals(FIELDS))); + + } + [Test] public void TestCreateFromTts() { @@ -104,6 +150,28 @@ public void TestCreateFromTts() var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); Assert.That(requestBodyParam.Value, Is.EqualTo(requestJson)); } + + [Test] + public void TestCreateFromTtsAndGetSoundDetails() + { + string responseJson = GetJsonPayload("/campaigns/campaignSoundsApi/response/uploadSoundWithDetails.json"); + string requestJson = GetJsonPayload("/campaigns/campaignSoundsApi/request/createFromTts.json"); + var restRequest = MockRestResponse(responseJson); + + TextToSpeech textToSpeech = new TextToSpeech + { + Voice = Voice.MALE1, + Message = "This is a TTS sound" + }; + + CampaignSound sound = Client.CampaignSoundsApi.CreateFromTtsAndGetSoundDetails(textToSpeech, FIELDS); + + Assert.That(Serializer.Serialize(sound), Is.EqualTo(responseJson)); + Assert.AreEqual(Method.POST, restRequest.Value.Method); + var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); + Assert.That(requestBodyParam.Value, Is.EqualTo(requestJson)); + Assert.That(restRequest.Value.Parameters, Has.None.Matches(p => p.Name.Equals("FIELDS") && p.Value.Equals(FIELDS))); + } } } diff --git a/src/CallfireApiClient.Tests/Api/Campaigns/TextBroadcastsApiTest.cs b/src/CallfireApiClient.Tests/Api/Campaigns/TextBroadcastsApiTest.cs index f561670..6717af2 100644 --- a/src/CallfireApiClient.Tests/Api/Campaigns/TextBroadcastsApiTest.cs +++ b/src/CallfireApiClient.Tests/Api/Campaigns/TextBroadcastsApiTest.cs @@ -30,7 +30,8 @@ public void Create() { new TextRecipient { PhoneNumber = "13233832214" }, new TextRecipient { PhoneNumber = "13233832215" }, - } + }, + ResumeNextDay = true }; var id = Client.TextBroadcastsApi.Create(textBroadcast, true); Assert.That(Serializer.Serialize(id), Is.EqualTo(responseJson)); @@ -76,7 +77,8 @@ public void Update() { Id = 11, Name = "Example API SMS updated", - Message = "a new test message" + Message = "a new test message", + ResumeNextDay = true }; Client.TextBroadcastsApi.Update(textBroadcast); @@ -132,7 +134,7 @@ public void Archive() } [Test] - public void GetTexts() + public void GetTextsWithGetByIdRequest() { var expectedJson = GetJsonPayload("/campaigns/textBroadcastsApi/response/getTexts.json"); var restRequest = MockRestResponse(expectedJson); @@ -155,6 +157,32 @@ public void GetTexts() Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("fields") && p.Value.Equals(FIELDS))); } + [Test] + public void GetTextsWithGetByIdAndBatchIdRequest() + { + var expectedJson = GetJsonPayload("/campaigns/textBroadcastsApi/response/getTexts.json"); + var restRequest = MockRestResponse(expectedJson); + + var request = new GetBroadcastCallsTextsRequest + { + Offset = 5, + Fields = FIELDS, + Id = 11, + batchId = 13 + }; + var texts = Client.TextBroadcastsApi.GetTexts(request); + Assert.That(Serializer.Serialize(texts), Is.EqualTo(expectedJson)); + + Assert.AreEqual(Method.GET, restRequest.Value.Method); + var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); + Assert.IsNull(requestBodyParam); + Assert.That(restRequest.Value.Resource, Is.StringEnding("/11/texts")); + Assert.That(restRequest.Value.Parameters, Has.No.Some.Matches(p => p.Name.Equals("id"))); + Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("offset") && p.Value.Equals("5"))); + Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("fields") && p.Value.Equals(FIELDS))); + Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("batchId") && p.Value.Equals("13"))); + } + [Test] public void GetStats() { diff --git a/src/CallfireApiClient.Tests/Api/Webhooks/WebhooksApiTest.cs b/src/CallfireApiClient.Tests/Api/Webhooks/WebhooksApiTest.cs index fc9102e..6792309 100644 --- a/src/CallfireApiClient.Tests/Api/Webhooks/WebhooksApiTest.cs +++ b/src/CallfireApiClient.Tests/Api/Webhooks/WebhooksApiTest.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using CallfireApiClient.Api.Webhooks.Model.Request; using CallfireApiClient.Api.Webhooks.Model; +using CallfireApiClient.Api.Common.Model; namespace CallfireApiClient.Tests.Api.Webhooks { @@ -110,11 +111,35 @@ public void ValidateWebhook() { var webhook = new Webhook { - Resource = ResourceType.VOICE_BROADCAST, + Resource = ResourceType.CALL_BROADCAST, Events = new HashSet { ResourceEvent.FINISHED, ResourceEvent.STARTED, ResourceEvent.UNKNOWN } }; var ex = Assert.Throws(() => Client.WebhooksApi.Update(webhook)); - Assert.That(ex.Message, Is.StringContaining("Event [unknown] is unsupported for voiceCampaign resource")); + Assert.That(ex.Message, Is.StringContaining("Event [unknown] is unsupported for CallBroadcast resource")); + } + + [Test] + public void TestFindWebhookResources() + { + var expectedJson = GetJsonPayload("/webhooks/webhooksApi/response/findWebhookResources.json"); + var restRequest = MockRestResponse(expectedJson); + + IList resources = Client.WebhooksApi.FindWebhookResources(FIELDS); + Assert.That(Serializer.Serialize(new ListHolder(resources)), Is.EqualTo(expectedJson)); + Assert.AreEqual(Method.GET, restRequest.Value.Method); + Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("fields") && p.Value.Equals(FIELDS))); + } + + [Test] + public void TestFindWebhookResource() + { + var expectedJson = GetJsonPayload("/webhooks/webhooksApi/response/findSpecificWebhookResource.json"); + var restRequest = MockRestResponse(expectedJson); + + WebhookResource resource = Client.WebhooksApi.FindWebhookResource(ResourceType.CALL_BROADCAST, FIELDS); + Assert.That(Serializer.Serialize(resource), Is.EqualTo(expectedJson)); + Assert.AreEqual(Method.GET, restRequest.Value.Method); + Assert.That(restRequest.Value.Parameters, Has.Some.Matches(p => p.Name.Equals("fields") && p.Value.Equals(FIELDS))); } } } \ No newline at end of file diff --git a/src/CallfireApiClient.Tests/CallfireApiClient.Tests.csproj b/src/CallfireApiClient.Tests/CallfireApiClient.Tests.csproj index 03f541e..e7067ab 100644 --- a/src/CallfireApiClient.Tests/CallfireApiClient.Tests.csproj +++ b/src/CallfireApiClient.Tests/CallfireApiClient.Tests.csproj @@ -51,6 +51,7 @@ + @@ -100,11 +101,20 @@ + + + + + Always + + + Always + diff --git a/src/CallfireApiClient.Tests/Integration/AbstractIntegrationTest.cs b/src/CallfireApiClient.Tests/Integration/AbstractIntegrationTest.cs index 87179ab..5a05198 100644 --- a/src/CallfireApiClient.Tests/Integration/AbstractIntegrationTest.cs +++ b/src/CallfireApiClient.Tests/Integration/AbstractIntegrationTest.cs @@ -8,7 +8,7 @@ public class AbstractIntegrationTest public AbstractIntegrationTest() { - Client = new CallfireClient("login", "password"); + Client = new CallfireClient("9b4f74b51316", "608bec4e28889510"); } } } diff --git a/src/CallfireApiClient.Tests/Integration/CallsTexts/CallsApiIntegrationTest.cs b/src/CallfireApiClient.Tests/Integration/CallsTexts/CallsApiIntegrationTest.cs index 5c74167..758fbce 100644 --- a/src/CallfireApiClient.Tests/Integration/CallsTexts/CallsApiIntegrationTest.cs +++ b/src/CallfireApiClient.Tests/Integration/CallsTexts/CallsApiIntegrationTest.cs @@ -5,6 +5,9 @@ using System.Collections.Generic; using NUnit.Framework; using CallfireApiClient.Api.Contacts.Model.Request; +using CallfireApiClient.Api.Common.Model.Request; +using CallfireApiClient.Api.Campaigns.Model; +using System.IO; namespace CallfireApiClient.Tests.Integration.CallsTexts { @@ -45,8 +48,8 @@ public void SendCall() { var contacts = Client.ContactsApi.Find(new FindContactsRequest()); - var recipient1 = new CallRecipient { ContactId = contacts.Items[0].Id, LiveMessage = "testMessage" }; - var recipient2 = new CallRecipient { ContactId = contacts.Items[0].Id, LiveMessage = "testMessage" }; + var recipient1 = new CallRecipient { ContactId = contacts.Items[0].Id, LiveMessage = "testMessage", TransferDigit = "1", TransferMessage = "transferTestMessage", TransferNumber = "14246525473" }; + var recipient2 = new CallRecipient { ContactId = contacts.Items[0].Id, LiveMessage = "testMessage", TransferDigit = "1", TransferMessageSoundId = 1, TransferNumber = "14246525473" }; var recipients = new List { recipient1, recipient2 }; IList calls = Client.CallsApi.Send(recipients, null, "items(id,fromNumber,state)"); @@ -56,7 +59,89 @@ public void SendCall() Assert.NotNull(calls[0].Id); Assert.IsNull(calls[0].CampaignId); Assert.AreEqual(StateType.READY, calls[0].State); + + var request = new SendCallsRequest + { + Recipients = recipients, + CampaignId = 7373471003, + Fields = "items(id, fromNumber, state, campaignId)", + DefaultLiveMessage = "DefaultLiveMessage", + DefaultMachineMessage = "DefaultMachineMessage", + DefaultVoice = CallfireApiClient.Api.Campaigns.Model.Voice.FRENCHCANADIAN1 + }; + calls = Client.CallsApi.Send(request); + Assert.AreEqual(2, calls.Count); + Assert.AreEqual(calls[0].CampaignId, 7373471003); + + request = new SendCallsRequest + { + Recipients = recipients, + CampaignId = 7373471003, + Fields = "items(id, fromNumber, state, campaignId)", + DefaultLiveMessageSoundId = 1, + DefaultMachineMessageSoundId = 1, + DefaultVoice = CallfireApiClient.Api.Campaigns.Model.Voice.FRENCHCANADIAN1 + }; + calls = Client.CallsApi.Send(request); + Assert.AreEqual(2, calls.Count); + } + + [Test] + public void GetCallRecording() + { + CallRecording rec = Client.CallsApi.GetCallRecording(1); + Assert.NotNull(rec); + Assert.NotNull(rec.Id); + Assert.NotNull(rec.Mp3Url); + + rec = Client.CallsApi.GetCallRecording(1, "campaignId"); + Assert.Null(rec.Id); + } + + [Test] + public void GetCallRecordingInMp3Format() + { + string mp3FilePath = "Integration/Resources/File-examples/testDownloadRecordingById.mp3"; + MemoryStream ms = (MemoryStream)Client.CallsApi.GetCallRecordingMp3(1); + File.WriteAllBytes(mp3FilePath, ms.ToArray()); + } + + [Test] + public void GetCallRecordings() + { + CallRecording rec = Client.CallsApi.GetCallRecording(1); + IList recs = Client.CallsApi.GetCallRecordings((long) rec.CallId, null); + Assert.NotNull(recs); + Assert.AreEqual(rec.CallId, recs[0].CallId); + + recs = Client.CallsApi.GetCallRecordings((long)rec.CallId, "items(callId)"); + Assert.Null(recs[0].Id); + Assert.Null(recs[0].CallId); + } + + [Test] + public void GetCallRecordingByName() + { + CallRecording rec = Client.CallsApi.GetCallRecording(18666772003); + CallRecording recording = Client.CallsApi.GetCallRecordingByName((long)rec.CallId, rec.Name, null); + Assert.NotNull(recording); + Assert.AreEqual(rec.CallId, recording.CallId); + Assert.AreEqual(rec.Id, recording.Id); + Assert.AreEqual(rec.Name, recording.Name); + Assert.AreEqual(rec.Mp3Url, recording.Mp3Url); + + recording = Client.CallsApi.GetCallRecordingByName((long)rec.CallId, rec.Name, "callId"); + Assert.Null(recording.Id); + Assert.Null(recording.CallId); + } + + [Test] + public void CallRecordingMp3ByName() + { + CallRecording rec = Client.CallsApi.GetCallRecording(18666772003); + string mp3FilePath = "Integration/Resources/File-examples/testDownloadRecordingByName.mp3"; + MemoryStream ms = (MemoryStream)Client.CallsApi.GetCallRecordingMp3ByName((long) rec.CallId, rec.Name); + File.WriteAllBytes(mp3FilePath, ms.ToArray()); } } } - diff --git a/src/CallfireApiClient.Tests/Integration/CallsTexts/TextsApiIntegrationTest.cs b/src/CallfireApiClient.Tests/Integration/CallsTexts/TextsApiIntegrationTest.cs index 7da6556..2c2f74d 100644 --- a/src/CallfireApiClient.Tests/Integration/CallsTexts/TextsApiIntegrationTest.cs +++ b/src/CallfireApiClient.Tests/Integration/CallsTexts/TextsApiIntegrationTest.cs @@ -4,6 +4,7 @@ using CallfireApiClient.Api.Common.Model; using System.Collections.Generic; using NUnit.Framework; +using CallfireApiClient.Api.Common.Model.Request; namespace CallfireApiClient.Tests.Integration.CallsTexts { @@ -45,6 +46,18 @@ public void SendText() Assert.NotNull(texts[0].Id); Assert.IsNull(texts[0].CampaignId); Assert.IsTrue(StateType.READY == texts[0].State || StateType.FINISHED == texts[0].State); + + recipient1.Message = null; + var request = new SendTextsRequest + { + Recipients = recipients, + CampaignId = 7415135003, + DefaultMessage = "DefaultLiveMessage", + Fields = "items(id,fromNumber,state)" + }; + texts = Client.TextsApi.Send(request); + CallfireApiClient.Api.CallsTexts.Model.Text text = Client.TextsApi.Get((long)texts[0].Id); + Assert.AreEqual(text.Message, "DefaultLiveMessage"); } } } diff --git a/src/CallfireApiClient.Tests/Integration/Campaigns/CallBroadcastsApiIntegrationTest.cs b/src/CallfireApiClient.Tests/Integration/Campaigns/CallBroadcastsApiIntegrationTest.cs index ecf01c9..159004c 100644 --- a/src/CallfireApiClient.Tests/Integration/Campaigns/CallBroadcastsApiIntegrationTest.cs +++ b/src/CallfireApiClient.Tests/Integration/Campaigns/CallBroadcastsApiIntegrationTest.cs @@ -28,22 +28,25 @@ public void VoiceBroadcastCrudOperations() { new Recipient { PhoneNumber = "12132212384" }, new Recipient { PhoneNumber = "12132212385" } - } + }, + ResumeNextDay = true }; var id = Client.CallBroadcastsApi.Create(broadcast, true); Console.WriteLine("broadcast id: " + id); var savedBroadcast = Client.CallBroadcastsApi.Get(id.Id); Assert.AreEqual(broadcast.Name, savedBroadcast.Name); - + Assert.AreEqual(savedBroadcast.ResumeNextDay, true); savedBroadcast.Name = "updated_name"; savedBroadcast.Sounds.LiveSoundText = null; savedBroadcast.Sounds.MachineSoundText = null; + savedBroadcast.ResumeNextDay = false; Client.CallBroadcastsApi.Update(savedBroadcast); - var updatedBroadcast = Client.CallBroadcastsApi.Get(id.Id, "id,name"); + var updatedBroadcast = Client.CallBroadcastsApi.Get(id.Id, "id,name,resumeNextDay"); Assert.Null(updatedBroadcast.Status); Assert.NotNull(updatedBroadcast.Id); Assert.AreEqual(savedBroadcast.Name, updatedBroadcast.Name); + Assert.AreEqual(updatedBroadcast.ResumeNextDay, false); } [Test] @@ -101,6 +104,13 @@ public void GetBroadcastCalls() var calls = Client.CallBroadcastsApi.GetCalls(getCallsRequest); Console.WriteLine(calls); Assert.That(calls.Items, Is.Not.Empty); + + long testBatchId = (long) calls.Items[0].BatchId; + + getCallsRequest = new GetBroadcastCallsTextsRequest { Id = 1, batchId = testBatchId }; + calls = Client.CallBroadcastsApi.GetCalls(getCallsRequest); + Console.WriteLine(calls); + Assert.AreEqual(calls.Items[0].BatchId, testBatchId); } [Test] diff --git a/src/CallfireApiClient.Tests/Integration/Campaigns/CampaignSoundsApiIntegrationTest.cs b/src/CallfireApiClient.Tests/Integration/Campaigns/CampaignSoundsApiIntegrationTest.cs index 2dedd23..52297c8 100644 --- a/src/CallfireApiClient.Tests/Integration/Campaigns/CampaignSoundsApiIntegrationTest.cs +++ b/src/CallfireApiClient.Tests/Integration/Campaigns/CampaignSoundsApiIntegrationTest.cs @@ -37,6 +37,11 @@ public void TestCallInToRecord() ResourceId resourceId = Client.CampaignSoundsApi.RecordViaPhone(callCreateSound); Assert.NotNull(resourceId.Id); + + CampaignSound sound = Client.CampaignSoundsApi.RecordViaPhoneAndGetSoundDetails(callCreateSound, "id,name"); + Assert.NotNull(sound.Id); + Assert.NotNull(sound.Name); + Assert.Null(sound.Status); } [Test] @@ -70,6 +75,14 @@ public void TestUploadMp3WavFilesAndGetThem() existingFilePath = Path.GetFullPath("Integration/Resources/File-examples/train1.wav"); pathToSaveNewFile = existingFilePath.Replace("train.wav", "wav_sound.wav"); File.WriteAllBytes(pathToSaveNewFile, ms.ToArray()); + + CampaignSound mp3Resource = Client.CampaignSoundsApi.UploadAndGetSoundDetails(mp3FilePath, soundName); + Assert.True(mp3Resource.Name.Contains("mp3_test")); + Assert.AreEqual(1, mp3Resource.LengthInSeconds); + Assert.True((bool) mp3Resource.Duplicate); + + CampaignSound wavResource = Client.CampaignSoundsApi.UploadAndGetSoundDetails(wavFilePath); + Assert.NotNull(wavResource.Id); } [Test, Ignore("need TTS setup")] @@ -80,6 +93,12 @@ public void TestCreateFromTts() CampaignSound campaignSound = Client.CampaignSoundsApi.Get(resourceId.Id); Assert.AreEqual(resourceId.Id, campaignSound.Id); Assert.Greater(campaignSound.LengthInSeconds, 2); + + CampaignSound sound = Client.CampaignSoundsApi.CreateFromTtsAndGetSoundDetails(tts, "id,name"); + Assert.NotNull(sound.Id); + Assert.NotNull(sound.Name); + Assert.Null(sound.Status); + Assert.AreEqual(sound.Id, campaignSound.Id); } } } \ No newline at end of file diff --git a/src/CallfireApiClient.Tests/Integration/Campaigns/TextBroadcastsApiIntegrationTest.cs b/src/CallfireApiClient.Tests/Integration/Campaigns/TextBroadcastsApiIntegrationTest.cs index a483558..9f67a7d 100644 --- a/src/CallfireApiClient.Tests/Integration/Campaigns/TextBroadcastsApiIntegrationTest.cs +++ b/src/CallfireApiClient.Tests/Integration/Campaigns/TextBroadcastsApiIntegrationTest.cs @@ -31,19 +31,22 @@ public void CrudOperations() { new TextRecipient { PhoneNumber = "14246525473" }, new TextRecipient { PhoneNumber = "12132041238" } - } + }, + ResumeNextDay = true }; var id = Client.TextBroadcastsApi.Create(broadcast, true); var savedBroadcast = Client.TextBroadcastsApi.Get(id.Id); Assert.AreEqual(broadcast.Name, savedBroadcast.Name); - + Assert.AreEqual(savedBroadcast.ResumeNextDay, true); savedBroadcast.Name = "updated_name"; + savedBroadcast.ResumeNextDay = false; Client.TextBroadcastsApi.Update(savedBroadcast); var updatedBroadcast = Client.TextBroadcastsApi.Get(id.Id, "id,name"); Assert.Null(updatedBroadcast.Status); Assert.NotNull(updatedBroadcast.Id); Assert.AreEqual(savedBroadcast.Name, updatedBroadcast.Name); + Assert.AreEqual(savedBroadcast.ResumeNextDay, false); } [Test] @@ -84,6 +87,12 @@ public void GetBroadcastTexts() var texts = Client.TextBroadcastsApi.GetTexts(request); Console.WriteLine(texts); Assert.That(texts.Items, Is.Not.Empty); + + long testBatchId = (long)texts.Items[0].BatchId; + + request = new GetBroadcastCallsTextsRequest { Id = broadcastId.Id, batchId = testBatchId }; + texts = Client.TextBroadcastsApi.GetTexts(request); + Assert.AreEqual(texts.Items[0].BatchId, testBatchId); } [Test] diff --git a/src/CallfireApiClient.Tests/Integration/Keywords/KeywordsApiIntegrationTest.cs b/src/CallfireApiClient.Tests/Integration/Keywords/KeywordsApiIntegrationTest.cs index c9731cb..da75bc8 100644 --- a/src/CallfireApiClient.Tests/Integration/Keywords/KeywordsApiIntegrationTest.cs +++ b/src/CallfireApiClient.Tests/Integration/Keywords/KeywordsApiIntegrationTest.cs @@ -31,7 +31,7 @@ public void FindKeywords() public void IsAvailable() { Boolean isAvaialble = Client.KeywordsApi.IsAvailable("TEST"); - Assert.AreEqual(false, isAvaialble); + Assert.AreEqual(true, isAvaialble); } } diff --git a/src/CallfireApiClient.Tests/Integration/Webhooks/WebhooksApiIntegrationTest.cs b/src/CallfireApiClient.Tests/Integration/Webhooks/WebhooksApiIntegrationTest.cs index 3db0832..1baa992 100644 --- a/src/CallfireApiClient.Tests/Integration/Webhooks/WebhooksApiIntegrationTest.cs +++ b/src/CallfireApiClient.Tests/Integration/Webhooks/WebhooksApiIntegrationTest.cs @@ -31,7 +31,7 @@ public void CrudOperations() Fields = "items(id,callback,name,resource,events)" }; var page = api.Find(findRequest); - Assert.That(page.Items, Has.Count.EqualTo(1)); + Assert.That(page.Items.Count > 1); Assert.AreEqual("test_name1", page.Items[0].Name); Assert.AreEqual("test_callback", page.Items[0].Callback); Assert.AreEqual(ResourceType.TEXT_BROADCAST, page.Items[0].Resource); @@ -39,7 +39,7 @@ public void CrudOperations() Assert.NotNull(page.Items[0].Id); webhook = page.Items[0]; - webhook.Resource = ResourceType.VOICE_BROADCAST; + webhook.Name = "test_name2"; api.Update(webhook); Webhook updated = api.Get((long)webhook.Id); Assert.AreEqual(webhook.Resource, updated.Resource); @@ -50,6 +50,25 @@ public void CrudOperations() Assert.Throws(() => api.Get((long)resourceId1.Id)); Assert.Throws(() => api.Get((long)resourceId2.Id)); } - } -} + [Test] + public void TestResourceTypeOperations() + { + var api = Client.WebhooksApi; + var resources = api.FindWebhookResources(null); + Assert.NotNull(resources); + Assert.AreEqual(resources.Count, 9); + resources = api.FindWebhookResources("items(resource)"); + Assert.NotNull(resources[0].Resource); + Assert.AreEqual(resources[0].SupportedEvents, null); + + WebhookResource resource = api.FindWebhookResource(ResourceType.CALL_BROADCAST, null); + Assert.NotNull(resource); + Assert.NotNull(resource.SupportedEvents); + Assert.AreEqual(resource.Resource, "CallBroadcast"); + resource = api.FindWebhookResource(ResourceType.CALL_BROADCAST, "resource"); + Assert.NotNull(resource.Resource); + Assert.AreEqual(resource.SupportedEvents, null); + } + } +} \ No newline at end of file diff --git a/src/CallfireApiClient.Tests/JsonMocks/callstexts/callsApi/request/sendCalls.json b/src/CallfireApiClient.Tests/JsonMocks/callstexts/callsApi/request/sendCalls.json index d099d3c..773bd71 100644 --- a/src/CallfireApiClient.Tests/JsonMocks/callstexts/callsApi/request/sendCalls.json +++ b/src/CallfireApiClient.Tests/JsonMocks/callstexts/callsApi/request/sendCalls.json @@ -1,7 +1,10 @@ [ { "phoneNumber": "12135551100", - "liveMessage": "Why hello there!" + "liveMessage": "Why hello there!", + "transferMessage": "testMessage", + "transferDigit": "1", + "transferNumber": "12135551101" }, { "phoneNumber": "12135551101", diff --git a/src/CallfireApiClient.Tests/JsonMocks/callstexts/callsApi/response/getCallRecording.json b/src/CallfireApiClient.Tests/JsonMocks/callstexts/callsApi/response/getCallRecording.json new file mode 100644 index 0000000..947a0d2 --- /dev/null +++ b/src/CallfireApiClient.Tests/JsonMocks/callstexts/callsApi/response/getCallRecording.json @@ -0,0 +1,12 @@ +{ + "id": 10, + "callId": 12, + "campaignId": 13, + "name": "testName", + "created": 1480896000000, + "lengthInBytes": 150, + "lengthInSeconds": 10, + "hash": "hashTest", + "mp3Url": "http://test", + "state": "RECORDING" +} \ No newline at end of file diff --git a/src/CallfireApiClient.Tests/JsonMocks/callstexts/callsApi/response/getCallRecordings.json b/src/CallfireApiClient.Tests/JsonMocks/callstexts/callsApi/response/getCallRecordings.json new file mode 100644 index 0000000..52efba5 --- /dev/null +++ b/src/CallfireApiClient.Tests/JsonMocks/callstexts/callsApi/response/getCallRecordings.json @@ -0,0 +1,28 @@ +{ + "items": [ + { + "id": 10, + "callId": 12, + "campaignId": 13, + "name": "test", + "created": 1480896000000, + "lengthInBytes": 150, + "lengthInSeconds": 10, + "hash": "hashTest", + "mp3Url": "http://test", + "state": "RECORDING" + }, + { + "id": 11, + "callId": 13, + "campaignId": 13, + "name": "test", + "created": 1480896000000, + "lengthInBytes": 150, + "lengthInSeconds": 10, + "hash": "hashTest", + "mp3Url": "http://test", + "state": "RECORDING" + } + ] +} diff --git a/src/CallfireApiClient.Tests/JsonMocks/campaigns/callBroadcastsApi/request/createCallBroadcast.json b/src/CallfireApiClient.Tests/JsonMocks/campaigns/callBroadcastsApi/request/createCallBroadcast.json index 39b07f2..28cf761 100644 --- a/src/CallfireApiClient.Tests/JsonMocks/campaigns/callBroadcastsApi/request/createCallBroadcast.json +++ b/src/CallfireApiClient.Tests/JsonMocks/campaigns/callBroadcastsApi/request/createCallBroadcast.json @@ -1,6 +1,7 @@ { "name": "Example API VB", "fromNumber": "12135551189", + "resumeNextDay": true, "recipients": [ { "phoneNumber": "13233832214" diff --git a/src/CallfireApiClient.Tests/JsonMocks/campaigns/callBroadcastsApi/request/updateCallBroadcast.json b/src/CallfireApiClient.Tests/JsonMocks/campaigns/callBroadcastsApi/request/updateCallBroadcast.json index 604e2d6..ec001bd 100644 --- a/src/CallfireApiClient.Tests/JsonMocks/campaigns/callBroadcastsApi/request/updateCallBroadcast.json +++ b/src/CallfireApiClient.Tests/JsonMocks/campaigns/callBroadcastsApi/request/updateCallBroadcast.json @@ -2,6 +2,7 @@ "id": 11, "name": "Example API VB updated", "fromNumber": "12135551189", + "resumeNextDay": true, "sounds": { "liveSoundText": "Hello! This is an updated VB config tts", "machineSoundId": 1258704003 diff --git a/src/CallfireApiClient.Tests/JsonMocks/campaigns/callBroadcastsApi/response/findCallBroadcasts.json b/src/CallfireApiClient.Tests/JsonMocks/campaigns/callBroadcastsApi/response/findCallBroadcasts.json index 040e1f0..352f79b 100644 --- a/src/CallfireApiClient.Tests/JsonMocks/campaigns/callBroadcastsApi/response/findCallBroadcasts.json +++ b/src/CallfireApiClient.Tests/JsonMocks/campaigns/callBroadcastsApi/response/findCallBroadcasts.json @@ -14,6 +14,7 @@ "endMinute": 0 }, "maxActive": 100, + "resumeNextDay": true, "retryConfig": { "maxAttempts": 1, "minutesBetweenAttempts": 60, @@ -42,6 +43,7 @@ "endMinute": 0 }, "maxActive": 100, + "resumeNextDay": true, "retryConfig": { "maxAttempts": 1, "minutesBetweenAttempts": 60, diff --git a/src/CallfireApiClient.Tests/JsonMocks/campaigns/callBroadcastsApi/response/getCallBroadcast.json b/src/CallfireApiClient.Tests/JsonMocks/campaigns/callBroadcastsApi/response/getCallBroadcast.json index 585ccde..8643b28 100644 --- a/src/CallfireApiClient.Tests/JsonMocks/campaigns/callBroadcastsApi/response/getCallBroadcast.json +++ b/src/CallfireApiClient.Tests/JsonMocks/campaigns/callBroadcastsApi/response/getCallBroadcast.json @@ -12,6 +12,7 @@ "endMinute": 0 }, "maxActive": 100, + "resumeNextDay": true, "retryConfig": { "maxAttempts": 1, "minutesBetweenAttempts": 60, diff --git a/src/CallfireApiClient.Tests/JsonMocks/campaigns/campaignSoundsApi/response/uploadSoundWithDetails.json b/src/CallfireApiClient.Tests/JsonMocks/campaigns/campaignSoundsApi/response/uploadSoundWithDetails.json new file mode 100644 index 0000000..d1641a7 --- /dev/null +++ b/src/CallfireApiClient.Tests/JsonMocks/campaigns/campaignSoundsApi/response/uploadSoundWithDetails.json @@ -0,0 +1,6 @@ +{ + "id": 61, + "name": "My sound file", + "status": "UPLOAD", + "duplicate": true +} \ No newline at end of file diff --git a/src/CallfireApiClient.Tests/JsonMocks/campaigns/textBroadcastsApi/request/createTextBroadcast.json b/src/CallfireApiClient.Tests/JsonMocks/campaigns/textBroadcastsApi/request/createTextBroadcast.json index da65231..53bbf6a 100644 --- a/src/CallfireApiClient.Tests/JsonMocks/campaigns/textBroadcastsApi/request/createTextBroadcast.json +++ b/src/CallfireApiClient.Tests/JsonMocks/campaigns/textBroadcastsApi/request/createTextBroadcast.json @@ -1,6 +1,7 @@ { "name": "Example API SMS", "fromNumber": "19206596476", + "resumeNextDay": true, "message": "Hello World!", "recipients": [ { diff --git a/src/CallfireApiClient.Tests/JsonMocks/campaigns/textBroadcastsApi/request/updateTextBroadcast.json b/src/CallfireApiClient.Tests/JsonMocks/campaigns/textBroadcastsApi/request/updateTextBroadcast.json index cc5f171..b052c70 100644 --- a/src/CallfireApiClient.Tests/JsonMocks/campaigns/textBroadcastsApi/request/updateTextBroadcast.json +++ b/src/CallfireApiClient.Tests/JsonMocks/campaigns/textBroadcastsApi/request/updateTextBroadcast.json @@ -1,5 +1,6 @@ { "id": 11, "name": "Example API SMS updated", + "resumeNextDay": true, "message": "a new test message" } \ No newline at end of file diff --git a/src/CallfireApiClient.Tests/JsonMocks/campaigns/textBroadcastsApi/response/findTextBroadcasts.json b/src/CallfireApiClient.Tests/JsonMocks/campaigns/textBroadcastsApi/response/findTextBroadcasts.json index 0eb6273..1b2310b 100644 --- a/src/CallfireApiClient.Tests/JsonMocks/campaigns/textBroadcastsApi/response/findTextBroadcasts.json +++ b/src/CallfireApiClient.Tests/JsonMocks/campaigns/textBroadcastsApi/response/findTextBroadcasts.json @@ -9,6 +9,7 @@ "localTimeRestriction": { "enabled": false }, + "resumeNextDay": true, "message": "This is a text broadcast", "bigMessageStrategy": "DO_NOT_SEND" }, @@ -21,6 +22,7 @@ "localTimeRestriction": { "enabled": false }, + "resumeNextDay": true, "message": "Hello World!" } ], diff --git a/src/CallfireApiClient.Tests/JsonMocks/campaigns/textBroadcastsApi/response/getTextBroadcast.json b/src/CallfireApiClient.Tests/JsonMocks/campaigns/textBroadcastsApi/response/getTextBroadcast.json index dd59f37..0abb019 100644 --- a/src/CallfireApiClient.Tests/JsonMocks/campaigns/textBroadcastsApi/response/getTextBroadcast.json +++ b/src/CallfireApiClient.Tests/JsonMocks/campaigns/textBroadcastsApi/response/getTextBroadcast.json @@ -7,5 +7,6 @@ "localTimeRestriction": { "enabled": false }, + "resumeNextDay": true, "message": "Hello World!" } \ No newline at end of file diff --git a/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/request/createWebhook.json b/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/request/createWebhook.json index e3874c5..407e3ad 100644 --- a/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/request/createWebhook.json +++ b/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/request/createWebhook.json @@ -1,9 +1,9 @@ { "name": "API hook", - "resource": "textCampaign", + "resource": "TextBroadcast", "callback": "http://yoursite.com/webhook", "events": [ - "start", - "stop" + "Started", + "Stopped" ] } \ No newline at end of file diff --git a/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/request/updateWebhook.json b/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/request/updateWebhook.json index f60acea..d779f2d 100644 --- a/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/request/updateWebhook.json +++ b/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/request/updateWebhook.json @@ -1,9 +1,9 @@ { "id": 11, "name": "API hook", - "resource": "textCampaign", + "resource": "TextBroadcast", "callback": "http://yoursite.com/webhook", "events": [ - "stop" + "Stopped" ] } \ No newline at end of file diff --git a/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/response/findSpecificWebhookResource.json b/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/response/findSpecificWebhookResource.json new file mode 100644 index 0000000..d6b8b42 --- /dev/null +++ b/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/response/findSpecificWebhookResource.json @@ -0,0 +1,8 @@ +{ + "resource": "CallBroadcast", + "supportedEvents": [ + "Started", + "Stopped", + "Finished" + ] +} diff --git a/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/response/findWebhookResources.json b/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/response/findWebhookResources.json new file mode 100644 index 0000000..226c564 --- /dev/null +++ b/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/response/findWebhookResources.json @@ -0,0 +1,66 @@ +{ + "items": [ + { + "resource": "MonthlyRenewal", + "supportedEvents": [ + "Failed", + "Finished" + ] + }, + { + "resource": "LowBalance", + "supportedEvents": [ + "Failed", + "Finished" + ] + }, + { + "resource": "CccCampaign", + "supportedEvents": [ + "Started", + "Stopped", + "Finished" + ] + }, + { + "resource": "CallBroadcast", + "supportedEvents": [ + "Started", + "Stopped", + "Finished" + ] + }, + { + "resource": "TextBroadcast", + "supportedEvents": [ + "Started", + "Stopped", + "Finished" + ] + }, + { + "resource": "OutboundCall", + "supportedEvents": [ + "Finished" + ] + }, + { + "resource": "InboundCall", + "supportedEvents": [ + "Finished" + ] + }, + { + "resource": "OutboundText", + "supportedEvents": [ + "Finished" + ] + }, + { + "resource": "InboundText", + "supportedEvents": [ + "Finished" + ] + } + ] +} diff --git a/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/response/findWebhooks.json b/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/response/findWebhooks.json index 7697af0..0648ca4 100644 --- a/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/response/findWebhooks.json +++ b/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/response/findWebhooks.json @@ -4,26 +4,26 @@ "id": 4321, "enabled": false, "name": "API hook", - "resource": "textCampaign", + "resource": "TextBroadcast", "callback": "https://callfire.com/newText", "createdAt": 1443408255000, "updatedAt": 1443408255000, "events": [ - "stop", - "start" + "Started", + "Stopped" ] }, { "id": 2, "enabled": false, "name": "API hook", - "resource": "textCampaign", + "resource": "TextBroadcast", "callback": "https://www.callfire.com/stoppedTexts", "createdAt": 1443408445000, "updatedAt": 1443408445000, "events": [ - "stop", - "start" + "Started", + "Stopped" ] } ], diff --git a/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/response/getWebhook.json b/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/response/getWebhook.json index 31fa21a..95db823 100644 --- a/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/response/getWebhook.json +++ b/src/CallfireApiClient.Tests/JsonMocks/webhooks/webhooksApi/response/getWebhook.json @@ -2,12 +2,12 @@ "id": 4321, "enabled": false, "name": "API hook", - "resource": "textCampaign", + "resource": "TextBroadcast", "callback": "http://webhook.receiver.xyz/endpoint", "createdAt": 1443408255000, "updatedAt": 1443408255000, "events": [ - "stop", - "start" + "Started", + "Stopped" ] } \ No newline at end of file diff --git a/src/CallfireApiClient/Api/CallsTexts/CallsApi.cs b/src/CallfireApiClient/Api/CallsTexts/CallsApi.cs index 24f4924..17459ca 100644 --- a/src/CallfireApiClient/Api/CallsTexts/CallsApi.cs +++ b/src/CallfireApiClient/Api/CallsTexts/CallsApi.cs @@ -2,6 +2,9 @@ using CallfireApiClient.Api.CallsTexts.Model; using System.Collections.Generic; using CallfireApiClient.Api.CallsTexts.Model.Request; +using CallfireApiClient.Api.Common.Model.Request; +using CallfireApiClient.Api.Campaigns.Model; +using System.IO; namespace CallfireApiClient.Api.CallsTexts { @@ -9,6 +12,11 @@ public class CallsApi { private const string CALLS_PATH = "/calls"; private const string CALLS_ITEM_PATH = "/calls/{}"; + private static string CALLS_ITEM_RECORDINGS_PATH = "/calls/{}/recordings"; + private static string CALLS_ITEM_RECORDING_BY_NAME_PATH = "/calls/{}/recordings/{}"; + private static string CALLS_ITEM_MP3_RECORDING_BY_NAME_PATH = "/calls/{}/recordings/{}.mp3"; + private static string CALLS_ITEM_RECORDING_BY_ID_PATH = "/calls/recordings/{}"; + private static string CALLS_ITEM_MP3_RECORDING_BY_ID_PATH = "/calls/recordings/{}.mp3"; private readonly RestApiClient Client; @@ -81,5 +89,131 @@ public IList Send(IList recipients, long? campaignId = null ClientUtils.AddQueryParamIfSet("fields", fields, queryParams); return Client.Post>(CALLS_PATH, recipients, queryParams).Items; } + + /// + /// Send calls to recipients through default campaign. + /// Use the API to quickly send individual calls. + /// A verified Caller ID and sufficient credits are required to make a call. + /// + /// request object with different fields to filter + /// list with created call objects + /// in case HTTP response code is 400 - Bad request, the request was formatted improperly. + /// in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. + /// in case HTTP response code is 403 - Forbidden, insufficient permissions. + /// in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. + /// in case HTTP response code is 500 - Internal Server Error. + /// in case HTTP response code is something different from codes listed above. + /// in case error has occurred in client. + public IList Send(SendCallsRequest request) + { + Validate.NotBlank(request.Recipients.ToString(), "recipients cannot be blank"); + var queryParams = ClientUtils.BuildQueryParams(request); + return Client.Post>(CALLS_PATH, request.Recipients, queryParams).Items; + } + + /// + /// Returns call recordings for a call + /// + /// id of call + /// Limit text fields returned. Example fields=limit,offset,items(id,message) + /// CallRecording objects list + /// in case HTTP response code is 400 - Bad request, the request was formatted improperly. + /// in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. + /// in case HTTP response code is 403 - Forbidden, insufficient permissions. + /// in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. + /// in case HTTP response code is 500 - Internal Server Error. + /// in case HTTP response code is something different from codes listed above. + /// in case error has occurred in client. + public IList GetCallRecordings(long id, string fields = null) + { + Validate.NotBlank(id.ToString(), "id cannot be blank"); + string path = CALLS_ITEM_RECORDINGS_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, id.ToString()); + var queryParams = ClientUtils.BuildQueryParams("fields", fields); + return Client.Get>(path, queryParams).Items; + } + + /// + /// Returns call recording by name + /// + /// id of call + /// name of call recording + /// limit fields returned. Example fields=id,name + /// CallRecording object + /// in case HTTP response code is 400 - Bad request, the request was formatted improperly. + /// in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. + /// in case HTTP response code is 403 - Forbidden, insufficient permissions. + /// in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. + /// in case HTTP response code is 500 - Internal Server Error. + /// in case HTTP response code is something different from codes listed above. + /// in case error has occurred in client. + public CallRecording GetCallRecordingByName(long callId, string recordingName, string fields = null) + { + Validate.NotBlank(callId.ToString(), "callId cannot be blank"); + Validate.NotBlank(recordingName, "recordingName cannot be blank"); + string path = CALLS_ITEM_RECORDING_BY_NAME_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, callId.ToString()).ReplaceFirst(ClientConstants.PLACEHOLDER, recordingName); + var queryParams = ClientUtils.BuildQueryParams("fields", fields); + return Client.Get(path, queryParams); + } + + /// + /// Download call mp3 recording by name + /// + /// id of call + /// name of call recording + /// Call recording meta object + /// in case HTTP response code is 400 - Bad request, the request was formatted improperly. + /// in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. + /// in case HTTP response code is 403 - Forbidden, insufficient permissions. + /// in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. + /// in case HTTP response code is 500 - Internal Server Error. + /// in case HTTP response code is something different from codes listed above. + /// in case error has occurred in client. + public Stream GetCallRecordingMp3ByName(long callId, string recordingName) + { + Validate.NotBlank(callId.ToString(), "callId cannot be blank"); + Validate.NotBlank(recordingName, "recordingName cannot be blank"); + string path = CALLS_ITEM_MP3_RECORDING_BY_NAME_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, callId.ToString()).ReplaceFirst(ClientConstants.PLACEHOLDER, recordingName); + return Client.GetFileData(path); + } + + /// + /// Returns call recording by id + /// + /// id of call recording + /// limit fields returned. Example fields=id,name + /// CallRecording objects list + /// in case HTTP response code is 400 - Bad request, the request was formatted improperly. + /// in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. + /// in case HTTP response code is 403 - Forbidden, insufficient permissions. + /// in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. + /// in case HTTP response code is 500 - Internal Server Error. + /// in case HTTP response code is something different from codes listed above. + /// in case error has occurred in client. + public CallRecording GetCallRecording(long id, string fields = null) + { + Validate.NotBlank(id.ToString(), "id cannot be blank"); + string path = CALLS_ITEM_RECORDING_BY_ID_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, id.ToString()); + var queryParams = ClientUtils.BuildQueryParams("fields", fields); + return Client.Get(path, queryParams); + } + + /// + /// Download call mp3 recording by id + /// + /// id of call + /// Call recording meta object + /// in case HTTP response code is 400 - Bad request, the request was formatted improperly. + /// in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. + /// in case HTTP response code is 403 - Forbidden, insufficient permissions. + /// in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. + /// in case HTTP response code is 500 - Internal Server Error. + /// in case HTTP response code is something different from codes listed above. + /// in case error has occurred in client. + public Stream GetCallRecordingMp3(long id) + { + Validate.NotBlank(id.ToString(), "callId cannot be blank"); + string path = CALLS_ITEM_MP3_RECORDING_BY_ID_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, id.ToString()); + return Client.GetFileData(path); + } } -} \ No newline at end of file +} diff --git a/src/CallfireApiClient/Api/CallsTexts/Model/CallRecipient.cs b/src/CallfireApiClient/Api/CallsTexts/Model/CallRecipient.cs index 99546e3..402cf92 100644 --- a/src/CallfireApiClient/Api/CallsTexts/Model/CallRecipient.cs +++ b/src/CallfireApiClient/Api/CallsTexts/Model/CallRecipient.cs @@ -8,12 +8,16 @@ public class CallRecipient : Recipient public long? LiveMessageSoundId { get; set; } public string MachineMessage { get; set; } public long? MachineMessageSoundId { get; set; } + public string TransferMessage { get; set; } + public long? TransferMessageSoundId { get; set; } + public string TransferDigit { get; set; } + public string TransferNumber { get; set; } public Voice? Voice { get; set; } public override string ToString() { - return string.Format("[CallRecipient: {0}, liveMessage={1}, liveMessageSoundId={2}, machineMessage={3}, machineMessageSoundId={4}, voice={5}]", base.ToString(), - LiveMessage, LiveMessageSoundId, MachineMessage, MachineMessageSoundId, Voice); + return string.Format("[CallRecipient: {0}, liveMessage={1}, liveMessageSoundId={2}, machineMessage={3}, machineMessageSoundId={4}, transferMessage={5}, transferMessageSoundId={6}, transferDigit={7}, transferNumber={8}, voice={9]", base.ToString(), + LiveMessage, LiveMessageSoundId, MachineMessage, MachineMessageSoundId, TransferMessage, TransferMessageSoundId, TransferDigit, TransferNumber, Voice); } } } diff --git a/src/CallfireApiClient/Api/CallsTexts/Model/Request/SendCallsRequest.cs b/src/CallfireApiClient/Api/CallsTexts/Model/Request/SendCallsRequest.cs new file mode 100644 index 0000000..30ed384 --- /dev/null +++ b/src/CallfireApiClient/Api/CallsTexts/Model/Request/SendCallsRequest.cs @@ -0,0 +1,43 @@ + + +using CallfireApiClient.Api.CallsTexts.Model; +using CallfireApiClient.Api.Campaigns.Model; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace CallfireApiClient.Api.Common.Model.Request +{ + /// + /// Contains fields to send calls (recipients, campaignId etc) + /// + public class SendCallsRequest : CallfireModel + { + [JsonIgnore] + public List Recipients; + + public long? CampaignId { get; set; } + + public string DefaultLiveMessage { get; set; } + + public string DefaultMachineMessage { get; set; } + + public long? DefaultLiveMessageSoundId { get; set; } + + public long? DefaultMachineMessageSoundId { get; set; } + + public Voice DefaultVoice { get; set; } + + public string Fields { get; set; } + + public SendCallsRequest() + { + Recipients = new List(); + } + + public override string ToString() + { + return string.Format("[SendCallsRequest: Recipients={0}, CampaignId={1}, DefaultLiveMessage={2}, DefaultMachineMessage={3}, DefaultLiveMessageSoundId={4}, DefaultMachineMessageSoundId ={5}, DefaultVoice ={6}, Fields ={7}]", + Recipients, CampaignId, DefaultLiveMessage, DefaultMachineMessage, DefaultLiveMessageSoundId, DefaultMachineMessageSoundId, DefaultVoice, Fields); + } + } +} diff --git a/src/CallfireApiClient/Api/CallsTexts/Model/Request/SendTextsRequest.cs b/src/CallfireApiClient/Api/CallsTexts/Model/Request/SendTextsRequest.cs new file mode 100644 index 0000000..e2b7345 --- /dev/null +++ b/src/CallfireApiClient/Api/CallsTexts/Model/Request/SendTextsRequest.cs @@ -0,0 +1,35 @@ + + +using CallfireApiClient.Api.CallsTexts.Model; +using CallfireApiClient.Api.Campaigns.Model; +using Newtonsoft.Json; +using System.Collections.Generic; + +namespace CallfireApiClient.Api.Common.Model.Request +{ + /// + /// Contains fields to send texts (recipients, campaignId etc) + /// + public class SendTextsRequest : CallfireModel + { + [JsonIgnore] + public List Recipients; + + public long? CampaignId { get; set; } + + public string DefaultMessage { get; set; } + + public string Fields { get; set; } + + public SendTextsRequest() + { + Recipients = new List(); + } + + public override string ToString() + { + return string.Format("[SendCallsRequest: Recipients={0}, CampaignId={1}, DefaultMessage={2}, Fields ={3}]", + Recipients, CampaignId, DefaultMessage, Fields); + } + } +} diff --git a/src/CallfireApiClient/Api/CallsTexts/TextsApi.cs b/src/CallfireApiClient/Api/CallsTexts/TextsApi.cs index c7f5464..20a37f8 100644 --- a/src/CallfireApiClient/Api/CallsTexts/TextsApi.cs +++ b/src/CallfireApiClient/Api/CallsTexts/TextsApi.cs @@ -2,6 +2,7 @@ using CallfireApiClient.Api.CallsTexts.Model; using System.Collections.Generic; using CallfireApiClient.Api.CallsTexts.Model.Request; +using CallfireApiClient.Api.Common.Model.Request; namespace CallfireApiClient.Api.CallsTexts { @@ -82,5 +83,26 @@ public IList Send(List recipients, long? campaignId = null, ClientUtils.AddQueryParamIfSet("fields", fields, queryParams); return Client.Post>(TEXTS_PATH, recipients, queryParams).Items; } + + /// + /// Send texts to recipients through existing campaign, if null default campaign will be used + /// Use the /texts API to quickly send individual texts.A verified Caller ID and sufficient + /// credits are required to make a call. + /// + /// request object with different fields to filter + /// list with created text objects + /// in case HTTP response code is 400 - Bad request, the request was formatted improperly. + /// in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. + /// in case HTTP response code is 403 - Forbidden, insufficient permissions. + /// in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. + /// in case HTTP response code is 500 - Internal Server Error. + /// in case HTTP response code is something different from codes listed above. + /// in case error has occurred in client. + public IList Send(SendTextsRequest request) + { + Validate.NotBlank(request.Recipients.ToString(), "recipients cannot be blank"); + var queryParams = ClientUtils.BuildQueryParams(request); + return Client.Post>(TEXTS_PATH, request.Recipients, queryParams).Items; + } } } \ No newline at end of file diff --git a/src/CallfireApiClient/Api/Campaigns/CallBroadcastsApi.cs b/src/CallfireApiClient/Api/Campaigns/CallBroadcastsApi.cs index 13249da..714fd7a 100644 --- a/src/CallfireApiClient/Api/Campaigns/CallBroadcastsApi.cs +++ b/src/CallfireApiClient/Api/Campaigns/CallBroadcastsApi.cs @@ -204,12 +204,31 @@ public ResourceId AddBatch(AddBatchRequest request) /// in case HTTP response code is 500 - Internal Server Error. /// in case HTTP response code is something different from codes listed above. /// in case error has occurred in client. + [Obsolete] public Page GetCalls(GetByIdRequest request) { String path = CB_ITEM_CALLS_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, request.Id.ToString()); return Client.Get>(path, request); } + /// + /// Get calls associated with call broadcast ordered by date + /// + /// request with properties to filter + /// calls assosiated with broadcast + /// in case HTTP response code is 400 - Bad request, the request was formatted improperly. + /// in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. + /// in case HTTP response code is 403 - Forbidden, insufficient permissions. + /// in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. + /// in case HTTP response code is 500 - Internal Server Error. + /// in case HTTP response code is something different from codes listed above. + /// in case error has occurred in client. + public Page GetCalls(GetBroadcastCallsTextsRequest request) + { + String path = CB_ITEM_CALLS_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, request.Id.ToString()); + return Client.Get>(path, request); + } + /// /// Get statistics on call broadcast /// diff --git a/src/CallfireApiClient/Api/Campaigns/CampaignSoundsApi.cs b/src/CallfireApiClient/Api/Campaigns/CampaignSoundsApi.cs index 4f85010..3679451 100644 --- a/src/CallfireApiClient/Api/Campaigns/CampaignSoundsApi.cs +++ b/src/CallfireApiClient/Api/Campaigns/CampaignSoundsApi.cs @@ -2,6 +2,7 @@ using CallfireApiClient.Api.Common.Model; using CallfireApiClient.Api.CallsTexts.Model.Request; using System.IO; +using System; namespace CallfireApiClient.Api.Campaigns { @@ -114,11 +115,33 @@ public Stream GetWav(long id) /// in case HTTP response code is 500 - Internal Server Error. /// in case HTTP response code is something different from codes listed above. /// in case error has occurred in client. + [Obsolete] public ResourceId RecordViaPhone(CallCreateSound callCreateSound) { return Client.Post(SOUNDS_CALLS_PATH, callCreateSound); } + /// + /// Use this API to create a sound via phone call. Supply the required phone number in + /// the CallCreateSound object inside of the request, and the user will receive a call + /// shortly after with instructions on how to record a sound over the phone. + /// + /// request object to create campaign sound + /// Limit text fields returned. Example fields=limit,offset,items(id,message) + /// CampaignSound object with sound details + /// in case HTTP response code is 400 - Bad request, the request was formatted improperly. + /// in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. + /// in case HTTP response code is 403 - Forbidden, insufficient permissions. + /// in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. + /// in case HTTP response code is 500 - Internal Server Error. + /// in case HTTP response code is something different from codes listed above. + /// in case error has occurred in client. + public CampaignSound RecordViaPhoneAndGetSoundDetails(CallCreateSound callCreateSound, string fields) + { + var queryParams = ClientUtils.BuildQueryParams("fields", fields); + return Client.Post(SOUNDS_CALLS_PATH, callCreateSound, queryParams); + } + /// /// Upload a MP3 or WAV file to account /// @@ -132,11 +155,30 @@ public ResourceId RecordViaPhone(CallCreateSound callCreateSound) /// in case HTTP response code is 500 - Internal Server Error. /// in case HTTP response code is something different from codes listed above. /// in case error has occurred in client. + [Obsolete] public ResourceId Upload(string pathToFile, string name = null) { return Client.PostFile(SOUNDS_FILES_PATH, name, pathToFile); } + /// + /// Upload a MP3 or WAV file to account + /// + /// contact list name + /// path to MP3 or WAV file + /// CampaignSound object with sound details + /// in case HTTP response code is 400 - Bad request, the request was formatted improperly. + /// in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. + /// in case HTTP response code is 403 - Forbidden, insufficient permissions. + /// in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. + /// in case HTTP response code is 500 - Internal Server Error. + /// in case HTTP response code is something different from codes listed above. + /// in case error has occurred in client. + public CampaignSound UploadAndGetSoundDetails(string pathToFile, string name = null) + { + return Client.PostFile(SOUNDS_FILES_PATH, name, pathToFile); + } + /// /// Use this API to create a sound file via a supplied string of text. /// @@ -149,9 +191,29 @@ public ResourceId Upload(string pathToFile, string name = null) /// in case HTTP response code is 500 - Internal Server Error. /// in case HTTP response code is something different from codes listed above. /// in case error has occurred in client. + [Obsolete] public ResourceId CreateFromTts(TextToSpeech textToSpeech) { return Client.Post(SOUNDS_TTS_PATH, textToSpeech); } + + /// + /// Use this API to create a sound file via a supplied string of text. + /// + /// TTS object to create + /// Limit text fields returned. Example fields=limit,offset,items(id,message) + /// CampaignSound object with sound details + /// in case HTTP response code is 400 - Bad request, the request was formatted improperly. + /// in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. + /// in case HTTP response code is 403 - Forbidden, insufficient permissions. + /// in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. + /// in case HTTP response code is 500 - Internal Server Error. + /// in case HTTP response code is something different from codes listed above. + /// in case error has occurred in client. + public CampaignSound CreateFromTtsAndGetSoundDetails(TextToSpeech textToSpeech, string fields) + { + var queryParams = ClientUtils.BuildQueryParams("fields", fields); + return Client.Post(SOUNDS_TTS_PATH, textToSpeech, queryParams); + } } } \ No newline at end of file diff --git a/src/CallfireApiClient/Api/Campaigns/Model/Broadcast.cs b/src/CallfireApiClient/Api/Campaigns/Model/Broadcast.cs index fdf8556..f740b03 100644 --- a/src/CallfireApiClient/Api/Campaigns/Model/Broadcast.cs +++ b/src/CallfireApiClient/Api/Campaigns/Model/Broadcast.cs @@ -27,10 +27,12 @@ public abstract class Broadcast : CallfireModel public IList Labels { get; set; } + public bool? ResumeNextDay { get; set; } + public override string ToString() { - return string.Format("[Broadcast: Id={0}, Name={1}, Status={2}, LastModified={3}, FromNumber={4}, LocalTimeRestriction={5}, Schedules={6}, MaxActive={7}, Labels={8}]", - Id, Name, Status, LastModified, FromNumber, LocalTimeRestriction, Schedules, MaxActive, Labels); + return string.Format("[Broadcast: Id={0}, Name={1}, Status={2}, LastModified={3}, FromNumber={4}, LocalTimeRestriction={5}, Schedules={6}, MaxActive={7}, Labels={8}, ResumeNextDay={9}]", + Id, Name, Status, LastModified, FromNumber, LocalTimeRestriction, Schedules, MaxActive, Labels, ResumeNextDay); } } } diff --git a/src/CallfireApiClient/Api/Campaigns/Model/CampaignSound.cs b/src/CallfireApiClient/Api/Campaigns/Model/CampaignSound.cs index e7f5989..96bfe21 100644 --- a/src/CallfireApiClient/Api/Campaigns/Model/CampaignSound.cs +++ b/src/CallfireApiClient/Api/Campaigns/Model/CampaignSound.cs @@ -1,6 +1,5 @@ using System; using CallfireApiClient.Api.Common.Model; -using Newtonsoft.Json; namespace CallfireApiClient.Api.Campaigns.Model { @@ -16,6 +15,8 @@ public class CampaignSound : CallfireModel public SoundStatus? Status { get; private set; } + public bool? Duplicate { get; private set; } + public enum SoundStatus { UPLOAD, @@ -27,8 +28,8 @@ public enum SoundStatus public override string ToString() { - return string.Format("[CampaignSound: Id={0}, Name={1}, StatusString={2}, Created={3}, lengthInSeconds={4}]", - Id, Name, Status, Created, LengthInSeconds); + return string.Format("[CampaignSound: Id={0}, Name={1}, StatusString={2}, Created={3}, lengthInSeconds={4}, status={4}, duplicate={4}]", + Id, Name, Status, Created, LengthInSeconds, Status, Duplicate); } } } diff --git a/src/CallfireApiClient/Api/Campaigns/Model/Request/GetBroadcastCallsTextsRequest.cs b/src/CallfireApiClient/Api/Campaigns/Model/Request/GetBroadcastCallsTextsRequest.cs new file mode 100644 index 0000000..dd5dfff --- /dev/null +++ b/src/CallfireApiClient/Api/Campaigns/Model/Request/GetBroadcastCallsTextsRequest.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; + +namespace CallfireApiClient.Api.Common.Model.Request +{ + /// + /// Find by id request with id, batchId, limit, offset and fields properties + /// + public class GetBroadcastCallsTextsRequest : GetByIdRequest + { + public long? batchId { get; set; } + + public override string ToString() + { + return string.Format("{0} [GetBroadcastCallsTextsRequest: batchId={1}]", base.ToString(), batchId); + } + } +} \ No newline at end of file diff --git a/src/CallfireApiClient/Api/Campaigns/TextBroadcastsApi.cs b/src/CallfireApiClient/Api/Campaigns/TextBroadcastsApi.cs index 52c7fa2..2ed96c8 100644 --- a/src/CallfireApiClient/Api/Campaigns/TextBroadcastsApi.cs +++ b/src/CallfireApiClient/Api/Campaigns/TextBroadcastsApi.cs @@ -205,12 +205,31 @@ public ResourceId AddBatch(AddBatchRequest request) /// in case HTTP response code is 500 - Internal Server Error. /// in case HTTP response code is something different from codes listed above. /// in case error has occurred in client. + [Obsolete] public Page GetTexts(GetByIdRequest request) { String path = TB_ITEM_TEXTS_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, request.Id.ToString()); return Client.Get>(path, request); } + /// + /// Get texts associated with text broadcast ordered by date + /// + /// request with properties to filter + /// texts assosiated with broadcast + /// in case HTTP response code is 400 - Bad request, the request was formatted improperly. + /// in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. + /// in case HTTP response code is 403 - Forbidden, insufficient permissions. + /// in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. + /// in case HTTP response code is 500 - Internal Server Error. + /// in case HTTP response code is something different from codes listed above. + /// in case error has occurred in client. + public Page GetTexts(GetBroadcastCallsTextsRequest request) + { + String path = TB_ITEM_TEXTS_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, request.Id.ToString()); + return Client.Get>(path, request); + } + /// /// Get statistics on text broadcast /// diff --git a/src/CallfireApiClient/Api/Webhooks/Model/ResourceType.cs b/src/CallfireApiClient/Api/Webhooks/Model/ResourceType.cs index b88318e..5b76e32 100644 --- a/src/CallfireApiClient/Api/Webhooks/Model/ResourceType.cs +++ b/src/CallfireApiClient/Api/Webhooks/Model/ResourceType.cs @@ -4,28 +4,39 @@ namespace CallfireApiClient.Api.Webhooks.Model { public enum ResourceEvent { - [EnumMember(Value = "start")] + [EnumMember(Value = "Started")] STARTED, - [EnumMember(Value = "stop")] + [EnumMember(Value = "Stopped")] STOPPED, - [EnumMember(Value = "finish")] + [EnumMember(Value = "Finished")] FINISHED, + [EnumMember(Value = "Failed")] + FAILED, [EnumMember(Value = "unknown")] UNKNOWN } public enum ResourceType { - [EnumMember(Value = "voiceCampaign")] - VOICE_BROADCAST, - [EnumMember(Value = "textCampaign")] - TEXT_BROADCAST, - [EnumMember(Value = "ivrCampaign")] - IVR_BROADCAST, - [EnumMember(Value = "cccCampaign")] + [EnumMember(Value = "MonthlyRenewal")] + MONTHLY_RENEWAL, + [EnumMember(Value = "LowBalance")] + LOW_BALANCE, + [EnumMember(Value = "CccCampaign")] CCC_CAMPAIGN, + [EnumMember(Value = "CallBroadcast")] + CALL_BROADCAST, + [EnumMember(Value = "TextBroadcast")] + TEXT_BROADCAST, + [EnumMember(Value = "OutboundCall")] + OUTBOUND_CALL, + [EnumMember(Value = "InboundCall")] + INBOUND_CALL, + [EnumMember(Value = "OutboundText")] + OUTBOUND_TEXT, + [EnumMember(Value = "InboundText")] + INBOUND_TEXT, [EnumMember(Value = "unknown")] UNKNOWN } -} - +} \ No newline at end of file diff --git a/src/CallfireApiClient/Api/Webhooks/Model/Webhook.cs b/src/CallfireApiClient/Api/Webhooks/Model/Webhook.cs index f863bd1..5c90155 100644 --- a/src/CallfireApiClient/Api/Webhooks/Model/Webhook.cs +++ b/src/CallfireApiClient/Api/Webhooks/Model/Webhook.cs @@ -30,11 +30,17 @@ public class Webhook : CallfireModel private static Dictionary> supportedEvents = new Dictionary> { + { ResourceType.MONTHLY_RENEWAL, new HashSet { ResourceEvent.FINISHED, ResourceEvent.FAILED } }, + { ResourceType.LOW_BALANCE, new HashSet { ResourceEvent.FINISHED, ResourceEvent.FAILED } }, { ResourceType.CCC_CAMPAIGN, new HashSet { ResourceEvent.FINISHED, ResourceEvent.STARTED, ResourceEvent.STOPPED } }, - { ResourceType.IVR_BROADCAST, new HashSet { ResourceEvent.FINISHED, ResourceEvent.STARTED, ResourceEvent.STOPPED } }, + { ResourceType.CALL_BROADCAST, new HashSet { ResourceEvent.FINISHED, ResourceEvent.STARTED, ResourceEvent.STOPPED } }, { ResourceType.TEXT_BROADCAST, new HashSet { ResourceEvent.FINISHED, ResourceEvent.STARTED, ResourceEvent.STOPPED } }, - { ResourceType.VOICE_BROADCAST, new HashSet { ResourceEvent.FINISHED, ResourceEvent.STARTED, ResourceEvent.STOPPED } } - }; + { ResourceType.INBOUND_CALL, new HashSet { ResourceEvent.FINISHED } }, + { ResourceType.OUTBOUND_CALL, new HashSet { ResourceEvent.FINISHED } }, + { ResourceType.INBOUND_TEXT, new HashSet { ResourceEvent.FINISHED } }, + { ResourceType.OUTBOUND_TEXT, new HashSet { ResourceEvent.FINISHED } }, + { ResourceType.UNKNOWN, new HashSet { } } + }; public override string ToString() { diff --git a/src/CallfireApiClient/Api/Webhooks/Model/WebhookResource.cs b/src/CallfireApiClient/Api/Webhooks/Model/WebhookResource.cs new file mode 100644 index 0000000..6393bf7 --- /dev/null +++ b/src/CallfireApiClient/Api/Webhooks/Model/WebhookResource.cs @@ -0,0 +1,19 @@ +using System; +using CallfireApiClient.Api.Common.Model; +using System.Collections.Generic; + +namespace CallfireApiClient.Api.Webhooks.Model +{ + public class WebhookResource : CallfireModel + { + public string Resource { get; private set; } + + public ISet SupportedEvents { get; private set; } + + public override string ToString() + { + return string.Format("[WebhookResource: Resource={0}, SupportedEvents={1}]", Resource, SupportedEvents?.ToPrettyString()); + } + } +} + diff --git a/src/CallfireApiClient/Api/Webhooks/WebhooksApi.cs b/src/CallfireApiClient/Api/Webhooks/WebhooksApi.cs index 42b15d9..99cd6c2 100644 --- a/src/CallfireApiClient/Api/Webhooks/WebhooksApi.cs +++ b/src/CallfireApiClient/Api/Webhooks/WebhooksApi.cs @@ -1,7 +1,7 @@ -using System; -using CallfireApiClient.Api.Common.Model; +using CallfireApiClient.Api.Common.Model; using CallfireApiClient.Api.Webhooks.Model; using CallfireApiClient.Api.Webhooks.Model.Request; +using System.Collections.Generic; namespace CallfireApiClient.Api.Webhooks { @@ -9,6 +9,8 @@ public class WebhooksApi { private const string WEBHOOKS_PATH = "/webhooks"; private const string WEBHOOKS_ITEM_PATH = "/webhooks/{}"; + private const string WEBHOOKS_RESOURCES_PATH = "/webhooks/resources"; + private const string WEBHOOKS_RESOURCE_PATH = "/webhooks/resources/{}"; private readonly RestApiClient Client; @@ -107,6 +109,41 @@ public void Delete(long id) { Client.Delete(WEBHOOKS_ITEM_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, id.ToString())); } - } -} + /// + /// Find webhook resources + /// + /// limit fields returned. Example fields=id,name + /// List of WebhookResource objects + /// in case HTTP response code is 400 - Bad request, the request was formatted improperly. + /// in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. + /// in case HTTP response code is 403 - Forbidden, insufficient permissions. + /// in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. + /// in case HTTP response code is 500 - Internal Server Error. + /// in case HTTP response code is something different from codes listed above. + /// in case error has occurred in client. + public IList FindWebhookResources(string fields) + { + var queryParams = ClientUtils.BuildQueryParams("fields", fields); + return Client.Get>(WEBHOOKS_RESOURCES_PATH, queryParams).Items; + } + + /// + /// Find specific webhook resource + /// + /// resource type object + /// WebhookResource object + /// in case HTTP response code is 400 - Bad request, the request was formatted improperly. + /// in case HTTP response code is 401 - Unauthorized, API Key missing or invalid. + /// in case HTTP response code is 403 - Forbidden, insufficient permissions. + /// in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist. + /// in case HTTP response code is 500 - Internal Server Error. + /// in case HTTP response code is something different from codes listed above. + /// in case error has occurred in client. + public WebhookResource FindWebhookResource(ResourceType resource, string fields) + { + var queryParams = ClientUtils.BuildQueryParams("fields", fields); + return Client.Get(WEBHOOKS_RESOURCE_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, resource.ToString()), queryParams); + } + } +} \ No newline at end of file diff --git a/src/CallfireApiClient/CallfireApiClient.csproj b/src/CallfireApiClient/CallfireApiClient.csproj index ba981ac..10cbdf7 100644 --- a/src/CallfireApiClient/CallfireApiClient.csproj +++ b/src/CallfireApiClient/CallfireApiClient.csproj @@ -58,6 +58,8 @@ + + @@ -94,6 +96,7 @@ + @@ -157,6 +160,7 @@ + diff --git a/src/CallfireApiClient/Properties/AssemblyInfo.cs b/src/CallfireApiClient/Properties/AssemblyInfo.cs index 0e6e71f..b0b07bf 100644 --- a/src/CallfireApiClient/Properties/AssemblyInfo.cs +++ b/src/CallfireApiClient/Properties/AssemblyInfo.cs @@ -13,7 +13,7 @@ // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. -[assembly: AssemblyVersion("1.1.7.*")] +[assembly: AssemblyVersion("1.1.8.*")] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. From 867ea8f9cbc1d0b4534a3ce3ebbdf1d44ba6e152 Mon Sep 17 00:00:00 2001 From: vmalinovskiy Date: Mon, 30 May 2016 14:19:47 +0300 Subject: [PATCH 2/2] vmalinovskiy - updated client to last api version(removed test creds) --- .../Integration/AbstractIntegrationTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CallfireApiClient.Tests/Integration/AbstractIntegrationTest.cs b/src/CallfireApiClient.Tests/Integration/AbstractIntegrationTest.cs index 5a05198..87179ab 100644 --- a/src/CallfireApiClient.Tests/Integration/AbstractIntegrationTest.cs +++ b/src/CallfireApiClient.Tests/Integration/AbstractIntegrationTest.cs @@ -8,7 +8,7 @@ public class AbstractIntegrationTest public AbstractIntegrationTest() { - Client = new CallfireClient("9b4f74b51316", "608bec4e28889510"); + Client = new CallfireClient("login", "password"); } } }