All Downloads are FREE. Search and download functionalities are using the official Maven repository.

csharp.ApiResponse.mustache Maven / Gradle / Ivy

There is a newer version: 7.8.0
Show newest version
{{>partial_header}}

using System;
using System.Collections.Generic;
using System.Net;

namespace {{packageName}}.Client
{
    /// 
    /// Provides a non-generic contract for the ApiResponse wrapper.
    /// 
    public interface IApiResponse
    {
        /// 
        /// The data type of 
        /// 
        Type ResponseType { get; }

        /// 
        /// The content of this response
        /// 
        Object Content { get; }

        /// 
        /// Gets or sets the status code (HTTP status code)
        /// 
        /// The status code.
        HttpStatusCode StatusCode { get; }

        /// 
        /// Gets or sets the HTTP headers
        /// 
        /// HTTP headers
        Multimap Headers { get; }

        /// 
        /// Gets or sets any error text defined by the calling client.
        /// 
        string ErrorText { get; set; }

        /// 
        /// Gets or sets any cookies passed along on the response.
        /// 
        List Cookies { get; set; }

        /// 
        /// The raw content of this response
        /// 
        string RawContent { get; }
    }

    /// 
    /// API Response
    /// 
    public class ApiResponse : IApiResponse
    {
        #region Properties

        /// 
        /// Gets or sets the status code (HTTP status code)
        /// 
        /// The status code.
        public HttpStatusCode StatusCode { get; }

        /// 
        /// Gets or sets the HTTP headers
        /// 
        /// HTTP headers
        public Multimap Headers { get; }

        /// 
        /// Gets or sets the data (parsed HTTP body)
        /// 
        /// The data.
        public T Data { get; }

        /// 
        /// Gets or sets any error text defined by the calling client.
        /// 
        public string ErrorText { get; set; }

        /// 
        /// Gets or sets any cookies passed along on the response.
        /// 
        public List Cookies { get; set; }

        /// 
        /// The content of this response
        /// 
        public Type ResponseType
        {
            get { return typeof(T); }
        }

        /// 
        /// The data type of 
        /// 
        public object Content
        {
            get { return Data; }
        }

        /// 
        /// The raw content
        /// 
        public string RawContent { get; }

        #endregion Properties

        #region Constructors

        /// 
        /// Initializes a new instance of the  class.
        /// 
        /// HTTP status code.
        /// HTTP headers.
        /// Data (parsed HTTP body)
        /// Raw content.
        public ApiResponse(HttpStatusCode statusCode, Multimap headers, T data, string rawContent)
        {
            StatusCode = statusCode;
            Headers = headers;
            Data = data;
            RawContent = rawContent;
        }

        /// 
        /// Initializes a new instance of the  class.
        /// 
        /// HTTP status code.
        /// HTTP headers.
        /// Data (parsed HTTP body)
        public ApiResponse(HttpStatusCode statusCode, Multimap headers, T data) : this(statusCode, headers, data, null)
        {
        }

        /// 
        /// Initializes a new instance of the  class.
        /// 
        /// HTTP status code.
        /// Data (parsed HTTP body)
        /// Raw content.
        public ApiResponse(HttpStatusCode statusCode, T data, string rawContent) : this(statusCode, null, data, rawContent)
        {
        }

        /// 
        /// Initializes a new instance of the  class.
        /// 
        /// HTTP status code.
        /// Data (parsed HTTP body)
        public ApiResponse(HttpStatusCode statusCode, T data) : this(statusCode, data, null)
        {
        }

        #endregion Constructors
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy