Bumped package version to 1.4.7. Added support for Stream requests and MemoryStream responses.
This commit is contained in:
@ -17,6 +17,8 @@ public class Client
|
||||
|
||||
public AuthApi Auth;
|
||||
|
||||
public StreamApi Stream;
|
||||
|
||||
public Client(string baseUrl)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(baseUrl))
|
||||
@ -48,6 +50,8 @@ public class Client
|
||||
this.Test = new TestApi(this);
|
||||
|
||||
this.Auth = new AuthApi(this);
|
||||
|
||||
this.Stream = new StreamApi(this);
|
||||
}
|
||||
|
||||
public class TestApi
|
||||
@ -174,7 +178,7 @@ public class Client
|
||||
}
|
||||
}
|
||||
|
||||
public void Signup(User request)
|
||||
public void Signup(UserDto request)
|
||||
{
|
||||
var message = new HttpRequestMessage(HttpMethod.Post, $"{this.Client.BaseUrl}/auth/signup");
|
||||
|
||||
@ -186,7 +190,7 @@ public class Client
|
||||
throw new Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
|
||||
}
|
||||
|
||||
public User Get()
|
||||
public UserDto Get()
|
||||
{
|
||||
var message = new HttpRequestMessage(HttpMethod.Get, $"{this.Client.BaseUrl}/auth");
|
||||
|
||||
@ -199,7 +203,7 @@ public class Client
|
||||
if (string.IsNullOrEmpty(content))
|
||||
return default;
|
||||
|
||||
return JsonConvert.DeserializeObject<User>(content);
|
||||
return JsonConvert.DeserializeObject<UserDto>(content);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -229,13 +233,61 @@ public class Client
|
||||
}
|
||||
}
|
||||
|
||||
public class StreamApi
|
||||
{
|
||||
public Client Client;
|
||||
|
||||
public StreamApi(Client client)
|
||||
{
|
||||
this.Client = client;
|
||||
}
|
||||
|
||||
public void Upload(System.IO.MemoryStream request)
|
||||
{
|
||||
var message = new HttpRequestMessage(HttpMethod.Post, $"{this.Client.BaseUrl}/upload");
|
||||
|
||||
request.Seek(0, System.IO.SeekOrigin.Begin);
|
||||
|
||||
message.Content = new StreamContent(request);
|
||||
|
||||
var response = this.Client.HttpClient.Send(message);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
throw new Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
|
||||
}
|
||||
|
||||
public System.IO.MemoryStream Download()
|
||||
{
|
||||
var message = new HttpRequestMessage(HttpMethod.Get, $"{this.Client.BaseUrl}/download");
|
||||
|
||||
var response = this.Client.HttpClient.Send(message);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
var stream = new System.IO.MemoryStream();
|
||||
|
||||
response.Content.ReadAsStream().CopyTo(stream);
|
||||
|
||||
stream.Seek(0, System.IO.SeekOrigin.Begin);
|
||||
|
||||
return stream;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unexpected Http Response StatusCode:" + response.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class IncludedType
|
||||
{
|
||||
public int Test;
|
||||
}
|
||||
|
||||
public class User : BaseUser
|
||||
public class UserDto : BaseUser
|
||||
{
|
||||
public System.PlatformID MachineType;
|
||||
|
||||
public string Name;
|
||||
|
||||
public System.Collections.Generic.List<string> List;
|
||||
|
Reference in New Issue
Block a user