/// <summary>
        /// Convert an API from the user's account using the API's [API Integration Key](https://docs.apimatic.io/getting-started/manage-apis/#view-api-integration-key). The response is generated zip file as per selected template.
        /// > Note: This endpoint does not require Basic Authentication.
        /// </summary>
        /// <param name="apikey">Required parameter: The API Key of the pre-configured API</param>
        /// <param name="template">Required parameter: The template to use for code generation</param>
        /// <param name="dl">Optional parameter: Optional</param>
        /// <return>Returns the Stream response from the API call</return>
        public async Task <Stream> UsingApikeyAsBinaryAsync(string apikey, Models.Template template, int?dl = 1)
        {
            //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>()
            {
                { "apikey", apikey },
                { "template", Models.TemplateHelper.ToValue(template) },
                { "dl", (null != dl) ? dl : 1 }
            }, 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" }
            };

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Get(_queryUrl, _headers, 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 == 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.RawBody);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Clean and sanitize untrusted HTML. See: https://www.neutrinoapi.com/api/html-clean/
        /// </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="outputType">Required parameter: The level of sanitization, possible values are:<br/><b>plain-text</b>: reduce the content to plain text only (no HTML tags at all)<br/><br/><b>simple-text</b>: allow only very basic text formatting tags like b, em, i, strong, u<br/><br/><b>basic-html</b>: allow advanced text formatting and hyper links<br/><br/><b>basic-html-with-images</b>: same as basic html but also allows image tags<br/><br/><b>advanced-html</b>: same as basic html with images but also allows many more common HTML tags like table, ul, dl, pre<br/></param>
        /// <return>Returns the Stream response from the API call</return>
        public async Task <Stream> HTMLCleanAsync(string content, string outputType)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/html-clean");

            //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>("content", content),
                new KeyValuePair <string, object>("output-type", outputType)
            };

            //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.º 3
0
        /// <summary>
        /// To choose a file format, set the Accept header to either 'application/pdf' or 'text/csv'
        /// </summary>
        /// <param name="accountUid">Required parameter: Example: </param>
        /// <param name="yearMonth">Required parameter: Example: </param>
        /// <return>Returns the Stream response from the API call</return>
        public async Task <Stream> GetDownloadCsvStatementAsync(Guid accountUid, string yearMonth)
        {
            //validating required parameters
            if (null == yearMonth)
            {
                throw new ArgumentNullException(nameof(yearMonth), "The parameter \"yearMonth\" is a required parameter and cannot be null.");
            }

            //the base uri for api requests
            var baseUri = Configuration.GetBaseURI();

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

            queryBuilder.Append("/api/v2/accounts/{accountUid}/statement/download");

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

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


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

            //append request with appropriate headers and parameters
            var headers = APIHelper.GetRequestHeaders(true, true);

            //prepare the API call request to fetch the response
            var request = ClientInstance.Get(queryUrl, headers);

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

            var context = new HTTPContext(request, response);

            //handle errors
            ValidateResponse(response, context);

            try
            {
                return(response.RawBody);
            }
            catch (Exception ex)
            {
                throw new APIException("Failed to parse the response: " + ex.Message, context);
            }
        }
        /// <summary>
        /// Download API description from the given URL and convert it to the given format. The API description format of the provided 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="descriptionUrl">Required parameter: The URL where the API description will be downloaded from</param>
        /// <return>Returns the Stream response from the API call</return>
        public async Task <Stream> UsingUrlAsync(Models.FormatTransformer format, string descriptionUrl)
        {
            //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) },
                { "descriptionUrl", descriptionUrl }
            }, 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" }
            };

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Get(_queryUrl, _headers, 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.º 5
0
        /// <summary>
        /// To choose a file format, set the Accept header to either 'application/pdf' or 'text/csv'
        /// </summary>
        /// <param name="accountUid">Required parameter: Example: </param>
        /// <param name="start">Required parameter: Example: </param>
        /// <param name="end">Optional parameter: Example: </param>
        /// <return>Returns the Stream response from the API call</return>
        public async Task <Stream> GetDownloadCsvStatementForDateRangeAsync(Guid accountUid, DateTime start, DateTime?end = null)
        {
            //the base uri for api requests
            var baseUri = Configuration.GetBaseURI();

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

            queryBuilder.Append("/api/v2/accounts/{accountUid}/statement/downloadForDateRange");

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

            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(queryBuilder, new Dictionary <string, object>
            {
                { "start", start.ToString("yyyy'-'MM'-'dd") },
                { "end", end?.ToString("yyyy'-'MM'-'dd") }
            }, ArrayDeserializationFormat, ParameterSeparator);


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

            //append request with appropriate headers and parameters
            var headers = APIHelper.GetRequestHeaders(true, true);

            //prepare the API call request to fetch the response
            var request = ClientInstance.Get(queryUrl, headers);

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

            var context = new HTTPContext(request, response);

            //handle errors
            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>
        /// Categories are subdivisions within an account.
        /// The `defaultCategory` from [`/api/v2/accounts`](#operations-tag-Accounts) is where the main balance and transactions are held.
        /// Other categories are used for Savings Goals.
        /// </summary>
        /// <param name="accountUid">Required parameter: Account uid</param>
        /// <param name="categoryUid">Required parameter: Category uid</param>
        /// <param name="feedItemUid">Required parameter: Feed item uid</param>
        /// <param name="feedItemAttachmentUid">Required parameter: Feed item attachment uid</param>
        /// <return>Returns the Stream response from the API call</return>
        public async Task <Stream> GetDownloadFeedItemAttachmentAsync(
            Guid accountUid,
            Guid categoryUid,
            Guid feedItemUid,
            Guid feedItemAttachmentUid)
        {
            //the base uri for api requests
            var baseUri = Configuration.GetBaseURI();

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

            queryBuilder.Append("/api/v2/feed/account/{accountUid}/category/{categoryUid}/{feedItemUid}/attachments/{feedItemAttachmentUid}");

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


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

            //append request with appropriate headers and parameters
            var headers = APIHelper.GetRequestHeaders(true, true);

            //prepare the API call request to fetch the response
            var request = ClientInstance.Get(queryUrl, headers);

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

            var context = new HTTPContext(request, response);

            //handle errors
            ValidateResponse(response, context);

            try
            {
                return(response.RawBody);
            }
            catch (Exception ex)
            {
                throw new APIException("Failed to parse the response: " + ex.Message, context);
            }
        }
        /// <summary>
        /// gets a binary object
        /// </summary>
        /// <return>Returns the Stream response from the API call</return>
        public async Task <Stream> GetBinaryAsync()
        {
            //the base uri for api requestss
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/response/binary");


            //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" }
            };

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

            //invoke request and get response
            HttpResponse _response = await ClientInstance.ExecuteAsBinaryAsync(_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.RawBody);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }
        /// <summary>
        /// gets a binary object
        /// </summary>
        /// <return>Returns the Stream response from the API call</return>
        public async Task <Stream> GetBinaryAsync()
        {
            //the base uri for api requestss
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/response/binary");


            //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" }
            };

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

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

            HttpContext _context = new HttpContext(_request, _response);

            //Error handling using HTTP status codes
            if ((_response.StatusCode < 200) || (_response.StatusCode > 206)) //[200,206] = HTTP OK
            {
                throw new APIException(@"HTTP Response Not OK", _context);
            }

            try
            {
                return(_response.RawBody);
            }
            catch (Exception ex)
            {
                throw new APIException("Failed to parse the response: " + ex.Message, _context);
            }
        }
Ejemplo n.º 9
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.º 10
0
        /// <summary>
        /// Watermark one image with another image. See: https://www.neutrinoapi.com/api/image-watermark/
        /// </summary>
        /// <param name="imageUrl">Required parameter: The URL to the source image</param>
        /// <param name="watermarkUrl">Required parameter: The URL to the watermark image</param>
        /// <param name="opacity">Optional parameter: The opacity of the watermark (0 to 100)</param>
        /// <param name="format">Optional parameter: The output image format, can be either png or jpg</param>
        /// <param name="position">Optional parameter: The position of the watermark image, possible values are:<br/>center, top-left, top-center, top-right, bottom-left, bottom-center, bottom-right</param>
        /// <param name="width">Optional parameter: If set resize the resulting image to this width (in px) while preserving aspect ratio</param>
        /// <param name="height">Optional parameter: If set resize the resulting image to this height (in px) while preserving aspect ratio</param>
        /// <return>Returns the Stream response from the API call</return>
        public async Task <Stream> ImageWatermarkAsync(
            string imageUrl,
            string watermarkUrl,
            int?opacity     = 50,
            string format   = "png",
            string position = "center",
            int?width       = null,
            int?height      = null)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

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

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

            //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>("watermark-url", watermarkUrl),
                new KeyValuePair <string, object>("opacity", (null != opacity) ? opacity : 50),
                new KeyValuePair <string, object>("format", (null != format) ? format : "png"),
                new KeyValuePair <string, object>("position", (null != position) ? position : "center"),
                new KeyValuePair <string, object>("width", width),
                new KeyValuePair <string, object>("height", height)
            };

            //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);
            }
        }
        /// <summary>
        /// Check if there is a bonus to be given to the advocate. Allows the clients to check if there is a bonus to be given, it simulates the behaivor of a POST request to /accounts/{account_slug}/bonuses resource. This resource is idempotent.
        /// </summary>
        /// <param name="accountSlug">Required parameter: The account identifier</param>
        /// <param name="advocateToken">Required parameter: The referral's token. Usually the one that completed the purchase, or trigger an event.</param>
        /// <param name="reference">Required parameter: The reference number for this request. Usually the order_id, payment_id, or timestamp.</param>
        /// <param name="paymentAmount">Required parameter: The payment amount the referrals has made. Required for a percentage based campaign.</param>
        /// <return>Returns the Stream response from the API call</return>
        public async Task <Stream> GetBonusCheckupAsync(
            string accountSlug,
            string advocateToken,
            string reference,
            double paymentAmount)
        {
            //the base uri for api requestss
            string _baseUri = Configuration.BaseUri;

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

            _queryBuilder.Append("/accounts/{account_slug}/bonuses/checkup");

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

            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(_queryBuilder, new Dictionary <string, object>()
            {
                { "advocate_token", advocateToken },
                { "reference", reference },
                { "payment_amount", paymentAmount }
            });


            //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("Content-Type", Configuration.ContentType);
            _headers.Add("X-Auth-Token", Configuration.XAuthToken);

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

            //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);
            }
        }