Revize a155a763
Přidáno uživatelem Jakub Šilhavý před téměř 3 roky(ů)
ld_client/LDClient/network/HttpClient.cs | ||
---|---|---|
9 | 9 |
using LDClient.network.data; |
10 | 10 |
|
11 | 11 |
namespace LDClient.network { |
12 |
|
|
13 |
/// <summary> |
|
14 |
/// Implementation of IHttpClient which defines the functionality |
|
15 |
/// of a HTTP client that is used by the API client to send data to the server. |
|
16 |
/// </summary> |
|
12 | 17 |
public class HttpClient : IHttpClient{ |
13 | 18 |
|
19 |
/// <summary> |
|
20 |
/// Instance of System.Net.Http.HttpClient |
|
21 |
/// </summary> |
|
14 | 22 |
private readonly System.Net.Http.HttpClient _httpClient; |
15 | 23 |
|
24 |
/// <summary> |
|
25 |
/// URL to which the HTTP client will connect |
|
26 |
/// </summary> |
|
16 | 27 |
private readonly string _uri; |
28 |
|
|
29 |
/// <summary> |
|
30 |
/// Creates an instance of the class |
|
31 |
/// </summary> |
|
32 |
/// <param name="uri">URL to which the HTTP client will connect</param> |
|
17 | 33 |
public HttpClient(string uri) { |
18 |
|
|
19 | 34 |
_httpClient = new System.Net.Http.HttpClient(); |
20 | 35 |
_uri = uri; |
21 | 36 |
} |
22 | 37 |
|
38 |
/// <summary> |
|
39 |
/// Asynchronically sends data in JSON format to the server. |
|
40 |
/// </summary> |
|
41 |
/// <param name="payload">Payload to be sent to the server</param> |
|
42 |
/// <returns></returns> |
|
23 | 43 |
public Task<HttpResponseMessage> PostAsJsonAsync(Payload payload) { |
44 |
// Serialize the payload and send it to the server as JSON. |
|
24 | 45 |
return _httpClient.PostAsJsonAsync(_uri, payload, new JsonSerializerOptions { |
25 | 46 |
Converters = { |
26 | 47 |
new JsonStringEnumConverter( JsonNamingPolicy.CamelCase) |
ld_client/LDClient/network/IApiClient.cs | ||
---|---|---|
2 | 2 |
|
3 | 3 |
namespace LDClient.network { |
4 | 4 |
|
5 |
/// <summary> |
|
6 |
/// This interface defines the functionality of an API client |
|
7 |
/// which is used to send information (payloads) to the server. |
|
8 |
/// </summary> |
|
5 | 9 |
public interface IApiClient { |
6 | 10 |
|
11 |
/// <summary> |
|
12 |
/// Sends a payload to the server (API). |
|
13 |
/// </summary> |
|
14 |
/// <param name="payload">instance of a payload to be sent off to the server</param> |
|
7 | 15 |
public Task SendPayloadAsync(Payload payload); |
16 |
|
|
17 |
/// <summary> |
|
18 |
/// Runs the periodical retrieval of failed payloads stored |
|
19 |
/// in a file-based cache. This method is instantiated as a thread. |
|
20 |
/// </summary> |
|
8 | 21 |
public void Run(); |
9 | 22 |
} |
10 | 23 |
} |
ld_client/LDClient/network/IHttpClient.cs | ||
---|---|---|
6 | 6 |
using LDClient.network.data; |
7 | 7 |
|
8 | 8 |
namespace LDClient.network { |
9 |
|
|
10 |
/// <summary> |
|
11 |
/// This interface defines the functionality of a HTTP client |
|
12 |
/// through which the API client sends data (payloads) to the server. |
|
13 |
/// </summary> |
|
9 | 14 |
public interface IHttpClient { |
10 | 15 |
|
16 |
/// <summary> |
|
17 |
/// Asynchronically sends data in JSON format to the server. |
|
18 |
/// </summary> |
|
19 |
/// <param name="payload">Payload to be sent to the server</param> |
|
20 |
/// <returns></returns> |
|
11 | 21 |
public Task<HttpResponseMessage> PostAsJsonAsync(Payload payload); |
12 | 22 |
} |
13 | 23 |
} |
Také k dispozici: Unified diff
re #9570 Commented HttpClient.cs, IHttpClient.cs, and IApiClient.cs