| | 1 | | namespace Songhay.Models; |
| | 2 | |
|
| | 3 | | /// <summary> |
| | 4 | | /// REST API Metadata |
| | 5 | | /// </summary> |
| | 6 | | public class RestApiMetadata |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// A convential name representing an API key |
| | 10 | | /// to sent in the HTTP headers for authentication. |
| | 11 | | /// </summary> |
| | 12 | | /// <remarks> |
| | 13 | | /// Usually <c>"headerAuthorization": "Authorization"</c>. |
| | 14 | | /// |
| | 15 | | /// See https://docs.microsoft.com/en-us/rest/api/azure/#request-header |
| | 16 | | /// </remarks> |
| | 17 | | public const string ClaimsSetHeaderApiAuthorization = "headerAuthorization"; |
| | 18 | |
|
| | 19 | | /// <summary> |
| | 20 | | /// A convential name representing an API key |
| | 21 | | /// to sent in the HTTP headers for authentication. |
| | 22 | | /// </summary> |
| | 23 | | /// <remarks> |
| | 24 | | /// Usually <c>"headerContentType": "Content-Type"</c>. |
| | 25 | | /// |
| | 26 | | /// See https://docs.microsoft.com/en-us/rest/api/azure/#request-header |
| | 27 | | /// </remarks> |
| | 28 | | public const string ClaimsSetHeaderApiContentType = "headerContentType"; |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// A convential name representing an API key |
| | 32 | | /// to sent in the HTTP headers for authentication. |
| | 33 | | /// </summary> |
| | 34 | | /// <remarks> |
| | 35 | | /// Usually <c>"headerKey": "X-ApiKey"</c>. |
| | 36 | | /// </remarks> |
| | 37 | | public const string ClaimsSetHeaderApiKey = "headerKey"; |
| | 38 | |
|
| | 39 | | /// <summary> |
| | 40 | | /// Gets or sets the API base. |
| | 41 | | /// </summary> |
| 4 | 42 | | public Uri? ApiBase { get; set; } |
| | 43 | |
|
| | 44 | | /// <summary> |
| | 45 | | /// Gets or sets the API key. |
| | 46 | | /// </summary> |
| 0 | 47 | | public string? ApiKey { get; set; } |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Gets or sets the claims set. |
| | 51 | | /// </summary> |
| 1 | 52 | | public Dictionary<string, string> ClaimsSet { get; set; } = new(); |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Gets or sets the URI templates. |
| | 56 | | /// </summary> |
| 4 | 57 | | public Dictionary<string, string> UriTemplates { get; set; } = new(); |
| | 58 | |
|
| | 59 | | /// <summary> |
| | 60 | | /// Converts this instance into a <see cref="string"/> representation. |
| | 61 | | /// </summary> |
| | 62 | | public override string ToString() |
| 0 | 63 | | { |
| 0 | 64 | | var sb = new StringBuilder(); |
| | 65 | |
|
| 0 | 66 | | if (ApiBase != null) sb.AppendFormat("ApiBase: {0}", ApiBase); |
| 0 | 67 | | if (!string.IsNullOrWhiteSpace(ApiKey)) sb.Append($" ApiKey: {ApiKey}"); |
| | 68 | |
|
| 0 | 69 | | if (ClaimsSet is {Count: > 0}) |
| 0 | 70 | | { |
| 0 | 71 | | sb.AppendLine($"{nameof(ClaimsSet)}:"); |
| 0 | 72 | | foreach (var item in ClaimsSet) |
| 0 | 73 | | { |
| 0 | 74 | | sb.AppendLine($" {item.Key}:"); |
| 0 | 75 | | sb.AppendLine($" {item.Value}"); |
| 0 | 76 | | } |
| 0 | 77 | | } |
| | 78 | |
|
| 0 | 79 | | if (UriTemplates is {Count: > 0}) |
| 0 | 80 | | { |
| 0 | 81 | | sb.AppendLine($"{nameof(UriTemplates)}:"); |
| 0 | 82 | | foreach (var item in UriTemplates) |
| 0 | 83 | | { |
| 0 | 84 | | sb.AppendLine($" {item.Key}:"); |
| 0 | 85 | | sb.AppendLine($" {item.Value}"); |
| 0 | 86 | | } |
| 0 | 87 | | } |
| | 88 | |
|
| 0 | 89 | | return sb.Length > 0 ? sb.ToString().Trim() : base.ToString() ?? GetType().Name; |
| 0 | 90 | | } |
| | 91 | | } |