Class ApiClient
API client is mainly responsible for making the HTTP call to the API backend.
Inheritance
Inherited Members
Namespace: Simplic.Datev.Swagger.Client
Assembly: Simplic.Datev.IO.Swagger.dll
Syntax
public class ApiClient
Constructors
| Improve this Doc View SourceApiClient()
Initializes a new instance of the ApiClient class with default configuration.
Declaration
public ApiClient()
ApiClient(Configuration)
Initializes a new instance of the ApiClient class with default base path (http://localhost:58454/datev/api/accounting/v1).
Declaration
public ApiClient(Configuration config)
Parameters
Type | Name | Description |
---|---|---|
Configuration | config | An instance of Configuration. |
ApiClient(String)
Initializes a new instance of the ApiClient class with default configuration.
Declaration
public ApiClient(string basePath = "http://localhost:58454/datev/api/accounting/v1")
Parameters
Type | Name | Description |
---|---|---|
System.String | basePath | The base path. |
Fields
| Improve this Doc View SourceDefault
Gets or sets the default API client for making HTTP calls.
Declaration
[Obsolete("ApiClient.Default is deprecated, please use 'Configuration.Default.ApiClient' instead.")]
public static ApiClient Default
Field Value
Type | Description |
---|---|
ApiClient | The default API client. |
Properties
| Improve this Doc View SourceConfiguration
Gets or sets an instance of the IReadableConfiguration.
Declaration
public IReadableConfiguration Configuration { get; set; }
Property Value
Type | Description |
---|---|
IReadableConfiguration | An instance of the IReadableConfiguration. |
Remarks
IReadableConfiguration helps us to avoid modifying possibly global configuration values from within a given client. It does not guarantee thread-safety of the Configuration instance in any way.
RestClient
Gets or sets the RestClient.
Declaration
public RestClient RestClient { get; set; }
Property Value
Type | Description |
---|---|
RestClient | An instance of the RestClient |
Methods
| Improve this Doc View SourceBase64Encode(String)
Encode string in base64 format.
Declaration
public static string Base64Encode(string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | String to be encoded. |
Returns
Type | Description |
---|---|
System.String | Encoded string. |
CallApi(String, RestSharp.Method, List<KeyValuePair<String, String>>, Object, Dictionary<String, String>, Dictionary<String, String>, Dictionary<String, FileParameter>, Dictionary<String, String>, String)
Makes the HTTP request (Sync).
Declaration
public object CallApi(string path, RestSharp.Method method, List<KeyValuePair<string, string>> queryParams, object postBody, Dictionary<string, string> headerParams, Dictionary<string, string> formParams, Dictionary<string, FileParameter> fileParams, Dictionary<string, string> pathParams, string contentType)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | URL path. |
RestSharp.Method | method | HTTP method. |
System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> | queryParams | Query parameters. |
System.Object | postBody | HTTP body (POST request). |
System.Collections.Generic.Dictionary<System.String, System.String> | headerParams | Header parameters. |
System.Collections.Generic.Dictionary<System.String, System.String> | formParams | Form parameters. |
System.Collections.Generic.Dictionary<System.String, FileParameter> | fileParams | File parameters. |
System.Collections.Generic.Dictionary<System.String, System.String> | pathParams | Path parameters. |
System.String | contentType | Content Type of the request |
Returns
Type | Description |
---|---|
System.Object | Object |
CallApiAsync(String, RestSharp.Method, List<KeyValuePair<String, String>>, Object, Dictionary<String, String>, Dictionary<String, String>, Dictionary<String, FileParameter>, Dictionary<String, String>, String)
Makes the asynchronous HTTP request.
Declaration
public async Task<object> CallApiAsync(string path, RestSharp.Method method, List<KeyValuePair<string, string>> queryParams, object postBody, Dictionary<string, string> headerParams, Dictionary<string, string> formParams, Dictionary<string, FileParameter> fileParams, Dictionary<string, string> pathParams, string contentType)
Parameters
Type | Name | Description |
---|---|---|
System.String | path | URL path. |
RestSharp.Method | method | HTTP method. |
System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> | queryParams | Query parameters. |
System.Object | postBody | HTTP body (POST request). |
System.Collections.Generic.Dictionary<System.String, System.String> | headerParams | Header parameters. |
System.Collections.Generic.Dictionary<System.String, System.String> | formParams | Form parameters. |
System.Collections.Generic.Dictionary<System.String, FileParameter> | fileParams | File parameters. |
System.Collections.Generic.Dictionary<System.String, System.String> | pathParams | Path parameters. |
System.String | contentType | Content type. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.Object> | The Task instance. |
ConvertType(Object, Type)
Dynamically cast the object into target type.
Declaration
public static dynamic ConvertType(dynamic fromObject, Type toObject)
Parameters
Type | Name | Description |
---|---|---|
System.Object | fromObject | Object to be casted |
System.Type | toObject | Target type |
Returns
Type | Description |
---|---|
System.Object | Casted object |
Deserialize(IRestResponse, Type)
Deserialize the JSON string into a proper object.
Declaration
public object Deserialize(IRestResponse response, Type type)
Parameters
Type | Name | Description |
---|---|---|
IRestResponse | response | The HTTP response. |
System.Type | type | Object type. |
Returns
Type | Description |
---|---|
System.Object | Object representation of the JSON string. |
EscapeString(String)
Escape string (url-encoded).
Declaration
public string EscapeString(string str)
Parameters
Type | Name | Description |
---|---|---|
System.String | str | String to be escaped. |
Returns
Type | Description |
---|---|
System.String | Escaped string. |
IsJsonMime(String)
Check if the given MIME is a JSON MIME. JSON MIME examples: application/json application/json; charset=UTF8 APPLICATION/JSON application/vnd.company+json
Declaration
public bool IsJsonMime(string mime)
Parameters
Type | Name | Description |
---|---|---|
System.String | mime | MIME |
Returns
Type | Description |
---|---|
System.Boolean | Returns True if MIME type is json. |
ParameterToFile(String, Stream)
Create FileParameter based on Stream.
Declaration
public FileParameter ParameterToFile(string name, Stream stream)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Parameter name. |
System.IO.Stream | stream | Input stream. |
Returns
Type | Description |
---|---|
FileParameter | FileParameter. |
ParameterToKeyValuePairs(String, String, Object)
Convert params to key/value pairs. Use collectionFormat to properly format lists and collections.
Declaration
public IEnumerable<KeyValuePair<string, string>> ParameterToKeyValuePairs(string collectionFormat, string name, object value)
Parameters
Type | Name | Description |
---|---|---|
System.String | collectionFormat | |
System.String | name | Key name. |
System.Object | value | Value object. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.String, System.String>> | A list of KeyValuePairs |
ParameterToString(Object)
If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime. If parameter is a list, join the list with ",". Otherwise just return the string.
Declaration
public string ParameterToString(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The parameter (header, path, query, form). |
Returns
Type | Description |
---|---|
System.String | Formatted string. |
ReadAsBytes(Stream)
Convert stream to byte array
Declaration
public static byte[] ReadAsBytes(Stream inputStream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | inputStream | Input stream to be converted |
Returns
Type | Description |
---|---|
System.Byte[] | Byte array |
SanitizeFilename(String)
Sanitize filename by removing the path
Declaration
public static string SanitizeFilename(string filename)
Parameters
Type | Name | Description |
---|---|---|
System.String | filename | Filename |
Returns
Type | Description |
---|---|
System.String | Filename |
SelectHeaderAccept(String[])
Select the Accept header's value from the given accepts array: if JSON exists in the given array, use it; otherwise use all of them (joining into a string)
Declaration
public string SelectHeaderAccept(string[] accepts)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | accepts | The accepts array to select from. |
Returns
Type | Description |
---|---|
System.String | The Accept header to use. |
SelectHeaderContentType(String[])
Select the Content-Type header's value from the given content-type array: if JSON type exists in the given array, use it; otherwise use the first one defined in 'consumes'
Declaration
public string SelectHeaderContentType(string[] contentTypes)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | contentTypes | The Content-Type array to select from. |
Returns
Type | Description |
---|---|
System.String | The Content-Type header to use. |
Serialize(Object)
Serialize an input (model) into JSON string
Declaration
public string Serialize(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | Object. |
Returns
Type | Description |
---|---|
System.String | JSON string. |
UrlEncode(String)
URL encode a string Credit/Ref: https://github.com/restsharp/RestSharp/blob/master/RestSharp/Extensions/StringExtensions.cs#L50
Declaration
public static string UrlEncode(string input)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | String to be URL encoded |
Returns
Type | Description |
---|---|
System.String | Byte array |