@@ -196,5 +196,77 @@ public static IRestResponse Delete(this IRestClient client, IRestRequest request
196
196
return client . Execute ( request ) ;
197
197
}
198
198
#endif
199
+
200
+ /// <summary>
201
+ /// Add a parameter to use on every request made with this client instance
202
+ /// </summary>
203
+ /// <param name="restClient">The IRestClient instance</param>
204
+ /// <param name="p">Parameter to add</param>
205
+ /// <returns></returns>
206
+ public static void AddDefaultParameter ( this IRestClient restClient , Parameter p )
207
+ {
208
+ if ( p . Type == ParameterType . RequestBody )
209
+ {
210
+ throw new NotSupportedException (
211
+ "Cannot set request body from default headers. Use Request.AddBody() instead." ) ;
212
+ }
213
+
214
+ restClient . DefaultParameters . Add ( p ) ;
215
+ }
216
+
217
+ /// <summary>
218
+ /// Adds a HTTP parameter (QueryString for GET, DELETE, OPTIONS and HEAD; Encoded form for POST and PUT)
219
+ /// Used on every request made by this client instance
220
+ /// </summary>
221
+ /// <param name="restClient">The IRestClient instance</param>
222
+ /// <param name="name">Name of the parameter</param>
223
+ /// <param name="value">Value of the parameter</param>
224
+ /// <returns>This request</returns>
225
+ public static void AddDefaultParameter ( this IRestClient restClient , string name , object value )
226
+ {
227
+ restClient . AddDefaultParameter ( new Parameter { Name = name , Value = value , Type = ParameterType . GetOrPost } ) ;
228
+ }
229
+
230
+ /// <summary>
231
+ /// Adds a parameter to the request. There are four types of parameters:
232
+ /// - GetOrPost: Either a QueryString value or encoded form value based on method
233
+ /// - HttpHeader: Adds the name/value pair to the HTTP request's Headers collection
234
+ /// - UrlSegment: Inserted into URL if there is a matching url token e.g. {AccountId}
235
+ /// - RequestBody: Used by AddBody() (not recommended to use directly)
236
+ /// </summary>
237
+ /// <param name="restClient">The IRestClient instance</param>
238
+ /// <param name="name">Name of the parameter</param>
239
+ /// <param name="value">Value of the parameter</param>
240
+ /// <param name="type">The type of parameter to add</param>
241
+ /// <returns>This request</returns>
242
+ public static void AddDefaultParameter ( this IRestClient restClient , string name , object value , ParameterType type )
243
+ {
244
+ restClient . AddDefaultParameter ( new Parameter { Name = name , Value = value , Type = type } ) ;
245
+ }
246
+
247
+ /// <summary>
248
+ /// Shortcut to AddDefaultParameter(name, value, HttpHeader) overload
249
+ /// </summary>
250
+ /// <param name="restClient">The IRestClient instance</param>
251
+ /// <param name="name">Name of the header to add</param>
252
+ /// <param name="value">Value of the header to add</param>
253
+ /// <returns></returns>
254
+ public static void AddDefaultHeader ( this IRestClient restClient , string name , string value )
255
+ {
256
+ restClient . AddDefaultParameter ( name , value , ParameterType . HttpHeader ) ;
257
+ }
258
+
259
+ /// <summary>
260
+ /// Shortcut to AddDefaultParameter(name, value, UrlSegment) overload
261
+ /// </summary>
262
+ /// <param name="restClient">The IRestClient instance</param>
263
+ /// <param name="name">Name of the segment to add</param>
264
+ /// <param name="value">Value of the segment to add</param>
265
+ /// <returns></returns>
266
+ public static void AddDefaultUrlSegment ( this IRestClient restClient , string name , string value )
267
+ {
268
+ restClient . AddDefaultParameter ( name , value , ParameterType . UrlSegment ) ;
269
+ }
270
+
199
271
}
200
272
}
0 commit comments