//------------------------------------------------------------------------------ // // This code was generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. // // Changes to this file may cause incorrect behavior and will be lost when // the code is regenerated. // //------------------------------------------------------------------------------ #nullable enable namespace LukeHagar.PlexAPI.SDK { using LukeHagar.PlexAPI.SDK.Hooks; using LukeHagar.PlexAPI.SDK.Models.Components; using LukeHagar.PlexAPI.SDK.Models.Errors; using LukeHagar.PlexAPI.SDK.Models.Requests; using LukeHagar.PlexAPI.SDK.Utils; using LukeHagar.PlexAPI.SDK.Utils.Retries; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; /// /// Media grabbers provide ways for media to be obtained for a given protocol. The simplest ones are `stream` and `download`. More complex grabbers can have associated devices
/// /// ///
/// Network tuners can present themselves on the network using the Simple Service Discovery Protocol and Plex Media Server will discover them. The following XML is an example of the data returned from SSDP. The `deviceType`, `serviceType`, and `serviceId` values must remain as they are in the example in order for PMS to properly discover the device. Other less-obvious fields are described in the parameters section below.
///
/// Example SSDP output
/// ```
/// <root xmlns="urn:schemas-upnp-org:device-1-0">
/// <specVersion>
/// <major>1</major>
/// <minor>0</minor>
/// </specVersion>
/// <device>
/// <deviceType>urn:plex-tv:device:Media:1</deviceType>
/// <friendlyName>Turing Hopper 3000</friendlyName>
/// <manufacturer>Plex, Inc.</manufacturer>
/// <manufacturerURL>https://plex.tv/</manufacturerURL>
/// <modelDescription>Turing Hopper 3000 Media Grabber</modelDescription>
/// <modelName>Plex Media Grabber</modelName>
/// <modelNumber>1</modelNumber>
/// <modelURL>https://plex.tv</modelURL>
/// <UDN>uuid:42fde8e4-93b6-41e5-8a63-12d848655811</UDN>
/// <serviceList>
/// <service>
/// <URLBase>http://10.0.0.5:8088</URLBase>
/// <serviceType>urn:plex-tv:service:MediaGrabber:1</serviceType>
/// <serviceId>urn:plex-tv:serviceId:MediaGrabber</serviceId>
/// </service>
/// </serviceList>
/// </device>
/// </root>
/// ```
///
/// - UDN: (string) A UUID for the device. This should be unique across models of a device at minimum.
/// - URLBase: (string) The base HTTP URL for the device from which all of the other endpoints are hosted.
/// ///
///
public interface IDevices { /// /// Get available grabbers /// /// /// Get available grabbers visible to the server /// /// Task GetAvailableGrabbersAsync(GetAvailableGrabbersRequest? request = null); /// /// Get all devices /// /// /// Get the list of all devices present /// /// Task ListDevicesAsync(); /// /// Add a device /// /// /// This endpoint adds a device to an existing grabber. The device is identified, and added to the correct grabber. /// /// Task AddDeviceAsync(AddDeviceRequest? request = null); /// /// Tell grabbers to discover devices /// /// /// Tell grabbers to discover devices /// /// Task DiscoverDevicesAsync(); /// /// Remove a device /// /// /// Remove a devices by its id along with its channel mappings /// /// Task RemoveDeviceAsync(RemoveDeviceRequest request); /// /// Get device details /// /// /// Get a device's details by its id /// /// Task GetDeviceDetailsAsync(GetDeviceDetailsRequest request); /// /// Enable or disable a device /// /// /// Enable or disable a device by its id /// /// Task ModifyDeviceAsync(ModifyDeviceRequest request); /// /// Set a device's channel mapping /// /// /// Set a device's channel mapping /// /// Task SetChannelmapAsync(SetChannelmapRequest request); /// /// Get a device's channels /// /// /// Get a device's channels by its id /// /// Task GetDevicesChannelsAsync(GetDevicesChannelsRequest request); /// /// Set device preferences /// /// /// Set device preferences by its id /// /// Task SetDevicePreferencesAsync(SetDevicePreferencesRequest request); /// /// Tell a device to stop scanning for channels /// /// /// Tell a device to stop scanning for channels /// /// Task StopScanAsync(StopScanRequest request); /// /// Tell a device to scan for channels /// /// /// Tell a device to scan for channels /// /// Task ScanAsync(ScanRequest request); /// /// Get device thumb /// /// /// Get a device's thumb for display to the user /// /// Task GetThumbAsync(GetThumbRequest request); } /// /// Media grabbers provide ways for media to be obtained for a given protocol. The simplest ones are `stream` and `download`. More complex grabbers can have associated devices
/// /// ///
/// Network tuners can present themselves on the network using the Simple Service Discovery Protocol and Plex Media Server will discover them. The following XML is an example of the data returned from SSDP. The `deviceType`, `serviceType`, and `serviceId` values must remain as they are in the example in order for PMS to properly discover the device. Other less-obvious fields are described in the parameters section below.
///
/// Example SSDP output
/// ```
/// <root xmlns="urn:schemas-upnp-org:device-1-0">
/// <specVersion>
/// <major>1</major>
/// <minor>0</minor>
/// </specVersion>
/// <device>
/// <deviceType>urn:plex-tv:device:Media:1</deviceType>
/// <friendlyName>Turing Hopper 3000</friendlyName>
/// <manufacturer>Plex, Inc.</manufacturer>
/// <manufacturerURL>https://plex.tv/</manufacturerURL>
/// <modelDescription>Turing Hopper 3000 Media Grabber</modelDescription>
/// <modelName>Plex Media Grabber</modelName>
/// <modelNumber>1</modelNumber>
/// <modelURL>https://plex.tv</modelURL>
/// <UDN>uuid:42fde8e4-93b6-41e5-8a63-12d848655811</UDN>
/// <serviceList>
/// <service>
/// <URLBase>http://10.0.0.5:8088</URLBase>
/// <serviceType>urn:plex-tv:service:MediaGrabber:1</serviceType>
/// <serviceId>urn:plex-tv:serviceId:MediaGrabber</serviceId>
/// </service>
/// </serviceList>
/// </device>
/// </root>
/// ```
///
/// - UDN: (string) A UUID for the device. This should be unique across models of a device at minimum.
/// - URLBase: (string) The base HTTP URL for the device from which all of the other endpoints are hosted.
/// ///
///
public class Devices: IDevices { public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; private const string _sdkVersion = "0.18.0"; private const string _sdkGenVersion = "2.730.5"; private const string _openapiDocVersion = "1.1.1"; public Devices(SDKConfig config) { SDKConfiguration = config; } public async Task GetAvailableGrabbersAsync(GetAvailableGrabbersRequest? request = null) { request.Accepts ??= SDKConfiguration.Accepts; request.ClientIdentifier ??= SDKConfiguration.ClientIdentifier; request.Product ??= SDKConfiguration.Product; request.Version ??= SDKConfiguration.Version; request.Platform ??= SDKConfiguration.Platform; request.PlatformVersion ??= SDKConfiguration.PlatformVersion; request.Device ??= SDKConfiguration.Device; request.Model ??= SDKConfiguration.Model; request.DeviceVendor ??= SDKConfiguration.DeviceVendor; request.DeviceName ??= SDKConfiguration.DeviceName; request.Marketplace ??= SDKConfiguration.Marketplace; string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/media/grabbers", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent); HeaderSerializer.PopulateHeaders(ref httpRequest, request); if (SDKConfiguration.SecuritySource != null) { httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest); } var hookCtx = new HookContext(SDKConfiguration, baseUrl, "getAvailableGrabbers", null, SDKConfiguration.SecuritySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await SDKConfiguration.Client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode >= 400 && _statusCode < 500 || _statusCode >= 500 && _statusCode < 600) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); if (_httpResponse != null) { httpResponse = _httpResponse; } } } catch (Exception error) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); if (_httpResponse != null) { httpResponse = _httpResponse; } else { throw; } } httpResponse = await this.SDKConfiguration.Hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; if(responseStatusCode == 200) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var httpResponseBody = await httpResponse.Content.ReadAsStringAsync(); GetAvailableGrabbersResponseBody obj; try { obj = ResponseBodyDeserializer.DeserializeNotNull(httpResponseBody, NullValueHandling.Include); } catch (Exception ex) { throw new ResponseValidationException("Failed to deserialize response body into GetAvailableGrabbersResponseBody.", httpResponse, httpResponseBody, ex); } var response = new GetAvailableGrabbersResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.Object = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } throw new Models.Errors.SDKException("Unknown status code received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } public async Task ListDevicesAsync() { string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/media/grabbers/devices"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent); if (SDKConfiguration.SecuritySource != null) { httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest); } var hookCtx = new HookContext(SDKConfiguration, baseUrl, "listDevices", null, SDKConfiguration.SecuritySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await SDKConfiguration.Client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode >= 400 && _statusCode < 500 || _statusCode >= 500 && _statusCode < 600) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); if (_httpResponse != null) { httpResponse = _httpResponse; } } } catch (Exception error) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); if (_httpResponse != null) { httpResponse = _httpResponse; } else { throw; } } httpResponse = await this.SDKConfiguration.Hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; if(responseStatusCode == 200) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var httpResponseBody = await httpResponse.Content.ReadAsStringAsync(); MediaContainerWithDevice obj; try { obj = ResponseBodyDeserializer.DeserializeNotNull(httpResponseBody, NullValueHandling.Ignore); } catch (Exception ex) { throw new ResponseValidationException("Failed to deserialize response body into MediaContainerWithDevice.", httpResponse, httpResponseBody, ex); } var response = new ListDevicesResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.MediaContainerWithDevice = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } throw new Models.Errors.SDKException("Unknown status code received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } public async Task AddDeviceAsync(AddDeviceRequest? request = null) { request.Accepts ??= SDKConfiguration.Accepts; request.ClientIdentifier ??= SDKConfiguration.ClientIdentifier; request.Product ??= SDKConfiguration.Product; request.Version ??= SDKConfiguration.Version; request.Platform ??= SDKConfiguration.Platform; request.PlatformVersion ??= SDKConfiguration.PlatformVersion; request.Device ??= SDKConfiguration.Device; request.Model ??= SDKConfiguration.Model; request.DeviceVendor ??= SDKConfiguration.DeviceVendor; request.DeviceName ??= SDKConfiguration.DeviceName; request.Marketplace ??= SDKConfiguration.Marketplace; string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/media/grabbers/devices", request); var httpRequest = new HttpRequestMessage(HttpMethod.Post, urlString); httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent); HeaderSerializer.PopulateHeaders(ref httpRequest, request); if (SDKConfiguration.SecuritySource != null) { httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest); } var hookCtx = new HookContext(SDKConfiguration, baseUrl, "addDevice", null, SDKConfiguration.SecuritySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await SDKConfiguration.Client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode == 400 || _statusCode >= 400 && _statusCode < 500 || _statusCode >= 500 && _statusCode < 600) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); if (_httpResponse != null) { httpResponse = _httpResponse; } } } catch (Exception error) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); if (_httpResponse != null) { httpResponse = _httpResponse; } else { throw; } } httpResponse = await this.SDKConfiguration.Hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; if(responseStatusCode == 200) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var httpResponseBody = await httpResponse.Content.ReadAsStringAsync(); MediaContainerWithDevice obj; try { obj = ResponseBodyDeserializer.DeserializeNotNull(httpResponseBody, NullValueHandling.Include); } catch (Exception ex) { throw new ResponseValidationException("Failed to deserialize response body into MediaContainerWithDevice.", httpResponse, httpResponseBody, ex); } var response = new AddDeviceResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.MediaContainerWithDevice = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode == 400 || responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } throw new Models.Errors.SDKException("Unknown status code received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } public async Task DiscoverDevicesAsync() { string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/media/grabbers/devices/discover"; var httpRequest = new HttpRequestMessage(HttpMethod.Post, urlString); httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent); if (SDKConfiguration.SecuritySource != null) { httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest); } var hookCtx = new HookContext(SDKConfiguration, baseUrl, "discoverDevices", null, SDKConfiguration.SecuritySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await SDKConfiguration.Client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode >= 400 && _statusCode < 500 || _statusCode >= 500 && _statusCode < 600) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); if (_httpResponse != null) { httpResponse = _httpResponse; } } } catch (Exception error) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); if (_httpResponse != null) { httpResponse = _httpResponse; } else { throw; } } httpResponse = await this.SDKConfiguration.Hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; if(responseStatusCode == 200) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var httpResponseBody = await httpResponse.Content.ReadAsStringAsync(); MediaContainerWithDevice obj; try { obj = ResponseBodyDeserializer.DeserializeNotNull(httpResponseBody, NullValueHandling.Ignore); } catch (Exception ex) { throw new ResponseValidationException("Failed to deserialize response body into MediaContainerWithDevice.", httpResponse, httpResponseBody, ex); } var response = new DiscoverDevicesResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.MediaContainerWithDevice = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } throw new Models.Errors.SDKException("Unknown status code received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } public async Task RemoveDeviceAsync(RemoveDeviceRequest request) { if (request == null) { request = new RemoveDeviceRequest(); } request.Accepts ??= SDKConfiguration.Accepts; request.ClientIdentifier ??= SDKConfiguration.ClientIdentifier; request.Product ??= SDKConfiguration.Product; request.Version ??= SDKConfiguration.Version; request.Platform ??= SDKConfiguration.Platform; request.PlatformVersion ??= SDKConfiguration.PlatformVersion; request.Device ??= SDKConfiguration.Device; request.Model ??= SDKConfiguration.Model; request.DeviceVendor ??= SDKConfiguration.DeviceVendor; request.DeviceName ??= SDKConfiguration.DeviceName; request.Marketplace ??= SDKConfiguration.Marketplace; string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/media/grabbers/devices/{deviceId}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Delete, urlString); httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent); HeaderSerializer.PopulateHeaders(ref httpRequest, request); if (SDKConfiguration.SecuritySource != null) { httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest); } var hookCtx = new HookContext(SDKConfiguration, baseUrl, "removeDevice", null, SDKConfiguration.SecuritySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await SDKConfiguration.Client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode == 404 || _statusCode >= 400 && _statusCode < 500 || _statusCode >= 500 && _statusCode < 600) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); if (_httpResponse != null) { httpResponse = _httpResponse; } } } catch (Exception error) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); if (_httpResponse != null) { httpResponse = _httpResponse; } else { throw; } } httpResponse = await this.SDKConfiguration.Hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; if(responseStatusCode == 200) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var httpResponseBody = await httpResponse.Content.ReadAsStringAsync(); RemoveDeviceResponseBody obj; try { obj = ResponseBodyDeserializer.DeserializeNotNull(httpResponseBody, NullValueHandling.Ignore); } catch (Exception ex) { throw new ResponseValidationException("Failed to deserialize response body into RemoveDeviceResponseBody.", httpResponse, httpResponseBody, ex); } var response = new RemoveDeviceResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.Object = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode == 404 || responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } throw new Models.Errors.SDKException("Unknown status code received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } public async Task GetDeviceDetailsAsync(GetDeviceDetailsRequest request) { if (request == null) { request = new GetDeviceDetailsRequest(); } request.Accepts ??= SDKConfiguration.Accepts; request.ClientIdentifier ??= SDKConfiguration.ClientIdentifier; request.Product ??= SDKConfiguration.Product; request.Version ??= SDKConfiguration.Version; request.Platform ??= SDKConfiguration.Platform; request.PlatformVersion ??= SDKConfiguration.PlatformVersion; request.Device ??= SDKConfiguration.Device; request.Model ??= SDKConfiguration.Model; request.DeviceVendor ??= SDKConfiguration.DeviceVendor; request.DeviceName ??= SDKConfiguration.DeviceName; request.Marketplace ??= SDKConfiguration.Marketplace; string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/media/grabbers/devices/{deviceId}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent); HeaderSerializer.PopulateHeaders(ref httpRequest, request); if (SDKConfiguration.SecuritySource != null) { httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest); } var hookCtx = new HookContext(SDKConfiguration, baseUrl, "getDeviceDetails", null, SDKConfiguration.SecuritySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await SDKConfiguration.Client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode == 404 || _statusCode >= 400 && _statusCode < 500 || _statusCode >= 500 && _statusCode < 600) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); if (_httpResponse != null) { httpResponse = _httpResponse; } } } catch (Exception error) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); if (_httpResponse != null) { httpResponse = _httpResponse; } else { throw; } } httpResponse = await this.SDKConfiguration.Hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; if(responseStatusCode == 200) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var httpResponseBody = await httpResponse.Content.ReadAsStringAsync(); MediaContainerWithDevice obj; try { obj = ResponseBodyDeserializer.DeserializeNotNull(httpResponseBody, NullValueHandling.Ignore); } catch (Exception ex) { throw new ResponseValidationException("Failed to deserialize response body into MediaContainerWithDevice.", httpResponse, httpResponseBody, ex); } var response = new GetDeviceDetailsResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.MediaContainerWithDevice = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode == 404 || responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } throw new Models.Errors.SDKException("Unknown status code received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } public async Task ModifyDeviceAsync(ModifyDeviceRequest request) { if (request == null) { request = new ModifyDeviceRequest(); } request.Accepts ??= SDKConfiguration.Accepts; request.ClientIdentifier ??= SDKConfiguration.ClientIdentifier; request.Product ??= SDKConfiguration.Product; request.Version ??= SDKConfiguration.Version; request.Platform ??= SDKConfiguration.Platform; request.PlatformVersion ??= SDKConfiguration.PlatformVersion; request.Device ??= SDKConfiguration.Device; request.Model ??= SDKConfiguration.Model; request.DeviceVendor ??= SDKConfiguration.DeviceVendor; request.DeviceName ??= SDKConfiguration.DeviceName; request.Marketplace ??= SDKConfiguration.Marketplace; string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/media/grabbers/devices/{deviceId}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Put, urlString); httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent); HeaderSerializer.PopulateHeaders(ref httpRequest, request); if (SDKConfiguration.SecuritySource != null) { httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest); } var hookCtx = new HookContext(SDKConfiguration, baseUrl, "modifyDevice", null, SDKConfiguration.SecuritySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await SDKConfiguration.Client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode == 404 || _statusCode >= 400 && _statusCode < 500 || _statusCode >= 500 && _statusCode < 600) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); if (_httpResponse != null) { httpResponse = _httpResponse; } } } catch (Exception error) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); if (_httpResponse != null) { httpResponse = _httpResponse; } else { throw; } } httpResponse = await this.SDKConfiguration.Hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; if(responseStatusCode == 200) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var httpResponseBody = await httpResponse.Content.ReadAsStringAsync(); ModifyDeviceResponseBody obj; try { obj = ResponseBodyDeserializer.DeserializeNotNull(httpResponseBody, NullValueHandling.Ignore); } catch (Exception ex) { throw new ResponseValidationException("Failed to deserialize response body into ModifyDeviceResponseBody.", httpResponse, httpResponseBody, ex); } var response = new ModifyDeviceResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.Object = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode == 404 || responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } throw new Models.Errors.SDKException("Unknown status code received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } public async Task SetChannelmapAsync(SetChannelmapRequest request) { if (request == null) { request = new SetChannelmapRequest(); } request.Accepts ??= SDKConfiguration.Accepts; request.ClientIdentifier ??= SDKConfiguration.ClientIdentifier; request.Product ??= SDKConfiguration.Product; request.Version ??= SDKConfiguration.Version; request.Platform ??= SDKConfiguration.Platform; request.PlatformVersion ??= SDKConfiguration.PlatformVersion; request.Device ??= SDKConfiguration.Device; request.Model ??= SDKConfiguration.Model; request.DeviceVendor ??= SDKConfiguration.DeviceVendor; request.DeviceName ??= SDKConfiguration.DeviceName; request.Marketplace ??= SDKConfiguration.Marketplace; string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/media/grabbers/devices/{deviceId}/channelmap", request); var httpRequest = new HttpRequestMessage(HttpMethod.Put, urlString); httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent); HeaderSerializer.PopulateHeaders(ref httpRequest, request); if (SDKConfiguration.SecuritySource != null) { httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest); } var hookCtx = new HookContext(SDKConfiguration, baseUrl, "setChannelmap", null, SDKConfiguration.SecuritySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await SDKConfiguration.Client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode >= 400 && _statusCode < 500 || _statusCode >= 500 && _statusCode < 600) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); if (_httpResponse != null) { httpResponse = _httpResponse; } } } catch (Exception error) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); if (_httpResponse != null) { httpResponse = _httpResponse; } else { throw; } } httpResponse = await this.SDKConfiguration.Hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; if(responseStatusCode == 200) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var httpResponseBody = await httpResponse.Content.ReadAsStringAsync(); MediaContainerWithDevice obj; try { obj = ResponseBodyDeserializer.DeserializeNotNull(httpResponseBody, NullValueHandling.Ignore); } catch (Exception ex) { throw new ResponseValidationException("Failed to deserialize response body into MediaContainerWithDevice.", httpResponse, httpResponseBody, ex); } var response = new SetChannelmapResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.MediaContainerWithDevice = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } throw new Models.Errors.SDKException("Unknown status code received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } public async Task GetDevicesChannelsAsync(GetDevicesChannelsRequest request) { if (request == null) { request = new GetDevicesChannelsRequest(); } request.Accepts ??= SDKConfiguration.Accepts; request.ClientIdentifier ??= SDKConfiguration.ClientIdentifier; request.Product ??= SDKConfiguration.Product; request.Version ??= SDKConfiguration.Version; request.Platform ??= SDKConfiguration.Platform; request.PlatformVersion ??= SDKConfiguration.PlatformVersion; request.Device ??= SDKConfiguration.Device; request.Model ??= SDKConfiguration.Model; request.DeviceVendor ??= SDKConfiguration.DeviceVendor; request.DeviceName ??= SDKConfiguration.DeviceName; request.Marketplace ??= SDKConfiguration.Marketplace; string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/media/grabbers/devices/{deviceId}/channels", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent); HeaderSerializer.PopulateHeaders(ref httpRequest, request); if (SDKConfiguration.SecuritySource != null) { httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest); } var hookCtx = new HookContext(SDKConfiguration, baseUrl, "getDevicesChannels", null, SDKConfiguration.SecuritySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await SDKConfiguration.Client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode == 404 || _statusCode >= 400 && _statusCode < 500 || _statusCode >= 500 && _statusCode < 600) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); if (_httpResponse != null) { httpResponse = _httpResponse; } } } catch (Exception error) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); if (_httpResponse != null) { httpResponse = _httpResponse; } else { throw; } } httpResponse = await this.SDKConfiguration.Hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; if(responseStatusCode == 200) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var httpResponseBody = await httpResponse.Content.ReadAsStringAsync(); GetDevicesChannelsResponseBody obj; try { obj = ResponseBodyDeserializer.DeserializeNotNull(httpResponseBody, NullValueHandling.Ignore); } catch (Exception ex) { throw new ResponseValidationException("Failed to deserialize response body into GetDevicesChannelsResponseBody.", httpResponse, httpResponseBody, ex); } var response = new GetDevicesChannelsResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.Object = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode == 404 || responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } throw new Models.Errors.SDKException("Unknown status code received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } public async Task SetDevicePreferencesAsync(SetDevicePreferencesRequest request) { if (request == null) { request = new SetDevicePreferencesRequest(); } request.Accepts ??= SDKConfiguration.Accepts; request.ClientIdentifier ??= SDKConfiguration.ClientIdentifier; request.Product ??= SDKConfiguration.Product; request.Version ??= SDKConfiguration.Version; request.Platform ??= SDKConfiguration.Platform; request.PlatformVersion ??= SDKConfiguration.PlatformVersion; request.Device ??= SDKConfiguration.Device; request.Model ??= SDKConfiguration.Model; request.DeviceVendor ??= SDKConfiguration.DeviceVendor; request.DeviceName ??= SDKConfiguration.DeviceName; request.Marketplace ??= SDKConfiguration.Marketplace; string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/media/grabbers/devices/{deviceId}/prefs", request); var httpRequest = new HttpRequestMessage(HttpMethod.Put, urlString); httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent); HeaderSerializer.PopulateHeaders(ref httpRequest, request); if (SDKConfiguration.SecuritySource != null) { httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest); } var hookCtx = new HookContext(SDKConfiguration, baseUrl, "setDevicePreferences", null, SDKConfiguration.SecuritySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await SDKConfiguration.Client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode >= 400 && _statusCode < 500 || _statusCode >= 500 && _statusCode < 600) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); if (_httpResponse != null) { httpResponse = _httpResponse; } } } catch (Exception error) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); if (_httpResponse != null) { httpResponse = _httpResponse; } else { throw; } } httpResponse = await this.SDKConfiguration.Hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; if(responseStatusCode == 200) { return new SetDevicePreferencesResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; } else if(responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } throw new Models.Errors.SDKException("Unknown status code received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } public async Task StopScanAsync(StopScanRequest request) { if (request == null) { request = new StopScanRequest(); } request.Accepts ??= SDKConfiguration.Accepts; request.ClientIdentifier ??= SDKConfiguration.ClientIdentifier; request.Product ??= SDKConfiguration.Product; request.Version ??= SDKConfiguration.Version; request.Platform ??= SDKConfiguration.Platform; request.PlatformVersion ??= SDKConfiguration.PlatformVersion; request.Device ??= SDKConfiguration.Device; request.Model ??= SDKConfiguration.Model; request.DeviceVendor ??= SDKConfiguration.DeviceVendor; request.DeviceName ??= SDKConfiguration.DeviceName; request.Marketplace ??= SDKConfiguration.Marketplace; string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/media/grabbers/devices/{deviceId}/scan", request); var httpRequest = new HttpRequestMessage(HttpMethod.Delete, urlString); httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent); HeaderSerializer.PopulateHeaders(ref httpRequest, request); if (SDKConfiguration.SecuritySource != null) { httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest); } var hookCtx = new HookContext(SDKConfiguration, baseUrl, "stopScan", null, SDKConfiguration.SecuritySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await SDKConfiguration.Client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode >= 400 && _statusCode < 500 || _statusCode >= 500 && _statusCode < 600) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); if (_httpResponse != null) { httpResponse = _httpResponse; } } } catch (Exception error) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); if (_httpResponse != null) { httpResponse = _httpResponse; } else { throw; } } httpResponse = await this.SDKConfiguration.Hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; if(responseStatusCode == 200) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var httpResponseBody = await httpResponse.Content.ReadAsStringAsync(); MediaContainerWithDevice obj; try { obj = ResponseBodyDeserializer.DeserializeNotNull(httpResponseBody, NullValueHandling.Ignore); } catch (Exception ex) { throw new ResponseValidationException("Failed to deserialize response body into MediaContainerWithDevice.", httpResponse, httpResponseBody, ex); } var response = new StopScanResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.MediaContainerWithDevice = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } throw new Models.Errors.SDKException("Unknown status code received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } public async Task ScanAsync(ScanRequest request) { if (request == null) { request = new ScanRequest(); } request.Accepts ??= SDKConfiguration.Accepts; request.ClientIdentifier ??= SDKConfiguration.ClientIdentifier; request.Product ??= SDKConfiguration.Product; request.Version ??= SDKConfiguration.Version; request.Platform ??= SDKConfiguration.Platform; request.PlatformVersion ??= SDKConfiguration.PlatformVersion; request.Device ??= SDKConfiguration.Device; request.Model ??= SDKConfiguration.Model; request.DeviceVendor ??= SDKConfiguration.DeviceVendor; request.DeviceName ??= SDKConfiguration.DeviceName; request.Marketplace ??= SDKConfiguration.Marketplace; string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/media/grabbers/devices/{deviceId}/scan", request); var httpRequest = new HttpRequestMessage(HttpMethod.Post, urlString); httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent); HeaderSerializer.PopulateHeaders(ref httpRequest, request); if (SDKConfiguration.SecuritySource != null) { httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest); } var hookCtx = new HookContext(SDKConfiguration, baseUrl, "scan", null, SDKConfiguration.SecuritySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await SDKConfiguration.Client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode >= 400 && _statusCode < 500 || _statusCode >= 500 && _statusCode < 600) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); if (_httpResponse != null) { httpResponse = _httpResponse; } } } catch (Exception error) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); if (_httpResponse != null) { httpResponse = _httpResponse; } else { throw; } } httpResponse = await this.SDKConfiguration.Hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; if(responseStatusCode == 200) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var httpResponseBody = await httpResponse.Content.ReadAsStringAsync(); MediaContainerWithDevice obj; try { obj = ResponseBodyDeserializer.DeserializeNotNull(httpResponseBody, NullValueHandling.Ignore); } catch (Exception ex) { throw new ResponseValidationException("Failed to deserialize response body into MediaContainerWithDevice.", httpResponse, httpResponseBody, ex); } var response = new ScanResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.MediaContainerWithDevice = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } throw new Models.Errors.SDKException("Unknown status code received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } public async Task GetThumbAsync(GetThumbRequest request) { if (request == null) { request = new GetThumbRequest(); } request.Accepts ??= SDKConfiguration.Accepts; request.ClientIdentifier ??= SDKConfiguration.ClientIdentifier; request.Product ??= SDKConfiguration.Product; request.Version ??= SDKConfiguration.Version; request.Platform ??= SDKConfiguration.Platform; request.PlatformVersion ??= SDKConfiguration.PlatformVersion; request.Device ??= SDKConfiguration.Device; request.Model ??= SDKConfiguration.Model; request.DeviceVendor ??= SDKConfiguration.DeviceVendor; request.DeviceName ??= SDKConfiguration.DeviceName; request.Marketplace ??= SDKConfiguration.Marketplace; string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = URLBuilder.Build(baseUrl, "/media/grabbers/devices/{deviceId}/thumb/{version}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", SDKConfiguration.UserAgent); HeaderSerializer.PopulateHeaders(ref httpRequest, request); if (SDKConfiguration.SecuritySource != null) { httpRequest = new SecurityMetadata(SDKConfiguration.SecuritySource).Apply(httpRequest); } var hookCtx = new HookContext(SDKConfiguration, baseUrl, "getThumb", null, SDKConfiguration.SecuritySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await SDKConfiguration.Client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode == 404 || _statusCode >= 400 && _statusCode < 500 || _statusCode >= 500 && _statusCode < 600) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), httpResponse, null); if (_httpResponse != null) { httpResponse = _httpResponse; } } } catch (Exception error) { var _httpResponse = await this.SDKConfiguration.Hooks.AfterErrorAsync(new AfterErrorContext(hookCtx), null, error); if (_httpResponse != null) { httpResponse = _httpResponse; } else { throw; } } httpResponse = await this.SDKConfiguration.Hooks.AfterSuccessAsync(new AfterSuccessContext(hookCtx), httpResponse); var contentType = httpResponse.Content.Headers.ContentType?.MediaType; int responseStatusCode = (int)httpResponse.StatusCode; if(responseStatusCode == 200) { return new GetThumbResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; } else if(responseStatusCode == 301) { return new GetThumbResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; } else if(responseStatusCode == 404 || responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } throw new Models.Errors.SDKException("Unknown status code received", httpResponse, await httpResponse.Content.ReadAsStringAsync()); } } }