Exemplo n.º 1
0
        public override MessagCoverageResponse GetCoverage(MessageRequest request)
        {
            try
            {
                //MessageCoverages of all the PhoneNumbers requested
                var messageCoverages = new List<MessageCoverage>();

                //Raw web responses from the Clickatell service
                var messageResults = new StringBuilder();

                //Loops through all Phonenumbers requested to check coverage
                foreach (var phoneNumber in request.PhoneNumbers)
                {
                    //Send Request to Clickatell service with CoverageURL and phoneNumber
                    var response = SendRequest(Properties.HTTPSettings.Default.CoverageURL, coveragePhoneNumber: phoneNumber);

                    //Add raw response to messageResults
                    messageResults.AppendLine(string.Format("PhoneNumber: {0} - {1}", phoneNumber, response));

                    //Extract messageCoverage from string response
                    var messageCoverage = GetMessageCoverageFromResponse(response, phoneNumber);

                    //Adds messageCoverage to messageCoverages list
                    messageCoverages.Add(messageCoverage);
                }

                return new MessagCoverageResponse
                {
                    Success = true,
                    Result = messageResults.ToString(),
                    MessageCoverages = messageCoverages.ToArray()
                };
            }
            catch (Exception exception)
            {
                return new MessagCoverageResponse
                {
                    Result = string.Format("Error occured during Clickatell {0}. Details: {1}", MethodBase.GetCurrentMethod().Name, exception.Message),
                    Success = false
                };
            }
        }
Exemplo n.º 2
0
        public override MessagCoverageResponse GetCoverage(MessageRequest request)
        {
            try
            {
                //Will hold all the MessageCoverages of all the phonenumbers requested
                var messageCoverages = new List<MessageCoverage>();
                //Will hold all the raw webResponses from the Clickatell service
                var messageResults = new StringBuilder();

                //Loops through all PhoneNumbers requested to check coverage
                foreach (var phoneNumber in request.PhoneNumbers)
                {
                    //Get WebRequest with CoverageURL+current phoneNumber with GET method
                    var webRequest = GetWebRequest(string.Format(Properties.RESTSettings.Default.CoverageURL, phoneNumber), Properties.RESTSettings.Default.GetMethod);
                    //Get WebResponse from Clickatell service
                    var webResponse = GetWebResponse(webRequest);

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

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

                    if (jsonResponse != null)
                    {
                        //Maps the jsonResponse to MessageCoverage and adds it to the messageCoverages list
                        messageCoverages.Add(new MessageCoverage
                        {
                            Routable = jsonResponse.routable,
                            Destination = jsonResponse.destination
                        });
                    }
                }
                return new MessagCoverageResponse
                {
                    Success = true,
                    Result = messageResults.ToString(),
                    MessageCoverages = messageCoverages.ToArray()
                };
            }
            catch (Exception exception)
            {
                return new MessagCoverageResponse
                {
                    Result = string.Format("Error occured during Clickatell {0}. Details: {1}", MethodBase.GetCurrentMethod().Name, exception.Message),
                    Success = false
                };
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Sends request with Phonenumbers to see if it is within coverage. (Coverage depends on your Clickatell account settings)
 /// </summary>
 /// <param name="MessageRequest"></param>
 /// <returns>
 /// MessagCoverageResponse:
 /// Success = If call was successfully made to Clickatell
 /// Result  = Service response
 /// MessageCoverages[]  = MessageCoverage object which will have Routable(If it is within the coverage) and Destination(The phonenumber supplied).
 /// </returns>
 public abstract MessagCoverageResponse GetCoverage(MessageRequest request);