Bumped package version to 1.5.9, exposed a parameter in the init method to allow a custom message handler to be used with the client for C#.

This commit is contained in:
2023-06-01 06:29:39 -07:00
parent 22ff3c1312
commit efd744974d
4 changed files with 129 additions and 40 deletions

View File

@ -1,3 +1,4 @@
//Generated using MontoyaTech.Rest.Net
using System;
using System.Net;
using System.Net.Http;
@ -9,7 +10,7 @@ public class Client
public CookieContainer CookieContainer;
public HttpClientHandler ClientHandler;
public HttpMessageHandler MessageHandler;
public HttpClient HttpClient;
@ -19,7 +20,7 @@ public class Client
public StreamApi Stream;
public Client(string baseUrl)
public Client(string baseUrl, HttpMessageHandler handler = null)
{
if (string.IsNullOrWhiteSpace(baseUrl))
throw new ArgumentException("baseUrl must not be null or whitespace.");
@ -31,15 +32,20 @@ public class Client
this.CookieContainer = new CookieContainer();
this.ClientHandler = new HttpClientHandler()
if (handler == null)
{
AllowAutoRedirect = true,
UseCookies = true,
CookieContainer = this.CookieContainer,
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
};
handler = new HttpClientHandler()
{
AllowAutoRedirect = true,
UseCookies = true,
CookieContainer = this.CookieContainer,
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
};
}
this.HttpClient = new HttpClient(this.ClientHandler);
this.MessageHandler = handler;
this.HttpClient = new HttpClient(handler);
this.HttpClient.DefaultRequestHeaders.Add("Accept", "*/*");
@ -67,7 +73,7 @@ public class Client
{
var message = new HttpRequestMessage(HttpMethod.Get, $"{this.Client.BaseUrl}/status");
var response = this.Client.HttpClient.Send(message);
var response = this.Client.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
@ -88,7 +94,7 @@ public class Client
{
var message = new HttpRequestMessage(HttpMethod.Post, $"{this.Client.BaseUrl}/add/{a}/{b}");
var response = this.Client.HttpClient.Send(message);
var response = this.Client.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
@ -109,7 +115,7 @@ public class Client
{
var message = new HttpRequestMessage(HttpMethod.Get, $"{this.Client.BaseUrl}/compress");
var response = this.Client.HttpClient.Send(message);
var response = this.Client.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
@ -130,7 +136,7 @@ public class Client
{
var message = new HttpRequestMessage(HttpMethod.Get, $"{this.Client.BaseUrl}/file/compress");
var response = this.Client.HttpClient.Send(message);
var response = this.Client.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
@ -161,7 +167,7 @@ public class Client
{
var message = new HttpRequestMessage(HttpMethod.Get, $"{this.Client.BaseUrl}/auth/{name}");
var response = this.Client.HttpClient.Send(message);
var response = this.Client.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
@ -184,7 +190,7 @@ public class Client
message.Content = new StringContent(JsonConvert.SerializeObject(request));
var response = this.Client.HttpClient.Send(message);
var response = this.Client.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (!response.IsSuccessStatusCode)
throw new Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
@ -194,7 +200,7 @@ public class Client
{
var message = new HttpRequestMessage(HttpMethod.Get, $"{this.Client.BaseUrl}/auth");
var response = this.Client.HttpClient.Send(message);
var response = this.Client.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
@ -215,7 +221,7 @@ public class Client
{
var message = new HttpRequestMessage(HttpMethod.Get, $"{this.Client.BaseUrl}/auth/role");
var response = this.Client.HttpClient.Send(message);
var response = this.Client.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
@ -250,7 +256,7 @@ public class Client
message.Content = new StreamContent(request);
var response = this.Client.HttpClient.Send(message);
var response = this.Client.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (!response.IsSuccessStatusCode)
throw new Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
@ -260,15 +266,13 @@ public class Client
{
var message = new HttpRequestMessage(HttpMethod.Get, $"{this.Client.BaseUrl}/download");
var response = this.Client.HttpClient.Send(message);
var response = this.Client.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead);
if (response.IsSuccessStatusCode)
{
var stream = new System.IO.MemoryStream();
response.Content.ReadAsStream().CopyTo(stream);
stream.Seek(0, System.IO.SeekOrigin.Begin);
response.Content.CopyToAsync(stream).GetAwaiter().GetResult();
return stream;
}
@ -282,6 +286,18 @@ public class Client
public class IncludedType
{
public int Test;
public IncludedType() { }
public IncludedType(IncludedType instance)
{
this.Test = instance.Test;
}
public IncludedType(int Test = 0)
{
this.Test = Test;
}
}
public class UserDto : BaseUser
@ -292,23 +308,79 @@ public class Client
public System.Collections.Generic.List<string> List;
public System.String[] Array;
public ulong Property { get; set; }
public UserDto() { }
public UserDto(UserDto instance)
{
this.MachineType = instance.MachineType;
this.Name = instance.Name;
this.List = instance.List;
this.Array = instance.Array;
this.Property = instance.Property;
}
public UserDto(System.PlatformID MachineType = 0, string Name = null, System.Collections.Generic.List<string> List = null, System.String[] Array = null, ulong Property = 0)
{
this.MachineType = MachineType;
this.Name = Name;
this.List = List;
this.Array = Array;
this.Property = Property;
}
}
public class BaseUser
{
public string Id;
public char FirstInitial;
public System.Collections.Generic.List<Permission> Permissions;
public UserRole Role { get; set; }
public BaseUser() { }
public BaseUser(BaseUser instance)
{
this.Id = instance.Id;
this.FirstInitial = instance.FirstInitial;
this.Permissions = instance.Permissions;
this.Role = instance.Role;
}
public BaseUser(string Id = null, char FirstInitial = '\0', System.Collections.Generic.List<Permission> Permissions = null, UserRole Role = 0)
{
this.Id = Id;
this.FirstInitial = FirstInitial;
this.Permissions = Permissions;
this.Role = Role;
}
public class Permission
{
public string Name;
public Types Type;
public Permission() { }
public Permission(Permission instance)
{
this.Name = instance.Name;
this.Type = instance.Type;
}
public Permission(string Name = null, Types Type = 0)
{
this.Name = Name;
this.Type = Type;
}
public enum Types : int
{
Read = 0,