Ejemplo n.º 1
0
        /// <summary>
        /// Retrieve a letter object by its LetterSid.
        /// </summary>
        /// <param name="lettersid">Required parameter: The unique identifier for a letter object.</param>
        /// <return>Returns the string response from the API call</return>
        public async Task <string> CreateViewLetterAsync(string lettersid)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/letter/viewletter.json");


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "APIMATIC 2.0" }
            };

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("lettersid", lettersid)
            };

            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Post(_queryUrl, _headers, _fields, Configuration.BasicAuthUserName, Configuration.BasicAuthPassword);

            //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(_response.Body);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Retries a charge
        /// </summary>
        /// <param name="chargeId">Required parameter: Charge id</param>
        /// <param name="idempotencyKey">Optional parameter: Example: </param>
        /// <return>Returns the Models.GetChargeResponse response from the API call</return>
        public async Task <Models.GetChargeResponse> RetryChargeAsync(string chargeId, string idempotencyKey = null)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/charges/{charge_id}/retry");

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


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "MundiSDK - DotNet 0.16.21" },
                { "accept", "application/json" },
                { "idempotency-key", idempotencyKey }
            };

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Post(_queryUrl, _headers, null, Configuration.BasicAuthUserName, Configuration.BasicAuthPassword);

            //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 <Models.GetChargeResponse>(_response.Body));
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// TODO: type endpoint description here
        /// </summary>
        /// <param name="array">Required parameter: TODO: type parameter description here</param>
        /// <return>Returns the dynamic response from the API call</return>
        public async Task <dynamic> SendStringEnumArrayAsync(
            Days array)
        {
            //the base uri for api requestss
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/form/stringenum?array=true");


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "Stamplay SDK" },
                { "accept", "application/json" }
            };

            //append form/field parameters
            var _fields = new Dictionary <string, object>()
            {
                { "array", array }
            };

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

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

            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);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sends a single header params
        /// </summary>
        /// <param name="customHeader">Required parameter: TODO: type parameter description here</param>
        /// <param name="mvalue">Required parameter: Represents the value of the custom header</param>
        /// <return>Returns the string response from the API call</return>
        public async Task<string> SendHeadersAsync(
                string customHeader,
                string mvalue)
        {
            //the base uri for api requestss
            string _baseUri = Configuration.BaseUri;

            //prepare query string for API call
            StringBuilder _queryBuilder = new StringBuilder(_baseUri);
            _queryBuilder.Append("/header");


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary<string,string>()
            {
                { "user-agent", "Stamplay SDK" },
                { "custom-header", customHeader }
            };

            //append form/field parameters
            var _fields = new Dictionary<string,object>()
            {
                { "value", mvalue }
            };

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

            //invoke request and get response
            HttpStringResponse _response = (HttpStringResponse) await ClientInstance.ExecuteAsStringAsync(_request);
            HttpContext _context = new HttpContext(_request,_response);
            //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);
            }
        }
        /// <summary>
        /// Upload a file and convert it to the given format. The API description format of the uploaded file will be detected automatically. The converted file is returned as the response.
        /// </summary>
        /// <param name="format">Required parameter: The API format to convert to</param>
        /// <param name="file">Required parameter: The input file to convert</param>
        /// <return>Returns the Stream response from the API call</return>
        public async Task <Stream> UsingFileAsync(Models.FormatTransformer format, FileStreamInfo file)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/transform");

            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(_queryBuilder, new Dictionary <string, object>()
            {
                { "format", Models.FormatTransformerHelper.ToValue(format) }
            }, ArrayDeserializationFormat, ParameterSeparator);


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "APIMATIC 2.0" }
            };

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("file", file)
            };

            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Post(_queryUrl, _headers, _fields, Configuration.BasicAuthUserName, Configuration.BasicAuthPassword);

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

            HttpContext _context = new HttpContext(_request, _response);

            //Error handling using HTTP status codes
            if (_response.StatusCode == 400)
            {
                throw new ValidationResultException(@"Bad Request", _context);
            }

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

            try
            {
                return(_response.RawBody);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Make an automated call to any valid phone number and playback a unique security code. See: https://www.neutrinoapi.com/api/phone-verify/
        /// </summary>
        /// <param name="number">Required parameter: The phone number to send the verification code to</param>
        /// <param name="codeLength">Optional parameter: The number of digits to use in the security code (between 4 and 12)</param>
        /// <param name="securityCode">Optional parameter: Pass in your own security code. This is useful if you have implemented TOTP or similar 2FA methods. If not set then we will generate a secure random code</param>
        /// <param name="playbackDelay">Optional parameter: The delay in milliseconds between the playback of each security code</param>
        /// <param name="countryCode">Optional parameter: ISO 2-letter country code, assume numbers are based in this country.<br/>If not set numbers are assumed to be in international format (with or without the leading + sign)</param>
        /// <param name="languageCode">Optional parameter: The language to playback the verification code in, available languages are:<ul><li>de - German</li><li>en - English</li><li>es - Spanish</li><li>fr - French</li><li>it - Italian</li><li>pt - Portuguese</li><li>ru - Russian</li></ul></param>
        /// <return>Returns the Models.PhoneVerifyResponse response from the API call</return>
        public async Task <Models.PhoneVerifyResponse> PhoneVerifyAsync(
            string number,
            int?codeLength      = 6,
            int?securityCode    = null,
            int?playbackDelay   = 800,
            string countryCode  = null,
            string languageCode = "en")
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/phone-verify");

            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(_queryBuilder, new Dictionary <string, object>()
            {
                { "user-id", Configuration.UserId },
                { "api-key", Configuration.ApiKey }
            }, ArrayDeserializationFormat, ParameterSeparator);


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "APIMATIC 2.0" },
                { "accept", "application/json" }
            };

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("output-case", "camel"),
                new KeyValuePair <string, object>("number", number),
                new KeyValuePair <string, object>("code-length", (null != codeLength) ? codeLength : 6),
                new KeyValuePair <string, object>("security-code", securityCode),
                new KeyValuePair <string, object>("playback-delay", (null != playbackDelay) ? playbackDelay : 800),
                new KeyValuePair <string, object>("country-code", countryCode),
                new KeyValuePair <string, object>("language-code", (null != languageCode) ? languageCode : "en")
            };

            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

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

            //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 <Models.PhoneVerifyResponse>(_response.Body));
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
        /// <summary>
        /// Send a variety for form params. Returns file count and body params
        /// </summary>
        /// <param name="SendMixedArrayInput">Object containing request parameters</param>
        /// <return>Returns the ServerResponse response from the API call</return>
        public async Task <ServerResponse> SendMixedArrayAsync(SendMixedArrayInput input)
        {
            //validating required parameters
            if (null == input.File)
            {
                throw new ArgumentNullException("file", "The property \"File\" in the input object cannot be null.");
            }

            if (null == input.Integers)
            {
                throw new ArgumentNullException("integers", "The property \"Integers\" in the input object cannot be null.");
            }

            if (null == input.Models)
            {
                throw new ArgumentNullException("models", "The property \"Models\" in the input object cannot be null.");
            }

            if (null == input.Strings)
            {
                throw new ArgumentNullException("strings", "The property \"Strings\" in the input object cannot be null.");
            }

            //the base uri for api requestss
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/form/mixed");


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "Stamplay SDK" },
                { "accept", "application/json" }
            };

            //append form/field parameters
            var _fields = new Dictionary <string, object>()
            {
                { "file", input.File }
            };

            _fields.Add(APIHelper.PrepareFormFieldsFromObject("integers", input.Integers));
            _fields.Add(APIHelper.PrepareFormFieldsFromObject("models", input.Models));
            _fields.Add(APIHelper.PrepareFormFieldsFromObject("strings", input.Strings));

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

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

            HttpContext _context = new HttpContext(_request, _response);

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

            try
            {
                return(APIHelper.JsonDeserialize <ServerResponse>(_response.Body));
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
        /// <summary>
        /// List All Inbound ShortCode
        /// </summary>
        /// <param name="datecreated">Optional parameter: Only list messages sent with the specified date</param>
        /// <param name="page">Optional parameter: The page count to retrieve from the total results in the collection. Page indexing starts at 1.</param>
        /// <param name="pagesize">Optional parameter: Number of individual resources listed in the response per page</param>
        /// <param name="mfrom">Optional parameter: From Number to Inbound ShortCode</param>
        /// <param name="shortcode">Optional parameter: Only list messages sent to this Short Code</param>
        /// <return>Returns the string response from the API call</return>
        public async Task <string> CreateListInboundSMSAsync(
            string datecreated = null,
            int?page           = null,
            int?pagesize       = null,
            string mfrom       = null,
            string shortcode   = null)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/shortcode/getinboundsms.json");

            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(_queryBuilder, new Dictionary <string, object>()
            {
                { "Datecreated", datecreated }
            }, ArrayDeserializationFormat, ParameterSeparator);


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "APIMATIC 2.0" }
            };

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("page", page),
                new KeyValuePair <string, object>("pagesize", pagesize),
                new KeyValuePair <string, object>("from", mfrom),
                new KeyValuePair <string, object>("Shortcode", shortcode)
            };

            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Post(_queryUrl, _headers, _fields, Configuration.BasicAuthUserName, Configuration.BasicAuthPassword);

            //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(_response.Body);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Create, print, and mail a letter to an address. The letter file must be supplied as a PDF or an HTML string.
        /// </summary>
        /// <param name="to">Required parameter: The AddressId or an object structured when creating an address by addresses/Create.</param>
        /// <param name="mfrom">Required parameter: The AddressId or an object structured when creating an address by addresses/Create.</param>
        /// <param name="attachbyid">Required parameter: Set an existing letter by attaching its LetterId.</param>
        /// <param name="file">Required parameter: File can be a 8.5"x11" PDF uploaded file or URL that links to a file.</param>
        /// <param name="color">Required parameter: Specify if letter should be printed in color.</param>
        /// <param name="description">Optional parameter: A description for the letter.</param>
        /// <param name="extraservice">Optional parameter: Add an extra service to your letter. Options are "certified" or "registered". Certified provides tracking and delivery confirmation for domestic destinations and is an additional $5.00. Registered provides tracking and confirmation for international addresses and is an additional $16.50.</param>
        /// <param name="doublesided">Optional parameter: Specify if letter should be printed on both sides.</param>
        /// <param name="template">Optional parameter: Boolean that defaults to true. When set to false, this specifies that your letter does not follow the m360 address template. In this case, a blank address page will be inserted at the beginning of your file and you will be charged for the extra page.</param>
        /// <param name="htmldata">Optional parameter: A string value that contains HTML markup.</param>
        /// <return>Returns the string response from the API call</return>
        public async Task <string> CreateLetterAsync(
            string to,
            string mfrom,
            string attachbyid,
            string file,
            string color,
            string description  = null,
            string extraservice = null,
            string doublesided  = null,
            string template     = null,
            string htmldata     = null)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/letter/create.json");


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "APIMATIC 2.0" }
            };

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("to", to),
                new KeyValuePair <string, object>("from", mfrom),
                new KeyValuePair <string, object>("attachbyid", attachbyid),
                new KeyValuePair <string, object>("file", file),
                new KeyValuePair <string, object>("color", color),
                new KeyValuePair <string, object>("description", description),
                new KeyValuePair <string, object>("extraservice", extraservice),
                new KeyValuePair <string, object>("doublesided", doublesided),
                new KeyValuePair <string, object>("template", template),
                new KeyValuePair <string, object>("htmldata", htmldata)
            };

            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Post(_queryUrl, _headers, _fields, Configuration.BasicAuthUserName, Configuration.BasicAuthPassword);

            //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(_response.Body);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// You can experiment with initiating a call through Message360 and view the request response generated when doing so and get the response in json
        /// </summary>
        /// <param name="CreateMakeCallInput">Object containing request parameters</param>
        /// <return>Returns the string response from the API call</return>
        public async Task <string> CreateMakeCallAsync(CreateMakeCallInput input)
        {
            //validating required parameters
            if (null == input.FromCountryCode)
            {
                throw new ArgumentNullException("fromCountryCode", "The property \"FromCountryCode\" in the input object cannot be null.");
            }

            if (null == input.From)
            {
                throw new ArgumentNullException("mfrom", "The property \"From\" in the input object cannot be null.");
            }

            if (null == input.ToCountryCode)
            {
                throw new ArgumentNullException("toCountryCode", "The property \"ToCountryCode\" in the input object cannot be null.");
            }

            if (null == input.To)
            {
                throw new ArgumentNullException("to", "The property \"To\" in the input object cannot be null.");
            }

            if (null == input.Url)
            {
                throw new ArgumentNullException("url", "The property \"Url\" in the input object cannot be null.");
            }

            //the base uri for api requestss
            string _baseUri = Configuration.GetBaseURI();

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

            _queryBuilder.Append("/calls/makecall.{ResponseType}");

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

            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(_queryBuilder, new Dictionary <string, object>()
            {
                { "Method", (input.Method.HasValue) ? HttpActionHelper.ToValue(input.Method.Value) : null }
            });


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "message360-api" }
            };

            //append form/field parameters
            var _fields = new Dictionary <string, object>()
            {
                { "FromCountryCode", input.FromCountryCode },
                { "From", input.From },
                { "ToCountryCode", input.ToCountryCode },
                { "To", input.To },
                { "Url", input.Url },
                { "StatusCallBackUrl", input.StatusCallBackUrl },
                { "StatusCallBackMethod", (input.StatusCallBackMethod.HasValue) ? HttpActionHelper.ToValue(input.StatusCallBackMethod.Value) : null },
                { "FallBackUrl", input.FallBackUrl },
                { "FallBackMethod", (input.FallBackMethod.HasValue) ? HttpActionHelper.ToValue(input.FallBackMethod.Value) : null },
                { "HeartBeatUrl", input.HeartBeatUrl },
                { "HeartBeatMethod", input.HeartBeatMethod },
                { "Timeout", input.Timeout },
                { "PlayDtmf", input.PlayDtmf },
                { "HideCallerId", input.HideCallerId },
                { "Record", input.Record },
                { "RecordCallBackUrl", input.RecordCallBackUrl },
                { "RecordCallBackMethod", (input.RecordCallBackMethod.HasValue) ? HttpActionHelper.ToValue(input.RecordCallBackMethod.Value) : null },
                { "Transcribe", input.Transcribe },
                { "TranscribeCallBackUrl", input.TranscribeCallBackUrl },
                { "IfMachine", (input.IfMachine.HasValue) ? IfMachineHelper.ToValue(input.IfMachine.Value) : null }
            };

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Post(_queryUrl, _headers, _fields, Configuration.BasicAuthUserName, Configuration.BasicAuthPassword);

            //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(_response.Body);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Resize an image and output as either JPEG or PNG. See: https://www.neutrinoapi.com/api/image-resize/
        /// </summary>
        /// <param name="imageUrl">Required parameter: The URL to the source image</param>
        /// <param name="width">Required parameter: The width to resize to (in px) while preserving aspect ratio</param>
        /// <param name="height">Required parameter: The height to resize to (in px) while preserving aspect ratio</param>
        /// <param name="format">Optional parameter: The output image format, can be either png or jpg</param>
        /// <return>Returns the Stream response from the API call</return>
        public async Task <Stream> ImageResizeAsync(
            string imageUrl,
            int width,
            int height,
            string format = "png")
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/image-resize");

            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(_queryBuilder, new Dictionary <string, object>()
            {
                { "user-id", Configuration.UserId },
                { "api-key", Configuration.ApiKey }
            }, ArrayDeserializationFormat, ParameterSeparator);


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "APIMATIC 2.0" }
            };

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("image-url", imageUrl),
                new KeyValuePair <string, object>("width", width),
                new KeyValuePair <string, object>("height", height),
                new KeyValuePair <string, object>("format", (null != format) ? format : "png")
            };

            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

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

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

            HttpContext _context = new HttpContext(_request, _response);

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

            try
            {
                return(_response.RawBody);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Render HTML content to PDF, JPG or PNG. See: https://www.neutrinoapi.com/api/html5-render/
        /// </summary>
        /// <param name="content">Required parameter: The HTML content. This can be either a URL to load HTML from or an actual HTML content string</param>
        /// <param name="format">Optional parameter: Which format to output, available options are: PDF, PNG, JPG</param>
        /// <param name="pageSize">Optional parameter: Set the document page size, can be one of: A0 - A9, B0 - B10, Comm10E, DLE or Letter</param>
        /// <param name="title">Optional parameter: The document title</param>
        /// <param name="margin">Optional parameter: The document margin (in mm)</param>
        /// <param name="marginLeft">Optional parameter: The document left margin (in mm)</param>
        /// <param name="marginRight">Optional parameter: The document right margin (in mm)</param>
        /// <param name="marginTop">Optional parameter: The document top margin (in mm)</param>
        /// <param name="marginBottom">Optional parameter: The document bottom margin (in mm)</param>
        /// <param name="landscape">Optional parameter: Set the document to lanscape orientation</param>
        /// <param name="zoom">Optional parameter: Set the zoom factor when rendering the page (2.0 for double size, 0.5 for half size)</param>
        /// <param name="grayscale">Optional parameter: Render the final document in grayscale</param>
        /// <param name="mediaPrint">Optional parameter: Use @media print CSS styles to render the document</param>
        /// <param name="mediaQueries">Optional parameter: Activate all @media queries before rendering. This can be useful if you wan't to render the mobile version of a responsive website</param>
        /// <param name="forms">Optional parameter: Generate real (fillable) PDF forms from HTML forms</param>
        /// <param name="css">Optional parameter: Inject custom CSS into the HTML. e.g. 'body { background-color: red;}'</param>
        /// <param name="imageWidth">Optional parameter: If rendering to an image format (PNG or JPG) use this image width (in pixels)</param>
        /// <param name="imageHeight">Optional parameter: If rendering to an image format (PNG or JPG) use this image height (in pixels). The default is automatic which dynamically sets the image height based on the content</param>
        /// <param name="renderDelay">Optional parameter: Number of milliseconds to wait before rendering the page (can be useful for pages with animations etc)</param>
        /// <param name="headerTextLeft">Optional parameter: Text to print to the left-hand side header of each page. e.g. 'My header - Page {page_number} of {total_pages}'</param>
        /// <param name="headerTextCenter">Optional parameter: Text to print to the center header of each page</param>
        /// <param name="headerTextRight">Optional parameter: Text to print to the right-hand side header of each page</param>
        /// <param name="headerSize">Optional parameter: The height of your header (in mm)</param>
        /// <param name="headerFont">Optional parameter: Set the header font. Fonts available: Times, Courier, Helvetica, Arial</param>
        /// <param name="headerFontSize">Optional parameter: Set the header font size (in pt)</param>
        /// <param name="headerLine">Optional parameter: Draw a full page width horizontal line under your header</param>
        /// <param name="footerTextLeft">Optional parameter: Text to print to the left-hand side footer of each page. e.g. 'My footer - Page {page_number} of {total_pages}'</param>
        /// <param name="footerTextCenter">Optional parameter: Text to print to the center header of each page</param>
        /// <param name="footerTextRight">Optional parameter: Text to print to the right-hand side header of each page</param>
        /// <param name="footerSize">Optional parameter: The height of your footer (in mm)</param>
        /// <param name="footerFont">Optional parameter: Set the footer font. Fonts available: Times, Courier, Helvetica, Arial</param>
        /// <param name="footerFontSize">Optional parameter: Set the footer font size (in pt)</param>
        /// <param name="footerLine">Optional parameter: Draw a full page width horizontal line above your footer</param>
        /// <param name="pageWidth">Optional parameter: Set the PDF page width explicitly (in mm)</param>
        /// <param name="pageHeight">Optional parameter: Set the PDF page height explicitly (in mm)</param>
        /// <return>Returns the Stream response from the API call</return>
        public async Task <Stream> HTML5RenderAsync(
            string content,
            string format           = "PDF",
            string pageSize         = "A4",
            string title            = null,
            int?margin              = 0,
            int?marginLeft          = 0,
            int?marginRight         = 0,
            int?marginTop           = 0,
            int?marginBottom        = 0,
            bool?landscape          = false,
            int?zoom                = 1.0,
            bool?grayscale          = false,
            bool?mediaPrint         = false,
            bool?mediaQueries       = false,
            bool?forms              = false,
            string css              = null,
            int?imageWidth          = 1024,
            int?imageHeight         = null,
            int?renderDelay         = 0,
            string headerTextLeft   = null,
            string headerTextCenter = null,
            string headerTextRight  = null,
            int?headerSize          = 9,
            string headerFont       = "Courier",
            int?headerFontSize      = 11,
            bool?headerLine         = false,
            string footerTextLeft   = null,
            string footerTextCenter = null,
            string footerTextRight  = null,
            int?footerSize          = 9,
            string footerFont       = "Courier",
            int?footerFontSize      = 11,
            bool?footerLine         = false,
            int?pageWidth           = null,
            int?pageHeight          = null)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/html5-render");

            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(_queryBuilder, new Dictionary <string, object>()
            {
                { "user-id", Configuration.UserId },
                { "api-key", Configuration.ApiKey }
            }, ArrayDeserializationFormat, ParameterSeparator);


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "APIMATIC 2.0" }
            };

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("output-case", "camel"),
                new KeyValuePair <string, object>("content", content),
                new KeyValuePair <string, object>("format", (null != format) ? format : "PDF"),
                new KeyValuePair <string, object>("page-size", (null != pageSize) ? pageSize : "A4"),
                new KeyValuePair <string, object>("title", title),
                new KeyValuePair <string, object>("margin", (null != margin) ? margin : 0),
                new KeyValuePair <string, object>("margin-left", (null != marginLeft) ? marginLeft : 0),
                new KeyValuePair <string, object>("margin-right", (null != marginRight) ? marginRight : 0),
                new KeyValuePair <string, object>("margin-top", (null != marginTop) ? marginTop : 0),
                new KeyValuePair <string, object>("margin-bottom", (null != marginBottom) ? marginBottom : 0),
                new KeyValuePair <string, object>("landscape", (null != landscape) ? landscape : false),
                new KeyValuePair <string, object>("zoom", (null != zoom) ? zoom : 1.0),
                new KeyValuePair <string, object>("grayscale", (null != grayscale) ? grayscale : false),
                new KeyValuePair <string, object>("media-print", (null != mediaPrint) ? mediaPrint : false),
                new KeyValuePair <string, object>("media-queries", (null != mediaQueries) ? mediaQueries : false),
                new KeyValuePair <string, object>("forms", (null != forms) ? forms : false),
                new KeyValuePair <string, object>("css", css),
                new KeyValuePair <string, object>("image-width", (null != imageWidth) ? imageWidth : 1024),
                new KeyValuePair <string, object>("image-height", imageHeight),
                new KeyValuePair <string, object>("render-delay", (null != renderDelay) ? renderDelay : 0),
                new KeyValuePair <string, object>("header-text-left", headerTextLeft),
                new KeyValuePair <string, object>("header-text-center", headerTextCenter),
                new KeyValuePair <string, object>("header-text-right", headerTextRight),
                new KeyValuePair <string, object>("header-size", (null != headerSize) ? headerSize : 9),
                new KeyValuePair <string, object>("header-font", (null != headerFont) ? headerFont : "Courier"),
                new KeyValuePair <string, object>("header-font-size", (null != headerFontSize) ? headerFontSize : 11),
                new KeyValuePair <string, object>("header-line", (null != headerLine) ? headerLine : false),
                new KeyValuePair <string, object>("footer-text-left", footerTextLeft),
                new KeyValuePair <string, object>("footer-text-center", footerTextCenter),
                new KeyValuePair <string, object>("footer-text-right", footerTextRight),
                new KeyValuePair <string, object>("footer-size", (null != footerSize) ? footerSize : 9),
                new KeyValuePair <string, object>("footer-font", (null != footerFont) ? footerFont : "Courier"),
                new KeyValuePair <string, object>("footer-font-size", (null != footerFontSize) ? footerFontSize : 11),
                new KeyValuePair <string, object>("footer-line", (null != footerLine) ? footerLine : false),
                new KeyValuePair <string, object>("page-width", pageWidth),
                new KeyValuePair <string, object>("page-height", pageHeight)
            };

            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

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

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

            HttpContext _context = new HttpContext(_request, _response);

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

            try
            {
                return(_response.RawBody);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// You can experiment with initiating a call through Ytel and view the request response generated when doing so and get the response in json
        /// </summary>
        /// <param name="Models.CreateCallsMakecallInput">Object containing request parameters</param>
        /// <return>Returns the string response from the API call</return>
        public async Task <string> CreateCallsMakecallAsync(Models.CreateCallsMakecallInput input)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/calls/makecall.json");


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "APIMATIC 2.0" }
            };

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("From", input.From),
                new KeyValuePair <string, object>("To", input.To),
                new KeyValuePair <string, object>("Url", input.Url),
                new KeyValuePair <string, object>("Method", input.Method),
                new KeyValuePair <string, object>("StatusCallBackUrl", input.StatusCallBackUrl),
                new KeyValuePair <string, object>("StatusCallBackMethod", input.StatusCallBackMethod),
                new KeyValuePair <string, object>("FallBackUrl", input.FallBackUrl),
                new KeyValuePair <string, object>("FallBackMethod", input.FallBackMethod),
                new KeyValuePair <string, object>("HeartBeatUrl", input.HeartBeatUrl),
                new KeyValuePair <string, object>("HeartBeatMethod", input.HeartBeatMethod),
                new KeyValuePair <string, object>("Timeout", input.Timeout),
                new KeyValuePair <string, object>("PlayDtmf", input.PlayDtmf),
                new KeyValuePair <string, object>("HideCallerId", input.HideCallerId),
                new KeyValuePair <string, object>("Record", input.Record),
                new KeyValuePair <string, object>("RecordCallBackUrl", input.RecordCallBackUrl),
                new KeyValuePair <string, object>("RecordCallBackMethod", input.RecordCallBackMethod),
                new KeyValuePair <string, object>("Transcribe", input.Transcribe),
                new KeyValuePair <string, object>("TranscribeCallBackUrl", input.TranscribeCallBackUrl),
                new KeyValuePair <string, object>("IfMachine", (input.IfMachine.HasValue) ? Models.IfMachineEnumHelper.ToValue(input.IfMachine.Value) : null),
                new KeyValuePair <string, object>("IfMachineUrl", input.IfMachineUrl),
                new KeyValuePair <string, object>("IfMachineMethod", input.IfMachineMethod),
                new KeyValuePair <string, object>("Feedback", input.Feedback),
                new KeyValuePair <string, object>("SurveyId", input.SurveyId)
            };

            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Post(_queryUrl, _headers, _fields, Configuration.BasicAuthUserName, Configuration.BasicAuthPassword);

            //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(_response.Body);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
        /// <summary>
        /// The code generation endpoint. The response is a path to the generated zip file relative to https://apimatic.io/
        /// </summary>
        /// <param name="name">Required parameter: The name of the API being used for code generation</param>
        /// <param name="format">Required parameter: The format of the API description to use for code generation</param>
        /// <param name="template">Required parameter: The template to use for code generation</param>
        /// <param name="body">Required parameter: The input file to use for code generation</param>
        /// <param name="dl">Optional parameter: Optional</param>
        /// <return>Returns the string response from the API call</return>
        public async Task <string> UsingFileAsStringAsync(
            string name,
            Models.Format format,
            Models.Template template,
            FileStreamInfo body,
            int?dl = 0)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/codegen");

            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(_queryBuilder, new Dictionary <string, object>()
            {
                { "name", name },
                { "format", Models.FormatHelper.ToValue(format) },
                { "template", Models.TemplateHelper.ToValue(template) },
                { "dl", (null != dl) ? dl : 0 }
            }, ArrayDeserializationFormat, ParameterSeparator);


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "APIMATIC 2.0" }
            };

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("body", body)
            };

            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Post(_queryUrl, _headers, _fields, 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 APIException(@"Unauthorized: Access is denied due to invalid credentials.", _context);
            }

            if (_response.StatusCode == 412)
            {
                throw new APIException(@"Precondition Failed", _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);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// To add an address to your address book, you create a new address object. You can retrieve and delete individual addresses as well as get a list of addresses. Addresses are identified by a unique random ID.
        /// </summary>
        /// <param name="name">Required parameter: Name of user</param>
        /// <param name="address">Required parameter: Address of user.</param>
        /// <param name="country">Required parameter: Must be a 2 letter country short-name code (ISO 3166)</param>
        /// <param name="state">Required parameter: Must be a 2 letter State eg. CA for US. For Some Countries it can be greater than 2 letters.</param>
        /// <param name="city">Required parameter: City Name.</param>
        /// <param name="zip">Required parameter: Zip code of city.</param>
        /// <param name="description">Optional parameter: Description of addresses.</param>
        /// <param name="email">Optional parameter: Email Id of user.</param>
        /// <param name="phone">Optional parameter: Phone number of user.</param>
        /// <return>Returns the string response from the API call</return>
        public async Task <string> CreateAddressAsync(
            string name,
            string address,
            string country,
            string state,
            string city,
            string zip,
            string description = null,
            string email       = null,
            string phone       = null)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/address/createaddress.json");


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "APIMATIC 2.0" }
            };

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("Name", name),
                new KeyValuePair <string, object>("Address", address),
                new KeyValuePair <string, object>("Country", country),
                new KeyValuePair <string, object>("State", state),
                new KeyValuePair <string, object>("City", city),
                new KeyValuePair <string, object>("Zip", zip),
                new KeyValuePair <string, object>("Description", description),
                new KeyValuePair <string, object>("email", email),
                new KeyValuePair <string, object>("Phone", phone)
            };

            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Post(_queryUrl, _headers, _fields, Configuration.BasicAuthUserName, Configuration.BasicAuthPassword);

            //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(_response.Body);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Send a single message.
        /// </summary>
        /// <param name="senderId">Required parameter: Sender id to send the message from.</param>
        /// <param name="mobileNumber">Required parameter: The mobile number supposed to receive the message.</param>
        /// <param name="message">Required parameter: Message text.</param>
        /// <return>Returns the string response from the API call</return>
        public async Task <string> CreateSendSMSMessageAsync(string senderId, string mobileNumber, string message)
        {
            //validating required parameters
            if (null == senderId)
            {
                throw new ArgumentNullException("senderId", "The parameter \"senderId\" is a required parameter and cannot be null.");
            }

            if (null == mobileNumber)
            {
                throw new ArgumentNullException("mobileNumber", "The parameter \"mobileNumber\" is a required parameter and cannot be null.");
            }

            if (null == message)
            {
                throw new ArgumentNullException("message", "The parameter \"message\" is a required parameter and cannot be null.");
            }

            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/message/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", "Releans" }
            };

            _headers.Add("Authorization", string.Format("Bearer {0}", Configuration.OAuthAccessToken));

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("senderId", senderId),
                new KeyValuePair <string, object>("mobileNumber", mobileNumber),
                new KeyValuePair <string, object>("message", message)
            };

            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

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

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

            HttpContext _context = new HttpContext(_request, _response);

            //return null on 404
            if (_response.StatusCode == 404)
            {
                return(null);
            }

            //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);
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Play Dtmf and send the Digit
        /// </summary>
        /// <param name="CreatePlayAudioInput">Object containing request parameters</param>
        /// <return>Returns the string response from the API call</return>
        public async Task <string> CreatePlayAudioAsync(CreatePlayAudioInput input)
        {
            //validating required parameters
            if (null == input.CallSid)
            {
                throw new ArgumentNullException("callSid", "The property \"CallSid\" in the input object cannot be null.");
            }

            if (null == input.AudioUrl)
            {
                throw new ArgumentNullException("audioUrl", "The property \"AudioUrl\" in the input object cannot be null.");
            }

            //the base uri for api requestss
            string _baseUri = Configuration.GetBaseURI();

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

            _queryBuilder.Append("/calls/playaudios.{ResponseType}");

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


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "message360-api" }
            };

            //append form/field parameters
            var _fields = new Dictionary <string, object>()
            {
                { "CallSid", input.CallSid },
                { "AudioUrl", input.AudioUrl },
                { "Length", input.Length },
                { "Direction", (input.Direction.HasValue) ? DirectionHelper.ToValue(input.Direction.Value) : null },
                { "Loop", input.Loop },
                { "Mix", input.Mix }
            };

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Post(_queryUrl, _headers, _fields, Configuration.BasicAuthUserName, Configuration.BasicAuthPassword);

            //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(_response.Body);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// TODO: type endpoint description here
        /// </summary>
        /// <param name="file">Required parameter: Example: </param>
        /// <param name="ticketId">Required parameter: Example: </param>
        /// <return>Returns the string response from the API call</return>
        public async Task <string> UploadInvoiceAsync(FileStreamInfo file, string ticketId)
        {
            //validating required parameters
            if (null == file)
            {
                throw new ArgumentNullException("file", "The parameter \"file\" is a required parameter and cannot be null.");
            }

            if (null == ticketId)
            {
                throw new ArgumentNullException("ticketId", "The parameter \"ticketId\" is a required parameter and cannot be null.");
            }

            //the base uri for api requestss
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/tickets/{ticket_id}/invoice_upload");

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


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "APIMATIC 2.0" }
            };

            _headers.Add("X-API-TOKEN", Configuration.XAPITOKEN);
            _headers.Add("X-API-EMAIL", Configuration.XAPIEMAIL);

            //append form/field parameters
            var _fields = new Dictionary <string, object>()
            {
                { "file", file }
            };

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

            //Custom Authentication to be added for authorization
            AuthUtility.AppendCustomAuthParams(_request);

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

            HttpContext _context = new HttpContext(_request, _response);

            //return null on 404
            if (_response.StatusCode == 404)
            {
                return(null);
            }

            //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);
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Lets you purchase a phone number from available Flowroute inventory.
        /// </summary>
        /// <param name="id">Required parameter: Phone number to purchase. Must be in 11-digit E.164 format; e.g. 12061231234.</param>
        /// <return>Returns the Models.Number26 response from the API call</return>
        public async Task <Models.Number26> CreatePurchaseAPhoneNumberAsync(string id)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/v2/numbers/{id}");

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


            //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" },
                { "accept", "application/json" }
            };

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Post(_queryUrl, _headers, null, 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);
            }

            if (_response.StatusCode == 403)
            {
                throw new ErrorException(@"Insufficient funds available to complete the request.", _context);
            }

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

            try
            {
                return(APIHelper.JsonDeserialize <Models.Number26>(_response.Body));
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// TODO: type endpoint description here
        /// </summary>
        /// <param name="suites">Required parameter: Example: </param>
        /// <return>Returns the ServerResponse response from the API call</return>
        public async Task <ServerResponse> SendIntegerEnumArrayAsync(List <SuiteCode> suites)
        {
            //validating required parameters
            if (null == suites)
            {
                throw new ArgumentNullException("suites", "The parameter \"suites\" is a required parameter and cannot be null.");
            }

            //the base uri for api requestss
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/form/integerenum");

            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(_queryBuilder, new Dictionary <string, object>()
            {
                { "array", "true" }
            });


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "Stamplay SDK" },
                { "accept", "application/json" }
            };

            //append form/field parameters
            var _fields = new Dictionary <string, object>();

            _fields.Add(APIHelper.PrepareFormFieldsFromObject("suites", suites));

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

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

            HttpContext _context = new HttpContext(_request, _response);

            //return null on 404
            if (_response.StatusCode == 404)
            {
                return(null);
            }

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

            try
            {
                return(APIHelper.JsonDeserialize <ServerResponse>(_response.Body));
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Send an SMS from a message360 number
        /// </summary>
        /// <param name="CreateSendSMSInput">Object containing request parameters</param>
        /// <return>Returns the string response from the API call</return>
        public async Task <string> CreateSendSMSAsync(CreateSendSMSInput input)
        {
            //validating required parameters
            if (null == input.From)
            {
                throw new ArgumentNullException("mfrom", "The property \"From\" in the input object cannot be null.");
            }

            if (null == input.To)
            {
                throw new ArgumentNullException("to", "The property \"To\" in the input object cannot be null.");
            }

            if (null == input.Body)
            {
                throw new ArgumentNullException("body", "The property \"Body\" in the input object cannot be null.");
            }

            //the base uri for api requestss
            string _baseUri = Configuration.GetBaseURI();

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

            _queryBuilder.Append("/sms/sendsms.{ResponseType}");

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


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "message360-api" }
            };

            //append form/field parameters
            var _fields = new Dictionary <string, object>()
            {
                { "fromcountrycode", input.Fromcountrycode },
                { "from", input.From },
                { "tocountrycode", input.Tocountrycode },
                { "to", input.To },
                { "body", input.Body },
                { "method", (input.Method.HasValue) ? HttpActionHelper.ToValue(input.Method.Value) : null },
                { "messagestatuscallback", input.Messagestatuscallback }
            };

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Post(_queryUrl, _headers, _fields, Configuration.BasicAuthUserName, Configuration.BasicAuthPassword);

            //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(_response.Body);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
        /// <summary>
        /// Create a new OAuth 2 token.
        /// </summary>
        /// <param name="authorization">Required parameter: Authorization header in Basic auth format</param>
        /// <param name="scope">Optional parameter: Requested scopes as a space-delimited list.</param>
        /// <param name="fieldParameters">Additional optional form parameters are supported by this endpoint</param>
        /// <return>Returns the Models.OAuthToken response from the API call</return>
        public async Task <Models.OAuthToken> CreateRequestTokenAsync(string authorization, string scope = null, Dictionary <string, object> fieldParameters = null)
        {
            //the base uri for api requests
            string _baseUri = Configuration.GetBaseURI();

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

            _queryBuilder.Append("/oauth/token");


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "APIMATIC 2.0" },
                { "accept", "application/json" },
                { "Authorization", authorization }
            };

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("grant_type", "client_credentials"),
                new KeyValuePair <string, object>("scope", scope)
            };

            //optional form parameters
            _fields.AddRange(APIHelper.PrepareFormFieldsFromObject("", fieldParameters, arrayDeserializationFormat: ArrayDeserializationFormat));
            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

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

            //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 OAuthProviderException(@"OAuth 2 provider returned an error.", _context);
            }

            if (_response.StatusCode == 401)
            {
                throw new OAuthProviderException(@"OAuth 2 provider says client authentication failed.", _context);
            }

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

            try
            {
                return(APIHelper.JsonDeserialize <Models.OAuthToken>(_response.Body));
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
        /// <summary>
        /// Update properties for a Ytel number that has been purchased for your account. Refer to the parameters list for the list of properties that can be updated.
        /// </summary>
        /// <param name="phoneNumber">Required parameter: A valid Ytel number (E.164 format).</param>
        /// <param name="voiceUrl">Required parameter: URL requested once the call connects</param>
        /// <param name="friendlyName">Optional parameter: Phone number friendly name description</param>
        /// <param name="voiceMethod">Optional parameter: Post or Get</param>
        /// <param name="voiceFallbackUrl">Optional parameter: URL requested if the voice URL is not available</param>
        /// <param name="voiceFallbackMethod">Optional parameter: Post or Get</param>
        /// <param name="hangupCallback">Optional parameter: callback url after a hangup occurs</param>
        /// <param name="hangupCallbackMethod">Optional parameter: Post or Get</param>
        /// <param name="heartbeatUrl">Optional parameter: URL requested once the call connects</param>
        /// <param name="heartbeatMethod">Optional parameter: URL that can be requested every 60 seconds during the call to notify of elapsed time</param>
        /// <param name="smsUrl">Optional parameter: URL requested when an SMS is received</param>
        /// <param name="smsMethod">Optional parameter: Post or Get</param>
        /// <param name="smsFallbackUrl">Optional parameter: URL used if any errors occur during execution of InboundXML from an SMS or at initial request of the SmsUrl.</param>
        /// <param name="smsFallbackMethod">Optional parameter: The HTTP method Ytel will use when URL requested if the SmsUrl is not available.</param>
        /// <return>Returns the string response from the API call</return>
        public async Task <string> UpdateNumberAsync(
            string phoneNumber,
            string voiceUrl,
            string friendlyName         = null,
            string voiceMethod          = null,
            string voiceFallbackUrl     = null,
            string voiceFallbackMethod  = null,
            string hangupCallback       = null,
            string hangupCallbackMethod = null,
            string heartbeatUrl         = null,
            string heartbeatMethod      = null,
            string smsUrl            = null,
            string smsMethod         = null,
            string smsFallbackUrl    = null,
            string smsFallbackMethod = null)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/incomingphone/updatenumber.json");


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "APIMATIC 2.0" }
            };

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("PhoneNumber", phoneNumber),
                new KeyValuePair <string, object>("VoiceUrl", voiceUrl),
                new KeyValuePair <string, object>("FriendlyName", friendlyName),
                new KeyValuePair <string, object>("VoiceMethod", voiceMethod),
                new KeyValuePair <string, object>("VoiceFallbackUrl", voiceFallbackUrl),
                new KeyValuePair <string, object>("VoiceFallbackMethod", voiceFallbackMethod),
                new KeyValuePair <string, object>("HangupCallback", hangupCallback),
                new KeyValuePair <string, object>("HangupCallbackMethod", hangupCallbackMethod),
                new KeyValuePair <string, object>("HeartbeatUrl", heartbeatUrl),
                new KeyValuePair <string, object>("HeartbeatMethod", heartbeatMethod),
                new KeyValuePair <string, object>("SmsUrl", smsUrl),
                new KeyValuePair <string, object>("SmsMethod", smsMethod),
                new KeyValuePair <string, object>("SmsFallbackUrl", smsFallbackUrl),
                new KeyValuePair <string, object>("SmsFallbackMethod", smsFallbackMethod)
            };

            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Post(_queryUrl, _headers, _fields, Configuration.BasicAuthUserName, Configuration.BasicAuthPassword);

            //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(_response.Body);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Sends a single header params
        /// </summary>
        /// <param name="customHeader">Required parameter: Example: </param>
        /// <param name="mvalue">Required parameter: Represents the value of the custom header</param>
        /// <return>Returns the ServerResponse response from the API call</return>
        public async Task <ServerResponse> SendHeadersAsync(string customHeader, string mvalue)
        {
            //validating required parameters
            if (null == customHeader)
            {
                throw new ArgumentNullException("customHeader", "The parameter \"customHeader\" is a required parameter and cannot be null.");
            }

            if (null == mvalue)
            {
                throw new ArgumentNullException("mvalue", "The parameter \"mvalue\" is a required parameter and cannot be null.");
            }

            //the base uri for api requestss
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/header");


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "Stamplay SDK" },
                { "accept", "application/json" },
                { "custom-header", customHeader }
            };

            //append form/field parameters
            var _fields = new Dictionary <string, object>()
            {
                { "value", mvalue }
            };

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

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

            HttpContext _context = new HttpContext(_request, _response);

            //return null on 404
            if (_response.StatusCode == 404)
            {
                return(null);
            }

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

            try
            {
                return(APIHelper.JsonDeserialize <ServerResponse>(_response.Body));
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Number Verification
        /// </summary>
        /// <param name="CreateVerifyNumberInput">Object containing request parameters</param>
        /// <return>Returns the string response from the API call</return>
        public async Task <string> CreateVerifyNumberAsync(CreateVerifyNumberInput input)
        {
            //validating required parameters
            if (null == input.Phonenumber)
            {
                throw new ArgumentNullException("phonenumber", "The property \"Phonenumber\" in the input object cannot be null.");
            }

            if (null == input.Type)
            {
                throw new ArgumentNullException("type", "The property \"Type\" in the input object cannot be null.");
            }

            //the base uri for api requestss
            string _baseUri = Configuration.GetBaseURI();

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

            _queryBuilder.Append("/verifycallerid/verifynumber.{ResponseType}");

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


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "message360-api" }
            };

            //append form/field parameters
            var _fields = new Dictionary <string, object>()
            {
                { "phonenumber", input.Phonenumber },
                { "type", input.Type }
            };

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Post(_queryUrl, _headers, _fields, Configuration.BasicAuthUserName, Configuration.BasicAuthPassword);

            //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(_response.Body);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
        /// <summary>
        /// Here you can experiment with initiating a conference call through Ytel and view the request response generated when doing so.
        /// </summary>
        /// <param name="url">Required parameter: URL requested once the conference connects</param>
        /// <param name="mfrom">Required parameter: A valid 10-digit number (E.164 format) that will be initiating the conference call.</param>
        /// <param name="to">Required parameter: A valid 10-digit number (E.164 format) that is to receive the conference call.</param>
        /// <param name="method">Optional parameter: Specifies the HTTP method used to request the required URL once call connects.</param>
        /// <param name="statusCallBackUrl">Optional parameter: URL that can be requested to receive notification when call has ended. A set of default parameters will be sent here once the conference is finished.</param>
        /// <param name="statusCallBackMethod">Optional parameter: Specifies the HTTP methodlinkclass used to request StatusCallbackUrl.</param>
        /// <param name="fallbackUrl">Optional parameter: URL requested if the initial Url parameter fails or encounters an error</param>
        /// <param name="fallbackMethod">Optional parameter: Specifies the HTTP method used to request the required FallbackUrl once call connects.</param>
        /// <param name="record">Optional parameter: Specifies if the conference should be recorded.</param>
        /// <param name="recordCallBackUrl">Optional parameter: Recording parameters will be sent here upon completion.</param>
        /// <param name="recordCallBackMethod">Optional parameter: Specifies the HTTP method used to request the required URL once conference connects.</param>
        /// <param name="scheduleTime">Optional parameter: Schedule conference in future. Schedule time must be greater than current time</param>
        /// <param name="timeout">Optional parameter: The number of seconds the call stays on the line while waiting for an answer. The max time limit is 999 and the default limit is 60 seconds but lower times can be set.</param>
        /// <return>Returns the string response from the API call</return>
        public async Task <string> CreateConferenceAsync(
            string url,
            string mfrom,
            string to,
            string method               = null,
            string statusCallBackUrl    = null,
            string statusCallBackMethod = null,
            string fallbackUrl          = null,
            string fallbackMethod       = null,
            bool?record = null,
            string recordCallBackUrl    = null,
            string recordCallBackMethod = null,
            string scheduleTime         = null,
            int?timeout = null)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/conferences/createConference.json");

            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(_queryBuilder, new Dictionary <string, object>()
            {
                { "Url", url }
            }, ArrayDeserializationFormat, ParameterSeparator);


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "APIMATIC 2.0" }
            };

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("From", mfrom),
                new KeyValuePair <string, object>("To", to),
                new KeyValuePair <string, object>("Method", method),
                new KeyValuePair <string, object>("StatusCallBackUrl", statusCallBackUrl),
                new KeyValuePair <string, object>("StatusCallBackMethod", statusCallBackMethod),
                new KeyValuePair <string, object>("FallbackUrl", fallbackUrl),
                new KeyValuePair <string, object>("FallbackMethod", fallbackMethod),
                new KeyValuePair <string, object>("Record", record),
                new KeyValuePair <string, object>("RecordCallBackUrl", recordCallBackUrl),
                new KeyValuePair <string, object>("RecordCallBackMethod", recordCallBackMethod),
                new KeyValuePair <string, object>("ScheduleTime", scheduleTime),
                new KeyValuePair <string, object>("Timeout", timeout)
            };

            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Post(_queryUrl, _headers, _fields, Configuration.BasicAuthUserName, Configuration.BasicAuthPassword);

            //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(_response.Body);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
        /// <summary>
        /// Create and submit an email message to one or more email addresses.
        /// </summary>
        /// <param name="to">Required parameter: A valid address that will receive the email. Multiple addresses can be separated by using commas.</param>
        /// <param name="type">Required parameter: Specifies the type of email to be sent</param>
        /// <param name="subject">Required parameter: The subject of the mail. Must be a valid string.</param>
        /// <param name="message">Required parameter: The email message that is to be sent in the text.</param>
        /// <param name="mfrom">Optional parameter: A valid address that will send the email.</param>
        /// <param name="cc">Optional parameter: Carbon copy. A valid address that will receive the email. Multiple addresses can be separated by using commas.</param>
        /// <param name="bcc">Optional parameter: Blind carbon copy. A valid address that will receive the email. Multiple addresses can be separated by using commas.</param>
        /// <param name="attachment">Optional parameter: A file that is attached to the email. Must be less than 7 MB in size.</param>
        /// <return>Returns the string response from the API call</return>
        public async Task <string> CreateSendEmailAsync(
            string to,
            Models.TypeEnum type,
            string subject,
            string message,
            string mfrom      = null,
            string cc         = null,
            string bcc        = null,
            string attachment = null)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/email/sendemails.json");


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "APIMATIC 2.0" }
            };

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("To", to),
                new KeyValuePair <string, object>("Type", Models.TypeEnumHelper.ToValue(type)),
                new KeyValuePair <string, object>("Subject", subject),
                new KeyValuePair <string, object>("Message", message),
                new KeyValuePair <string, object>("From", mfrom),
                new KeyValuePair <string, object>("Cc", cc),
                new KeyValuePair <string, object>("Bcc", bcc),
                new KeyValuePair <string, object>("Attachment", attachment)
            };

            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Post(_queryUrl, _headers, _fields, Configuration.BasicAuthUserName, Configuration.BasicAuthPassword);

            //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(_response.Body);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Browser bot can extract content, interact with keyboard and mouse events, and execute JavaScript on a website. See: https://www.neutrinoapi.com/api/browser-bot/
        /// </summary>
        /// <param name="url">Required parameter: The URL to load</param>
        /// <param name="timeout">Optional parameter: Timeout in seconds. Give up if still trying to load the page after this number of seconds</param>
        /// <param name="delay">Optional parameter: Delay in seconds to wait before executing any selectors or JavaScript</param>
        /// <param name="selector">Optional parameter: Extract content from the page DOM using this selector. Commonly known as a CSS selector, you can find a good reference <a href="https://www.w3schools.com/cssref/css_selectors.asp" target="_blank">here</a></param>
        /// <param name="exec">Optional parameter: Execute JavaScript on the page. Each array element should contain a valid JavaScript statement in string form. If a statement returns any kind of value it will be returned in the 'exec-results' response.<br/><br/>For your convenience you can also use the following special shortcut functions:<br/><div style='padding-left:32px; font-family:inherit; font-size:inherit;'>sleep(seconds); Just wait/sleep for the specified number of seconds.<br/>click('selector'); Click on the first element matching the given selector.<br/>focus('selector'); Focus on the first element matching the given selector.<br/>keys('characters'); Send the specified keyboard characters. Use click() or focus() first to send keys to a specific element.<br/>enter(); Send the Enter key.<br/>tab(); Send the Tab key.<br/></div><br/>Example:<br/><div style='padding-left:32px; font-family:inherit; font-size:inherit;'>[ "click('#button-id')", "sleep(1)", "click('.field-class')", "keys('1234')", "enter()" ]</div></param>
        /// <param name="userAgent">Optional parameter: Override the browsers default user-agent string with this one</param>
        /// <param name="ignoreCertificateErrors">Optional parameter: Ignore any TLS/SSL certificate errors and load the page anyway</param>
        /// <return>Returns the Models.BrowserBotResponse response from the API call</return>
        public async Task <Models.BrowserBotResponse> BrowserBotAsync(
            string url,
            int?timeout     = 30,
            int?delay       = 2,
            string selector = null,
            List <string> exec,
            string userAgent             = null,
            bool?ignoreCertificateErrors = false)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/browser-bot");

            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(_queryBuilder, new Dictionary <string, object>()
            {
                { "user-id", Configuration.UserId },
                { "api-key", Configuration.ApiKey }
            }, ArrayDeserializationFormat, ParameterSeparator);


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

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "APIMATIC 2.0" },
                { "accept", "application/json" }
            };

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("output-case", "camel"),
                new KeyValuePair <string, object>("url", url),
                new KeyValuePair <string, object>("timeout", (null != timeout) ? timeout : 30),
                new KeyValuePair <string, object>("delay", (null != delay) ? delay : 2),
                new KeyValuePair <string, object>("selector", selector),
                new KeyValuePair <string, object>("user-agent", userAgent),
                new KeyValuePair <string, object>("ignore-certificate-errors", (null != ignoreCertificateErrors) ? ignoreCertificateErrors : false)
            };

            _fields.AddRange(APIHelper.PrepareFormFieldsFromObject("exec", exec, arrayDeserializationFormat: ArrayDeserializationFormat));
            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

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

            //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 <Models.BrowserBotResponse>(_response.Body));
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }