Пример #1
0
        /// <summary>
        /// Cancel a scheduled message that has not yet been delivered.
        /// A scheduled message can be cancelled by updating the status of a message from ```scheduled```
        /// to ```cancelled```. This is done by submitting a PUT request to the messages endpoint using
        /// the message ID as a parameter (the same endpoint used above to retrieve the status of a message).
        /// The body of the request simply needs to contain a ```status``` property with the value set
        /// to ```cancelled```.
        /// ```json
        /// {
        ///     "status": "cancelled"
        /// }
        /// ```
        /// *Note: Only messages with a status of scheduled can be cancelled. If an invalid or non existent
        /// message ID parameter is specified in the request, then a HTTP 404 Not Found response will be
        /// returned*
        /// </summary>
        /// <param name="messageId">Required parameter: Example: </param>
        /// <param name="body">Required parameter: Example: </param>
        /// <return>Returns the dynamic response from the API call</return>
        public dynamic UpdateCancelScheduledMessage(string messageId, Models.CancelScheduledMessageRequest body)
        {
            Task <dynamic> t = UpdateCancelScheduledMessageAsync(messageId, body);

            APIHelper.RunTaskSynchronously(t);
            return(t.Result);
        }
        /// <summary>
        /// Cancel a scheduled message that has not yet been delivered.
        /// A scheduled message can be cancelled by updating the status of a message from ```scheduled```
        /// to ```cancelled```. This is done by submitting a PUT request to the messages endpoint using
        /// the message ID as a parameter (the same endpoint used above to retrieve the status of a message).
        /// The body of the request simply needs to contain a ```status``` property with the value set
        /// to ```cancelled```.
        /// ```json
        /// {
        ///     "status": "cancelled"
        /// }
        /// ```
        /// *Note: Only messages with a status of scheduled can be cancelled. If an invalid or non existent
        /// message ID parameter is specified in the request, then a HTTP 404 Not Found response will be
        /// returned*
        /// </summary>
        /// <param name="messageId">Required parameter: Example: </param>
        /// <param name="body">Required parameter: Example: </param>
        /// <return>Returns the dynamic response from the API call</return>
        public async Task <dynamic> CancelScheduledMessageAsync(string messageId, Models.CancelScheduledMessageRequest body)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/v1/messages/{messageId}");

            //process optional template parameters
            APIHelper.AppendUrlWithTemplateParameters(_queryBuilder, new Dictionary <string, object>()
            {
                { "messageId", messageId }
            });


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "messagemedia-messages" },
                { "accept", "application/json" },
                { "content-type", "application/json; charset=utf-8" }
            };

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

            //append authentication headers
            AuthManager.Instance.GetAuthHeaders(_queryUrl, _baseUri, _body).ToList().ForEach(x => _headers.Add(x.Key, x.Value));

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

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

            HttpContext _context = new HttpContext(_request, _response);

            //handle errors defined at the API level
            base.ValidateResponse(_response, _context);

            try
            {
                return(APIHelper.JsonDeserialize <dynamic>(_response.Body));
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Пример #3
0
        /// <summary>
        /// Cancel a scheduled message that has not yet been delivered.
        /// A scheduled message can be cancelled by updating the status of a message from ```scheduled```
        /// to ```cancelled```. This is done by submitting a PUT request to the messages endpoint using
        /// the message ID as a parameter (the same endpoint used above to retrieve the status of a message).
        /// The body of the request simply needs to contain a ```status``` property with the value set
        /// to ```cancelled```.
        /// ```json
        /// {
        ///     "status": "cancelled"
        /// }
        /// ```
        /// *Note: Only messages with a status of scheduled can be cancelled. If an invalid or non existent
        /// message ID parameter is specified in the request, then a HTTP 404 Not Found response will be
        /// returned*
        /// </summary>
        /// <param name="messageId">Required parameter: Example: </param>
        /// <param name="body">Required parameter: Example: </param>
        /// <param name="accountHeaderValue">Optional parameter: Sends the API an account value.</param>
        /// <return>Returns the dynamic response from the API call</return>
        public async Task <dynamic> UpdateCancelScheduledMessageAsync(string messageId, Models.CancelScheduledMessageRequest body, string accountHeaderValue = null)
        {
            //the base uri for api requests
            string baseUri = Configuration.BaseUri;

            //prepare query string for API call
            StringBuilder queryBuilder = new StringBuilder(baseUri);

            queryBuilder.Append("/v1/messages/{messageId}");

            //process optional template parameters
            APIHelper.AppendUrlWithTemplateParameters(queryBuilder, new Dictionary <string, object>()
            {
                { "messageId", messageId }
            });

            //validate and preprocess url
            string queryUrl = APIHelper.CleanUrl(queryBuilder);

            //append request with appropriate headers and parameters
            var headers = new Dictionary <string, string>()
            {
                { "user-agent", SdkVersion },
                { "accept", "application/json" },
                { "content-type", "application/json; charset=utf-8" }
            };

            AddAccountHeaderTo(headers, accountHeaderValue);

            //append body params
            var jsonBody = APIHelper.JsonSerialize(body);

            //prepare the API call request to fetch the response
            HttpRequest request = ClientInstance.PutBody(queryUrl, headers, jsonBody, Configuration.BasicAuthUserName, Configuration.BasicAuthPassword);

            //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 == 400)
            {
                throw new APIException(@"", _context);
            }

            if (response.StatusCode == 404)
            {
                throw new APIException(@"", _context);
            }

            //handle errors defined at the API level
            base.ValidateResponse(response, _context);

            try
            {
                return(APIHelper.JsonDeserialize <dynamic>(response.Body));
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }