Media Type Management
Managing media types encompasses the following interactions:
- Listing all media type IDs
- Getting the definition of a media type
- Creating or updating a media type
- Deleting a media type
The following examples assume you already have a configured
BoomackClient
instance in the variable client
.
See Get Started if you do not know how to configure
a BoomackClient instance.
List Media Type IDs
The method GetMediaTypeIds() returns a IdListResponse, which is an enumerable of strings.
var response = await client.GetPresetIds();
foreach (var id in response)
{
Console.WriteLine("- " + id);
}
Get Media Type
The method GetMediaType(string) returns a MediaTypeResponse.
var response = await client.GetMediaType("text/x-my-csharp");
var mediaType = response.MediaType;
Console.WriteLine("Is Text: {0}", mediaType.Text);
Console.WriteLine("Presets: ");
foreach (var presetIds in mediaType.Presets)
{
Console.WriteLine("- {0}", presetIds);
}
Console.WriteLine("Background: {0}", mediaType.Options.Background);
Create or Update Media Type
On the HTTP API level of the Boomack Server, creating and updating are the same operation. Both are implemented by an HTTP PUT request.
To make the code using this client library more readable, however, two methods are available that do the same thing in the background:
var mediaType = new MediaType()
{
Text = true,
Presets = new[] { "my-preset" },
Options = new DisplayOptions()
{
Background = "CornflowerBlue",
},
};
await client.AddMediaType("text/x-my-csharp", mediaType);
Delete Media Type
For the deletion of a media type you just need the media type ID.
await client.DeleteMediaType("text/x-my-csharp");
Next: Action Management