Ejemplo n.º 1
0
        /// <summary>
        /// Send SMS  to recipients using D7 SMS Gateway
        /// </summary>
        /// <param name="Models.CreateSendSMSInput">Object containing request parameters</param>
        /// <return>Returns the void response from the API call</return>
        public async Task CreateSendSMSAsync(Models.CreateSendSMSInput input)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

            //prepare query string for API call
            StringBuilder _queryBuilder = new StringBuilder(_baseUri);

            _queryBuilder.Append("/send");


            //validate and preprocess url
            string _queryUrl = APIHelper.CleanUrl(_queryBuilder);

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "D7SDK 1.0" },
                { "Content-Type", input.ContentType },
                { "Accept", input.Accept }
            };

            //append body params
            var _body = APIHelper.JsonSerialize(input.Body);

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.PostBody(_queryUrl, _headers, _body, Configuration.APIUsername, Configuration.APIPassword);

            //invoke request and get response
            HttpStringResponse _response = (HttpStringResponse)await ClientInstance.ExecuteAsStringAsync(_request).ConfigureAwait(false);

            HttpContext _context = new HttpContext(_request, _response);

            //Error handling using HTTP status codes
            if (_response.StatusCode == 500)
            {
                throw new APIException(@"Internal Server Error", _context);
            }

            //handle errors defined at the API level
            base.ValidateResponse(_response, _context);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Send SMS  to recipients using D7 SMS Gateway
        /// </summary>
        /// <param name="Models.CreateSendSMSInput">Object containing request parameters</param>
        /// <return>Returns the void response from the API call</return>
        public void CreateSendSMS(Models.CreateSendSMSInput input)
        {
            Task t = CreateSendSMSAsync(input);

            APIHelper.RunTaskSynchronously(t);
        }