Beispiel #1
0
        public override MessageStatusResponse StopMessage(APIMessageRequest request)
        {
            try
            {
                //Will hold all the MessagesStatuses of all the APIMessageIds requested to stop
                var messageStatuses = new List<MessageStatus>();
                //Will hold all the raw webResponses from the Clickatell service
                var messageResults = new StringBuilder();

                //Loops through all APIMessageIds requested to stop
                foreach (var apiMsgId in request.APIMessageIds)
                {
                    //Get WebRequest with StopMessageURL+current APIMessageId with DELETE method
                    var webRequest = GetWebRequest(string.Format(Properties.RESTSettings.Default.StopMessageURL, apiMsgId), Properties.RESTSettings.Default.DeleteMethod);
                    //Get WebResponse back from Clickatell service
                    var webResponse = GetWebResponse(webRequest);

                    //Add raw webResponse to messageResults
                    messageResults.AppendLine(webResponse.Result);

                    //Deserlialize the webResponse to Data.JSON.REST.StopMessageResponse.Rootobject
                    var jsonResponse = JsonDeserialize<Data.JSON.REST.StopMessageResponse.Rootobject>(webResponse.Result).data;

                    if (jsonResponse != null)
                    {
                        //Maps the jsonResponse to MessageStatus and adds it to the messageStatuses list
                        messageStatuses.Add(new MessageStatus
                        {
                            APIMessageID = jsonResponse.apiMessageId,
                            Description = jsonResponse.description,
                            Status = jsonResponse.messageStatus
                        });
                    }
                }

                return new MessageStatusResponse
                {
                    Success = true,
                    Result = messageResults.ToString(),
                    MessageStatuses = messageStatuses.ToArray()
                };
            }
            catch (Exception exception)
            {
                return new MessageStatusResponse
                {
                    Result = string.Format("Error occured during Clickatell {0}. Details: {1}", MethodBase.GetCurrentMethod().Name, exception.Message),
                    Success = false
                };
            }
        }
Beispiel #2
0
        public override MessageStatusResponse StopMessage(APIMessageRequest request)
        {
            try
            {
                //MessagesStatuses of all the APIMessageIds requested to stop
                var messageStatuses = new List<MessageStatus>();
                //Raw web responses from the Clickatell service
                var messageResults = new StringBuilder();

                //Loops through all APIMessageIds requested to stop
                foreach (var apiMessageId in request.APIMessageIds)
                {
                    //Send Request to Clickatell service with StopMessageURL and apiMessageId
                    var response = SendRequest(Properties.HTTPSettings.Default.StopMessageURL, apiMessageId: apiMessageId);

                    //Add raw response to messageResults
                    messageResults.AppendLine(response);

                    //Extract messageStatus from string response
                    var messageStatus = GetMessageStatusFromResponse(response);

                    //Adds messageStatus to messageStatuses list
                    messageStatuses.Add(messageStatus);
                }

                return new MessageStatusResponse
                {
                    Success = true,
                    Result = messageResults.ToString(),
                    MessageStatuses = messageStatuses.ToArray()
                };
            }
            catch (Exception exception)
            {
                return new MessageStatusResponse
                {
                    Result = string.Format("Error occured during Clickatell {0}. Details: {1}", MethodBase.GetCurrentMethod().Name, exception.Message),
                    Success = false
                };
            }
        }
 /// <summary>
 /// Sends a request with APIMessageID(s) to see in what status the requested APIMessageID(s) are.
 /// </summary>
 /// <param name="APIMessageRequest"></param>
 /// <returns>
 /// MessageStatusResponse:
 /// Success = If call was successfully made to Clickatell
 /// Result  = Service response
 /// MessageStatuses[]  = MessageStatus object which will have the current APIMessageID, Status and Description of the message.
 /// </returns>
 public abstract MessageStatusResponse GetMessageStatus(APIMessageRequest request);
 /// <summary>
 /// Sends request with APIMessageID(s) to stop/delete a message. 
 /// Note the message will only be stopped if it is still in Clickatells queue.
 /// </summary>
 /// <param name="APIMessageRequest"></param>
 /// <returns>
 /// MessageStatusResponse:
 /// Success = If call was successfully made to Clickatell
 /// Result  = Service response
 /// MessageStatuses[]  = MessageStatus object which will have the current APIMessageID, Status and Description of the message.
 /// </returns>
 public abstract MessageStatusResponse StopMessage(APIMessageRequest request);
 /// <summary>
 /// Sends a request with APIMessageID(s) to see what the costs were for these phonenumber(s) sent.
 /// </summary>
 /// <param name="APIMessageRequest"></param>
 /// <returns>
 /// MessageChargeResponse:
 /// Success = If call was successfully made to Clickatell
 /// Result  = Service response
 /// MessageCharges[]  = MessageCharge object which will have the current APIMessageID and Charge of that call.
 /// </returns>
 public abstract MessageChargeResponse GetMessageCharge(APIMessageRequest request);