public void Update()
        {
            var expectedJson = GetJsonPayload("/campaigns/textBroadcastsApi/request/updateTextBroadcast.json");
            var restRequest = MockRestResponse(expectedJson);

            var textBroadcast = new TextBroadcast
            {
                Id = 11,
                Name = "Example API SMS updated",
                Message = "a new test message",
                ResumeNextDay = true
            };
            Client.TextBroadcastsApi.Update(textBroadcast);

            Assert.AreEqual(Method.PUT, restRequest.Value.Method);
            var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody);
            Assert.AreEqual(requestBodyParam.Value, expectedJson);
            Assert.That(restRequest.Value.Resource, Is.StringEnding("/11"));
        }
        public void Create()
        {
            var requestJson = GetJsonPayload("/campaigns/textBroadcastsApi/request/createTextBroadcast.json");
            var responseJson = GetJsonPayload("/campaigns/textBroadcastsApi/response/createTextBroadcast.json");
            var restRequest = MockRestResponse(responseJson);

            var textBroadcast = new TextBroadcast
            {
                Name = "Example API SMS",
                FromNumber = "19206596476",
                Message = "Hello World!",
                Recipients = new List<TextRecipient>
                {
                    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));

            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<Parameter>(p => p.Name.Equals("start") && p.Value.Equals("True")));
        }
        public void CrudOperations()
        {
            var broadcast = new TextBroadcast
            {
                Name = "text_broadcast",
                BigMessageStrategy = BigMessageStrategy.SEND_MULTIPLE,
                Message = "test_msg",
                LocalTimeRestriction = new LocalTimeRestriction
                {
                    BeginHour = 10,
                    BeginMinute = 10,
                    EndHour = 22,
                    EndMinute = 0,
                    Enabled = true
                },
                Recipients = new List<TextRecipient>
                {
                    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);
        }
        public void GetBroadcastTexts()
        {
            var broadcast = new TextBroadcast
            {
                Name = "text_broadcast_1",
                Message = "test_msg",
                Recipients = new List<TextRecipient>
                {
                    new TextRecipient { PhoneNumber = "14246525473" }
                }
            };
            var broadcastId = Client.TextBroadcastsApi.Create(broadcast, false);

            var request = new GetByIdRequest { Id = broadcastId.Id };
            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);
        }
        public void GetBroadcastStats()
        {
            var broadcast = new TextBroadcast
            {
                Name = "text_broadcast_2",
                Message = "test_msg",
                Recipients = new List<TextRecipient>
                {
                    new TextRecipient { PhoneNumber = "12132041238" }
                }
            };
            var broadcastId = Client.TextBroadcastsApi.Create(broadcast, true);

            var begin = DateTime.Now.AddDays(-5d);
            var end = DateTime.Now;
            var fields = "TotalOutboundCount,remainingOutboundCount";
            var stats = Client.TextBroadcastsApi.GetStats(broadcastId.Id, fields, begin, end);
            Console.WriteLine(stats);
        }
 /// <summary>
 /// Update broadcast
 /// </summary>
 /// <param name="broadcast">broadcast to update</param>
 /// <exception cref="BadRequestException">          in case HTTP response code is 400 - Bad request, the request was formatted improperly.</exception>
 /// <exception cref="UnauthorizedException">        in case HTTP response code is 401 - Unauthorized, API Key missing or invalid.</exception>
 /// <exception cref="AccessForbiddenException">     in case HTTP response code is 403 - Forbidden, insufficient permissions.</exception>
 /// <exception cref="ResourceNotFoundException">    in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist.</exception>
 /// <exception cref="InternalServerErrorException"> in case HTTP response code is 500 - Internal Server Error.</exception>
 /// <exception cref="CallfireApiException">         in case HTTP response code is something different from codes listed above.</exception>
 /// <exception cref="CallfireClientException">      in case error has occurred in client.</exception>
 public void Update(TextBroadcast broadcast)
 {
     Validate.NotNull(broadcast.Id, "broadcast.id cannot be null");
     Client.Put<object>(TB_ITEM_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, broadcast.Id.ToString()), broadcast);
 }
 /// <summary>
 /// Create a text broadcast campaign using the Text Broadcast API. A campaign can be created with
 /// no contacts and bare minimum configuration, but contacts will have to be added further on to use the campaign.
 /// If start set to true campaign starts immediately
 /// </summary>
 /// <param name="broadcast">text broadcast to create</param>
 /// <param name="start">if set to true then broadcast will start immediately, by default it set to false</param>
 /// <returns>ResourceId object with id of created broadcast</returns>
 /// <exception cref="BadRequestException">          in case HTTP response code is 400 - Bad request, the request was formatted improperly.</exception>
 /// <exception cref="UnauthorizedException">        in case HTTP response code is 401 - Unauthorized, API Key missing or invalid.</exception>
 /// <exception cref="AccessForbiddenException">     in case HTTP response code is 403 - Forbidden, insufficient permissions.</exception>
 /// <exception cref="ResourceNotFoundException">    in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist.</exception>
 /// <exception cref="InternalServerErrorException"> in case HTTP response code is 500 - Internal Server Error.</exception>
 /// <exception cref="CallfireApiException">         in case HTTP response code is something different from codes listed above.</exception>
 /// <exception cref="CallfireClientException">      in case error has occurred in client.</exception>
 public ResourceId Create(TextBroadcast broadcast, bool start = false)
 {
     var queryParams = ClientUtils.BuildQueryParams("start", start.ToString());
     return Client.Post<ResourceId>(TB_PATH, broadcast, queryParams);
 }