| | 1 | | using System.Net.Http.Headers; |
| | 2 | |
|
| | 3 | | namespace Songhay.Extensions; |
| | 4 | |
|
| | 5 | | /// <summary> |
| | 6 | | /// Extensions of <see cref="ProgramMetadata"/>. |
| | 7 | | /// </summary> |
| | 8 | | public static class ProgramMetadataExtensions |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// Converts <see cref="ProgramMetadata" /> |
| | 12 | | /// to the conventional <see cref="HttpRequestHeaders"/>. |
| | 13 | | /// </summary> |
| | 14 | | /// <param name="meta">The <see cref="ProgramMetadata"/>.</param> |
| | 15 | | /// <param name="restApiMetadataSetKey">The key for <see cref="ProgramMetadata.RestApiMetadataSet"/>.</param> |
| | 16 | | public static Dictionary<string, string> ToConventionalHeaders(this ProgramMetadata? meta, |
| | 17 | | string restApiMetadataSetKey) |
| 0 | 18 | | { |
| 0 | 19 | | ArgumentNullException.ThrowIfNull(meta); |
| | 20 | |
|
| 0 | 21 | | var genWebApiMeta = meta.RestApiMetadataSet.TryGetValueWithKey(restApiMetadataSetKey); |
| 0 | 22 | | if (genWebApiMeta == null) throw new NullReferenceException(nameof(genWebApiMeta)); |
| | 23 | |
|
| 0 | 24 | | var headers = new Dictionary<string, string> |
| 0 | 25 | | { |
| 0 | 26 | | { |
| 0 | 27 | | genWebApiMeta.ClaimsSet.TryGetValueWithKey(RestApiMetadata.ClaimsSetHeaderApiKey).ToReferenceTypeValueOr |
| 0 | 28 | | genWebApiMeta.ApiKey ?? |
| 0 | 29 | | throw new NullReferenceException( |
| 0 | 30 | | $"The expected {nameof(RestApiMetadata.ClaimsSetHeaderApiKey)} is not here.") |
| 0 | 31 | | } |
| 0 | 32 | | }; |
| | 33 | |
|
| 0 | 34 | | return headers; |
| 0 | 35 | | } |
| | 36 | | } |