Class ApiUtils
Utility functions providing some benefit to API client consumers.
Inherited Members
Namespace: Unity.Services.Apis
Assembly: Unity.Services.Apis.dll
Syntax
public class ApiUtils
Fields
JsonRegex
Provides a case-insensitive check that a provided content type is a known JSON-like content type.
Declaration
public static readonly Regex JsonRegex
Field Value
Type | Description |
---|---|
Regex |
Methods
Base64Encode(string)
Encode string in base64 format.
Declaration
public static string Base64Encode(string text)
Parameters
Type | Name | Description |
---|---|---|
string | text | string to be encoded. |
Returns
Type | Description |
---|---|
string | Encoded 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 static bool IsJsonMime(string mime)
Parameters
Type | Name | Description |
---|---|---|
string | mime | MIME |
Returns
Type | Description |
---|---|
bool | Returns True if MIME type is json. |
ParameterToMultiMap(IApiConfiguration, string, string, object)
Convert params to key/value pairs. Use collectionFormat to properly format lists and collections.
Declaration
public static Multimap<string, string> ParameterToMultiMap(IApiConfiguration configuration, string collectionFormat, string name, object value)
Parameters
Type | Name | Description |
---|---|---|
IApi |
configuration | The api configuration. |
string | collectionFormat | The swagger-supported collection format, one of: csv, tsv, ssv, pipes, multi |
string | name | Key name. |
object | value | Value object. |
Returns
ParameterToString(IApiConfiguration, 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 static string ParameterToString(IApiConfiguration configuration, object obj)
Parameters
Type | Name | Description |
---|---|---|
IApi |
configuration | The api configuration. |
object | obj | The parameter (header, path, query, form). |
Returns
Type | Description |
---|---|
string | Formatted string. |
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 static string SelectHeaderAccept(string[] accepts)
Parameters
Type | Name | Description |
---|---|---|
string[] | accepts | The accepts array to select from. |
Returns
Type | Description |
---|---|
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 static string SelectHeaderContentType(string[] contentTypes)
Parameters
Type | Name | Description |
---|---|---|
string[] | contentTypes | The Content-Type array to select from. |
Returns
Type | Description |
---|---|
string | The Content-Type header to use. |