/// <summary>
        /// Creates a new inbound route which can then be associated with phone numbers. Please see "List Inbound Routes" to review the route values that you can associate with your Flowroute phone numbers.
        /// </summary>
        /// <param name="body">Required parameter: The new inbound route to be created.</param>
        /// <return>Returns the string response from the API call</return>
        public string CreateAnInboundRoute(Models.NewRoute body)
        {
            Task <string> t = CreateAnInboundRouteAsync(body);

            APIHelper.RunTaskSynchronously(t);
            return(t.Result);
        }
        /// <summary>
        /// Creates a new inbound route which can then be associated with phone numbers. Please see "List Inbound Routes" to review the route values that you can associate with your Flowroute phone numbers.
        /// </summary>
        /// <param name="body">Required parameter: The new inbound route to be created.</param>
        /// <return>Returns the string response from the API call</return>
        public async Task <string> CreateAnInboundRouteAsync(Models.NewRoute body)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/v2/routes");

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

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

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

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.PostBody(_queryUrl, _headers, _body, 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 == 401)
            {
                throw new ErrorException(@"Unauthorized – There was an issue with your API credentials.", _context);
            }

            if (_response.StatusCode == 404)
            {
                throw new ErrorException(@"The specified resource was not found", _context);
            }

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

            try
            {
                return(_response.Body);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Example #3
0
 public IHttpActionResult Post([FromBody] Models.NewRoute route)
 {
     return(new Services.Create(route, this.User.PrimarySid()));
 }