-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathIRestClient.cs
More file actions
347 lines (277 loc) · 14.7 KB
/
IRestClient.cs
File metadata and controls
347 lines (277 loc) · 14.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#region License
// Copyright 2010 John Sheehan
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion
using System;
using Crestron.SimplSharp;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;
using RestSharp.Authenticators;
using RestSharp.Deserializers;
#if ASYNC
using System.Threading.Tasks;
#endif
using Crestron.SimplSharp.Cryptography.X509Certificates;
using Crestron.SimplSharp.Net.Security;
using RestSharp.Serialization;
using SSMono.Net;
using SSMono.Net.Cache;
using HttpWebRequest = SSMono.Net.HttpWebRequest;
using IWebProxy = SSMono.Net.IWebProxy;
namespace RestSharp
{
public interface IRestClient
{
[Obsolete ("Use the overload that accepts the delegate factory")]
IRestClient UseSerializer (IRestSerializer serializer);
CookieContainer CookieContainer { get; set; }
bool AutomaticDecompression { get; set; }
int? MaxRedirects { get; set; }
string UserAgent { get; set; }
int Timeout { get; set; }
int ReadWriteTimeout { get; set; }
bool UseSynchronizationContext { get; set; }
IAuthenticator Authenticator { get; set; }
Uri BaseUrl { get; set; }
Encoding Encoding { get; set; }
bool ThrowOnDeserializationError { get; set; }
bool FailOnDeserializationError { get; set; }
string ConnectionGroupName { get; set; }
bool PreAuthenticate { get; set; }
bool UnsafeAuthenticatedConnectionSharing { get; set; }
IList<Parameter> DefaultParameters { get; }
string BaseHost { get; set; }
bool AllowMultipleDefaultParametersWithSameName { get; set; }
[Obsolete ("This method will be removed soon in favour of the proper async call")]
RestRequestAsyncHandle ExecuteAsync (IRestRequest request,
Action<IRestResponse, RestRequestAsyncHandle> callback);
[Obsolete ("This method will be removed soon in favour of the proper async call")]
RestRequestAsyncHandle ExecuteAsync<T> (IRestRequest request,
Action<IRestResponse<T>, RestRequestAsyncHandle> callback) where T : new();
[Obsolete ("This method will be removed soon in favour of the proper async call")]
RestRequestAsyncHandle ExecuteAsync (IRestRequest request,
Action<IRestResponse, RestRequestAsyncHandle> callback, Method httpMethod);
[Obsolete ("This method will be removed soon in favour of the proper async call")]
RestRequestAsyncHandle ExecuteAsync<T> (IRestRequest request,
Action<IRestResponse<T>, RestRequestAsyncHandle> callback, Method httpMethod) where T : new();
IRestResponse<T> Deserialize<T> (IRestResponse response) where T : new();
/// <summary>
/// Allows to use a custom way to encode URL parameters
/// </summary>
/// <param name="encoder">A delegate to encode URL parameters</param>
/// <example>client.UseUrlEncoder(s => HttpUtility.UrlEncode(s));</example>
/// <returns></returns>
IRestClient UseUrlEncoder (Func<string, string> encoder);
/// <summary>
/// Allows to use a custom way to encode query parameters
/// </summary>
/// <param name="queryEncoder">A delegate to encode query parameters</param>
/// <example>client.UseUrlEncoder((s, encoding) => HttpUtility.UrlEncode(s, encoding));</example>
/// <returns></returns>
IRestClient UseQueryEncoder (Func<string, Encoding, string> queryEncoder);
IRestResponse Execute (IRestRequest request);
IRestResponse Execute (IRestRequest request, Method httpMethod);
IRestResponse<T> Execute<T> (IRestRequest request) where T : new ();
IRestResponse<T> Execute<T> (IRestRequest request, Method httpMethod) where T : new ();
byte[] DownloadData (IRestRequest request);
byte[] DownloadData (IRestRequest request, bool throwOnError);
/// <summary>
/// X509CertificateCollection to be sent with request
/// </summary>
X509CertificateCollection ClientCertificates { get; set; }
IWebProxy Proxy { get; set; }
RequestCachePolicy CachePolicy { get; set; }
bool Pipelined { get; set; }
bool FollowRedirects { get; set; }
Uri BuildUri (IRestRequest request);
string BuildUriWithoutQueryParameters (IRestRequest request);
/// <summary>
/// Callback function for handling the validation of remote certificates. Useful for certificate pinning and
/// overriding certificate errors in the scope of a request.
/// </summary>
RemoteCertificateValidationCallback RemoteCertificateValidationCallback { get; set; }
/// <summary>
/// Executes a GET-style request and callback asynchronously, authenticating if needed
/// </summary>
/// <param name="request">Request to be executed</param>
/// <param name="callback">Callback function to be executed upon completion providing access to the async handle.</param>
/// <param name="httpMethod">The HTTP method to execute</param>
[Obsolete ("This method will be removed soon in favour of the proper async call")]
RestRequestAsyncHandle ExecuteAsyncGet (IRestRequest request, Action<IRestResponse,
RestRequestAsyncHandle> callback, string httpMethod);
/// <summary>
/// Executes a POST-style request and callback asynchronously, authenticating if needed
/// </summary>
/// <param name="request">Request to be executed</param>
/// <param name="callback">Callback function to be executed upon completion providing access to the async handle.</param>
/// <param name="httpMethod">The HTTP method to execute</param>
[Obsolete ("This method will be removed soon in favour of the proper async call")]
RestRequestAsyncHandle ExecuteAsyncPost (IRestRequest request, Action<IRestResponse,
RestRequestAsyncHandle> callback, string httpMethod);
/// <summary>
/// Executes a GET-style request and callback asynchronously, authenticating if needed
/// </summary>
/// <typeparam name="T">Target deserialization type</typeparam>
/// <param name="request">Request to be executed</param>
/// <param name="callback">Callback function to be executed upon completion</param>
/// <param name="httpMethod">The HTTP method to execute</param>
[Obsolete ("This method will be removed soon in favour of the proper async call")]
RestRequestAsyncHandle ExecuteAsyncGet<T> (IRestRequest request, Action<IRestResponse<T>,
RestRequestAsyncHandle> callback, string httpMethod) where T : new ();
/// <summary>
/// Executes a GET-style request and callback asynchronously, authenticating if needed
/// </summary>
/// <typeparam name="T">Target deserialization type</typeparam>
/// <param name="request">Request to be executed</param>
/// <param name="callback">Callback function to be executed upon completion</param>
/// <param name="httpMethod">The HTTP method to execute</param>
[Obsolete ("This method will be removed soon in favour of the proper async call")]
RestRequestAsyncHandle ExecuteAsyncPost<T> (IRestRequest request, Action<IRestResponse<T>,
RestRequestAsyncHandle> callback, string httpMethod) where T : new ();
/// <summary>
/// Add a delegate to apply custom configuration to HttpWebRequest before making a call
/// </summary>
/// <param name="configurator">Configuration delegate for HttpWebRequest</param>
void ConfigureWebRequest (Action<HttpWebRequest> configurator);
/// <summary>
/// Adds or replaces a deserializer for the specified content type
/// </summary>
/// <param name="contentType">Content type for which the deserializer will be replaced</param>
/// <param name="deserializer">Custom deserializer</param>
[Obsolete ("Use the overload that accepts a factory delegate")]
void AddHandler (string contentType, IDeserializer deserializer);
/// <summary>
/// Adds or replaces a deserializer for the specified content type
/// </summary>
/// <param name="contentType">Content type for which the deserializer will be replaced</param>
/// <param name="deserializerFactory">Custom deserializer factory</param>
void AddHandler (string contentType, Func<IDeserializer> deserializerFactory);
/// <summary>
/// Removes custom deserialzier for the specified content type
/// </summary>
/// <param name="contentType">Content type for which deserializer needs to be removed</param>
void RemoveHandler (string contentType);
/// <summary>
/// Remove deserializers for all content types
/// </summary>
void ClearHandlers ();
IRestResponse ExecuteAsGet (IRestRequest request, string httpMethod);
IRestResponse ExecuteAsPost (IRestRequest request, string httpMethod);
IRestResponse<T> ExecuteAsGet<T> (IRestRequest request, string httpMethod) where T : new ();
IRestResponse<T> ExecuteAsPost<T> (IRestRequest request, string httpMethod) where T : new ();
#if ASYNC
/// <summary>
/// Executes the request and callback asynchronously, authenticating if needed
/// </summary>
/// <typeparam name="T">Target deserialization type</typeparam>
/// <param name="request">Request to be executed</param>
/// <param name="token">The cancellation token</param>
[Obsolete("This method will be renamed to ExecuteAsync soon")]
Task<IRestResponse<T>> ExecuteTaskAsync<T>(IRestRequest request, CancellationToken token);
/// <summary>
/// Executes the request asynchronously, authenticating if needed
/// </summary>
/// <typeparam name="T">Target deserialization type</typeparam>
/// <param name="request">Request to be executed</param>
/// <param name="httpMethod">Override the request method</param>
[Obsolete("This method will be renamed to ExecuteAsync soon")]
Task<IRestResponse<T>> ExecuteTaskAsync<T>(IRestRequest request, Method httpMethod);
/// <summary>
/// Executes the request asynchronously, authenticating if needed
/// </summary>
/// <typeparam name="T">Target deserialization type</typeparam>
/// <param name="request">Request to be executed</param>
[Obsolete("This method will be renamed to ExecuteAsync soon")]
Task<IRestResponse<T>> ExecuteTaskAsync<T>(IRestRequest request);
/// <summary>
/// Executes a GET-style request asynchronously, authenticating if needed
/// </summary>
/// <typeparam name="T">Target deserialization type</typeparam>
/// <param name="request">Request to be executed</param>
[Obsolete("This method will be renamed to ExecuteGetAsync soon")]
Task<IRestResponse<T>> ExecuteGetTaskAsync<T>(IRestRequest request);
/// <summary>
/// Executes a GET-style request asynchronously, authenticating if needed
/// </summary>
/// <typeparam name="T">Target deserialization type</typeparam>
/// <param name="request">Request to be executed</param>
/// <param name="token">The cancellation token</param>
[Obsolete("This method will be renamed to ExecuteGetAsync soon")]
Task<IRestResponse<T>> ExecuteGetTaskAsync<T>(IRestRequest request, CancellationToken token);
/// <summary>
/// Executes a POST-style request asynchronously, authenticating if needed
/// </summary>
/// <typeparam name="T">Target deserialization type</typeparam>
/// <param name="request">Request to be executed</param>
[Obsolete("This method will be renamed to ExecutePostAsync soon")]
Task<IRestResponse<T>> ExecutePostTaskAsync<T>(IRestRequest request);
/// <summary>
/// Executes a POST-style request asynchronously, authenticating if needed
/// </summary>
/// <typeparam name="T">Target deserialization type</typeparam>
/// <param name="request">Request to be executed</param>
/// <param name="token">The cancellation token</param>
[Obsolete("This method will be renamed to ExecutePostAsync soon")]
Task<IRestResponse<T>> ExecutePostTaskAsync<T>(IRestRequest request, CancellationToken token);
/// <summary>
/// Executes the request and callback asynchronously, authenticating if needed
/// </summary>
/// <param name="request">Request to be executed</param>
/// <param name="token">The cancellation token</param>
[Obsolete("This method will be renamed to ExecuteAsync soon")]
Task<IRestResponse> ExecuteTaskAsync(IRestRequest request, CancellationToken token);
/// <summary>
/// Executes the request and callback asynchronously, authenticating if needed
/// </summary>
/// <param name="request">Request to be executed</param>
/// <param name="token">The cancellation token</param>
/// <param name="httpMethod">Override the request method</param>
[Obsolete("This method will be renamed to ExecuteAsync soon")]
Task<IRestResponse> ExecuteTaskAsync(IRestRequest request, CancellationToken token, Method httpMethod);
/// <summary>
/// Executes the request asynchronously, authenticating if needed
/// </summary>
/// <param name="request">Request to be executed</param>
[Obsolete("This method will be renamed to ExecuteAsync soon")]
Task<IRestResponse> ExecuteTaskAsync(IRestRequest request);
/// <summary>
/// Executes a GET-style asynchronously, authenticating if needed
/// </summary>
/// <param name="request">Request to be executed</param>
[Obsolete("This method will be renamed to ExecuteGetAsync soon")]
Task<IRestResponse> ExecuteGetTaskAsync(IRestRequest request);
/// <summary>
/// Executes a GET-style asynchronously, authenticating if needed
/// </summary>
/// <param name="request">Request to be executed</param>
/// <param name="token">The cancellation token</param>
[Obsolete("This method will be renamed to ExecuteGetAsync soon")]
Task<IRestResponse> ExecuteGetTaskAsync(IRestRequest request, CancellationToken token);
/// <summary>
/// Executes a POST-style asynchronously, authenticating if needed
/// </summary>
/// <param name="request">Request to be executed</param>
[Obsolete("This method will be renamed to ExecutePostAsync soon")]
Task<IRestResponse> ExecutePostTaskAsync(IRestRequest request);
/// <summary>
/// Executes a POST-style asynchronously, authenticating if needed
/// </summary>
/// <param name="request">Request to be executed</param>
/// <param name="token">The cancellation token</param>
[Obsolete("This method will be renamed to ExecutePostAsync soon")]
Task<IRestResponse> ExecutePostTaskAsync(IRestRequest request, CancellationToken token);
#endif
}
}