//------------------------------------------------------------------------------ // // 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; /// /// API Calls that perform operations directly against https://Plex.tv
/// /// /// /// ///
public interface IPlex { /// /// Get Companions Data /// /// /// Get Companions Data /// /// Task GetCompanionsDataAsync(string? serverUrl = null); /// /// Get list of friends of the user logged in /// /// /// Get friends of provided auth token. /// /// Task GetUserFriendsAsync(string? serverUrl = null); /// /// Get Geo Data /// /// /// Returns the geolocation and locale data of the caller /// /// Task GetGeoDataAsync(string? serverUrl = null); /// /// Get Plex Home Data /// /// /// Retrieves the home data for the authenticated user, including details like home ID, name, guest access information, and subscription status. /// /// Task GetHomeDataAsync(); /// /// Get Server Resources /// /// /// Get Plex server access tokens and server connections /// /// Task GetServerResourcesAsync(string clientID, IncludeHttps? includeHttps = LukeHagar.PlexAPI.SDK.Models.Requests.IncludeHttps.Disable, IncludeRelay? includeRelay = LukeHagar.PlexAPI.SDK.Models.Requests.IncludeRelay.Disable, IncludeIPv6? includeIPv6 = LukeHagar.PlexAPI.SDK.Models.Requests.IncludeIPv6.Disable, string? serverUrl = null); /// /// Get a Pin /// /// /// Retrieve a Pin ID from Plex.tv to use for authentication flows /// /// Task GetPinAsync(GetPinRequest request, string? serverUrl = null); /// /// Get Access Token by PinId /// /// /// Retrieve an Access Token from Plex.tv after the Pin has been authenticated /// /// Task GetTokenByPinIdAsync(GetTokenByPinIdRequest request, string? serverUrl = null); } /// /// API Calls that perform operations directly against https://Plex.tv
/// /// /// /// ///
public class Plex: IPlex { /// /// List of server URLs available for the getCompanionsData operation. /// public static readonly string[] GetCompanionsDataServerList = { "https://plex.tv/api/v2", }; /// /// List of server URLs available for the getUserFriends operation. /// public static readonly string[] GetUserFriendsServerList = { "https://plex.tv/api/v2", }; /// /// List of server URLs available for the getGeoData operation. /// public static readonly string[] GetGeoDataServerList = { "https://plex.tv/api/v2", }; /// /// List of server URLs available for the get-server-resources operation. /// public static readonly string[] GetServerResourcesServerList = { "https://plex.tv/api/v2", }; /// /// List of server URLs available for the getPin operation. /// public static readonly string[] GetPinServerList = { "https://plex.tv/api/v2", }; /// /// List of server URLs available for the getTokenByPinId operation. /// public static readonly string[] GetTokenByPinIdServerList = { "https://plex.tv/api/v2", }; public SDKConfig SDKConfiguration { get; private set; } private const string _language = "csharp"; private const string _sdkVersion = "0.14.7"; private const string _sdkGenVersion = "2.566.5"; private const string _openapiDocVersion = "0.0.3"; private const string _userAgent = "speakeasy-sdk/csharp 0.14.7 2.566.5 0.0.3 LukeHagar.PlexAPI.SDK"; private string _serverUrl = ""; private ISpeakeasyHttpClient _client; private Func? _securitySource; public Plex(ISpeakeasyHttpClient client, Func? securitySource, string serverUrl, SDKConfig config) { _client = client; _securitySource = securitySource; _serverUrl = serverUrl; SDKConfiguration = config; } public async Task GetCompanionsDataAsync(string? serverUrl = null) { string baseUrl = Utilities.TemplateUrl(GetCompanionsDataServerList[0], new Dictionary(){ }); if (serverUrl != null) { baseUrl = serverUrl; } var urlString = baseUrl + "/companions"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); if (_securitySource != null) { httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } var hookCtx = new HookContext(baseUrl, "getCompanionsData", new List { }, _securitySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await _client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode == 400 || _statusCode == 401 || _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 obj = ResponseBodyDeserializer.Deserialize>(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); var response = new GetCompanionsDataResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.ResponseBodies = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 400) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 401) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task GetUserFriendsAsync(string? serverUrl = null) { string baseUrl = Utilities.TemplateUrl(GetUserFriendsServerList[0], new Dictionary(){ }); if (serverUrl != null) { baseUrl = serverUrl; } var urlString = baseUrl + "/friends"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); if (_securitySource != null) { httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } var hookCtx = new HookContext(baseUrl, "getUserFriends", new List { }, _securitySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await _client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode == 400 || _statusCode == 401 || _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 obj = ResponseBodyDeserializer.Deserialize>(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); var response = new GetUserFriendsResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.Friends = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 400) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 401) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task GetGeoDataAsync(string? serverUrl = null) { string baseUrl = Utilities.TemplateUrl(GetGeoDataServerList[0], new Dictionary(){ }); if (serverUrl != null) { baseUrl = serverUrl; } var urlString = baseUrl + "/geoip"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); var hookCtx = new HookContext(baseUrl, "getGeoData", new List { }, null); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await _client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode == 400 || _statusCode == 401 || _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 obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); var response = new GetGeoDataResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.GeoData = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 400) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 401) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task GetHomeDataAsync() { string baseUrl = this.SDKConfiguration.GetTemplatedServerUrl(); var urlString = baseUrl + "/home"; var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); if (_securitySource != null) { httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } var hookCtx = new HookContext(baseUrl, "getHomeData", new List { }, _securitySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await _client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode == 400 || _statusCode == 401 || _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 obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); var response = new GetHomeDataResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.Object = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 400) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 401) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task GetServerResourcesAsync(string clientID, IncludeHttps? includeHttps = LukeHagar.PlexAPI.SDK.Models.Requests.IncludeHttps.Disable, IncludeRelay? includeRelay = LukeHagar.PlexAPI.SDK.Models.Requests.IncludeRelay.Disable, IncludeIPv6? includeIPv6 = LukeHagar.PlexAPI.SDK.Models.Requests.IncludeIPv6.Disable, string? serverUrl = null) { var request = new GetServerResourcesRequest() { ClientID = clientID, IncludeHttps = includeHttps, IncludeRelay = includeRelay, IncludeIPv6 = includeIPv6, }; string baseUrl = Utilities.TemplateUrl(GetServerResourcesServerList[0], new Dictionary(){ }); if (serverUrl != null) { baseUrl = serverUrl; } var urlString = URLBuilder.Build(baseUrl, "/resources", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); HeaderSerializer.PopulateHeaders(ref httpRequest, request); if (_securitySource != null) { httpRequest = new SecurityMetadata(_securitySource).Apply(httpRequest); } var hookCtx = new HookContext(baseUrl, "get-server-resources", new List { }, _securitySource); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await _client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode == 400 || _statusCode == 401 || _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 obj = ResponseBodyDeserializer.Deserialize>(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); var response = new GetServerResourcesResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.PlexDevices = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 400) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 401) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task GetPinAsync(GetPinRequest request, string? serverUrl = null) { string baseUrl = Utilities.TemplateUrl(GetPinServerList[0], new Dictionary(){ }); if (serverUrl != null) { baseUrl = serverUrl; } var urlString = URLBuilder.Build(baseUrl, "/pins", request); var httpRequest = new HttpRequestMessage(HttpMethod.Post, urlString); httpRequest.Headers.Add("user-agent", _userAgent); HeaderSerializer.PopulateHeaders(ref httpRequest, request); var hookCtx = new HookContext(baseUrl, "getPin", new List { }, null); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await _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 == 201) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); var response = new GetPinResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.AuthPinContainer = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 400) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } public async Task GetTokenByPinIdAsync(GetTokenByPinIdRequest request, string? serverUrl = null) { string baseUrl = Utilities.TemplateUrl(GetTokenByPinIdServerList[0], new Dictionary(){ }); if (serverUrl != null) { baseUrl = serverUrl; } var urlString = URLBuilder.Build(baseUrl, "/pins/{pinID}", request); var httpRequest = new HttpRequestMessage(HttpMethod.Get, urlString); httpRequest.Headers.Add("user-agent", _userAgent); HeaderSerializer.PopulateHeaders(ref httpRequest, request); var hookCtx = new HookContext(baseUrl, "getTokenByPinId", new List { }, null); httpRequest = await this.SDKConfiguration.Hooks.BeforeRequestAsync(new BeforeRequestContext(hookCtx), httpRequest); HttpResponseMessage httpResponse; try { httpResponse = await _client.SendAsync(httpRequest); int _statusCode = (int)httpResponse.StatusCode; if (_statusCode == 400 || _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 obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); var response = new GetTokenByPinIdResponse() { StatusCode = responseStatusCode, ContentType = contentType, RawResponse = httpResponse }; response.AuthPinContainer = obj; return response; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 400) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode == 404) { if(Utilities.IsContentTypeMatch("application/json", contentType)) { var obj = ResponseBodyDeserializer.Deserialize(await httpResponse.Content.ReadAsStringAsync(), NullValueHandling.Ignore); obj!.RawResponse = httpResponse; throw obj!; } throw new Models.Errors.SDKException("Unknown content type received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 400 && responseStatusCode < 500) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } else if(responseStatusCode >= 500 && responseStatusCode < 600) { throw new Models.Errors.SDKException("API error occurred", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } throw new Models.Errors.SDKException("Unknown status code received", responseStatusCode, await httpResponse.Content.ReadAsStringAsync(), httpResponse); } } }