@@ -77,7 +77,7 @@ public enum Methods
7777 /// REST API client.
7878 /// </summary>
7979 /// <param name="host">Base url (e.g. https://api.sendgrid.com)</param>
80- /// <param name="requestHeaders">A dictoinary of request headers</param>
80+ /// <param name="requestHeaders">A dictionary of request headers</param>
8181 /// <param name="version">API version, override AddVersion to customize</param>
8282 /// <param name="urlPath">Path to endpoint (e.g. /path/to/endpoint)</param>
8383 /// <returns>Fluent interface to a REST API</returns>
@@ -86,19 +86,28 @@ public Client(string host, Dictionary<string,string> requestHeaders = null, stri
8686 Host = host ;
8787 if ( requestHeaders != null )
8888 {
89- RequestHeaders = ( RequestHeaders != null )
90- ? RequestHeaders . Union ( requestHeaders ) . ToDictionary ( pair => pair . Key , pair => pair . Value ) : requestHeaders ;
89+ AddRequestHeader ( requestHeaders ) ;
9190 }
9291 Version = ( version != null ) ? version : null ;
9392 UrlPath = ( urlPath != null ) ? urlPath : null ;
9493 }
9594
95+ /// <summary>
96+ /// Add requestHeaders to the API call
97+ /// </summary>
98+ /// <param name="requestHeaders">A dictionary of request headers</param>
99+ public void AddRequestHeader ( Dictionary < string , string > requestHeaders )
100+ {
101+ RequestHeaders = ( RequestHeaders != null )
102+ ? RequestHeaders . Union ( requestHeaders ) . ToDictionary ( pair => pair . Key , pair => pair . Value ) : requestHeaders ;
103+ }
104+
96105 /// <summary>
97106 /// Build the final URL
98107 /// </summary>
99- /// <param name="query_params ">A string of JSON formatted query parameters (e.g {'param': 'param_value'})</param>
108+ /// <param name="queryParams ">A string of JSON formatted query parameters (e.g {'param': 'param_value'})</param>
100109 /// <returns>Final URL</returns>
101- private string BuildUrl ( string query_params = null )
110+ private string BuildUrl ( string queryParams = null )
102111 {
103112 string endpoint = null ;
104113
@@ -111,10 +120,10 @@ private string BuildUrl(string query_params = null)
111120 endpoint = Host + UrlPath ;
112121 }
113122
114- if ( query_params != null )
123+ if ( queryParams != null )
115124 {
116125 JavaScriptSerializer jss = new JavaScriptSerializer ( ) ;
117- var ds_query_params = jss . Deserialize < Dictionary < string , dynamic > > ( query_params ) ;
126+ var ds_query_params = jss . Deserialize < Dictionary < string , dynamic > > ( queryParams ) ;
118127 var query = HttpUtility . ParseQueryString ( string . Empty ) ;
119128 foreach ( var pair in ds_query_params )
120129 {
@@ -211,25 +220,29 @@ public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, o
211220
212221 if ( Enum . IsDefined ( typeof ( Methods ) , binder . Name . ToUpper ( ) ) )
213222 {
214- string query_params = null ;
215- string request_body = null ;
223+ string queryParams = null ;
224+ string requestBody = null ;
216225 int i = 0 ;
217226
218227 foreach ( object obj in args )
219228 {
220229 string name = binder . CallInfo . ArgumentNames . Count > i ?
221230 binder . CallInfo . ArgumentNames [ i ] : null ;
222- if ( name == "query_params" )
231+ if ( name == "queryParams" )
232+ {
233+ queryParams = obj . ToString ( ) ;
234+ }
235+ else if ( name == "requestBody" )
223236 {
224- query_params = obj . ToString ( ) ;
237+ requestBody = obj . ToString ( ) ;
225238 }
226- else if ( name == "request_body " )
239+ else if ( name == "requestHeaders " )
227240 {
228- request_body = obj . ToString ( ) ;
241+ AddRequestHeader ( ( Dictionary < string , string > ) obj ) ;
229242 }
230243 i ++ ;
231244 }
232- result = RequestAsync ( binder . Name . ToUpper ( ) , request_body : request_body , query_params : query_params ) . Result ;
245+ result = RequestAsync ( binder . Name . ToUpper ( ) , requestBody : requestBody , queryParams : queryParams ) . Result ;
233246 return true ;
234247 }
235248 else
@@ -256,18 +269,18 @@ public async virtual Task<Response> MakeRequest(HttpClient client, HttpRequestMe
256269 /// Prepare for async call to the API server
257270 /// </summary>
258271 /// <param name="method">HTTP verb</param>
259- /// <param name="request_body ">JSON formatted string</param>
260- /// <param name="query_params ">JSON formatted queary paramaters</param>
272+ /// <param name="requestBody ">JSON formatted string</param>
273+ /// <param name="queryParams ">JSON formatted queary paramaters</param>
261274 /// <returns>Response object</returns>
262- private async Task < Response > RequestAsync ( string method , String request_body = null , String query_params = null )
275+ private async Task < Response > RequestAsync ( string method , String requestBody = null , String queryParams = null )
263276 {
264277 using ( var client = new HttpClient ( ) )
265278 {
266279 try
267280 {
268281 // Build the URL
269282 client . BaseAddress = new Uri ( Host ) ;
270- string endpoint = BuildUrl ( query_params ) ;
283+ string endpoint = BuildUrl ( queryParams ) ;
271284
272285 // Build the request headers
273286 client . DefaultRequestHeaders . Accept . Clear ( ) ;
@@ -293,9 +306,9 @@ private async Task<Response> RequestAsync(string method, String request_body = n
293306
294307 // Build the request body
295308 StringContent content = null ;
296- if ( request_body != null )
309+ if ( requestBody != null )
297310 {
298- content = new StringContent ( request_body . ToString ( ) . Replace ( "'" , "\" " ) , Encoding . UTF8 , MediaType ) ;
311+ content = new StringContent ( requestBody . ToString ( ) . Replace ( "'" , "\" " ) , Encoding . UTF8 , MediaType ) ;
299312 }
300313
301314 // Build the final request
0 commit comments