generated from CareBoo/UPMTemplate-2020
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node services): add explicit operators to convert from `IAlgoApi…
…Client` to dotnet SDK APIs - add `UnityHttpMessageHandler` - add `UnityHttpClient` - add explicit operators `AlgodClient` <-> Algorand.Algod APIs - add explicit operators `IndexerClient` <-> Algorand.Indexer APIs fix #157, fix #158
- Loading branch information
1 parent
2bc3cfc
commit 6a657fc
Showing
94 changed files
with
603 additions
and
931 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,72 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using System; | ||
using System.Net.Http; | ||
|
||
namespace Algorand.Unity | ||
{ | ||
public class UnityHttpClient : HttpClient | ||
{ | ||
public readonly UnityHttpMessageHandler MessageHandler; | ||
|
||
protected UnityHttpClient(UnityHttpMessageHandler messageHandler) | ||
: base(messageHandler) | ||
{ | ||
MessageHandler = messageHandler; | ||
} | ||
|
||
public UnityHttpClient( | ||
string address | ||
) | ||
: base(new UnityHttpMessageHandler()) | ||
: this(address, System.Threading.Timeout.InfiniteTimeSpan) | ||
{ | ||
} | ||
|
||
public UnityHttpClient( | ||
string address, | ||
TimeSpan timeout | ||
) | ||
: this(new UnityHttpMessageHandler()) | ||
{ | ||
BaseAddress = FormatAddress(address); | ||
Timeout = timeout; | ||
} | ||
|
||
public UnityHttpClient( | ||
string address, | ||
params (string header, string value)[] headers | ||
) | ||
: base(new UnityHttpMessageHandler()) | ||
: this(address, System.Threading.Timeout.InfiniteTimeSpan, headers) | ||
{ | ||
} | ||
|
||
public UnityHttpClient( | ||
string address, | ||
TimeSpan timeout, | ||
params (string header, string value)[] headers | ||
) | ||
: this(new UnityHttpMessageHandler()) | ||
{ | ||
BaseAddress = FormatAddress(address); | ||
Timeout = timeout; | ||
|
||
if (headers == null) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (var (key, value) in headers) | ||
{ | ||
DefaultRequestHeaders.Add(key, value); | ||
} | ||
} | ||
|
||
private static Uri FormatAddress(string address) | ||
{ | ||
if (!address.EndsWith('/')) | ||
address = address + '/'; | ||
address += '/'; | ||
var addressUri = new Uri(address); | ||
if (!addressUri.IsAbsoluteUri) | ||
throw new ArgumentException("Given host must be an absolute path.", nameof(address)); | ||
if (headers == null) | ||
throw new ArgumentNullException(nameof(headers)); | ||
return addressUri; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.