Skip to content

Commit f3addbc

Browse files
committed
feat: Removed customData
1 parent 4d3675d commit f3addbc

File tree

5 files changed

+37
-41
lines changed

5 files changed

+37
-41
lines changed

BaseService.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717

1818
using IBM.Cloud.SDK.Utilities;
1919
using System;
20-
20+
using System.Collections.Generic;
21+
2122
namespace IBM.Cloud.SDK
2223
{
2324
public class BaseService
2425
{
2526
protected Credentials credentials;
2627
protected string url;
28+
protected Dictionary<string, string> customRequestHeaders = new Dictionary<string, string>();
2729

2830
public BaseService(string serviceId)
2931
{
@@ -75,5 +77,37 @@ public BaseService(string versionDate, string serviceId) : this(serviceId) { }
7577
public BaseService(string versionDate, Credentials credentials, string serviceId) { }
7678

7779
public BaseService(Credentials credentials, string serviceId) { }
80+
81+
public void WithHeader(string name, string value)
82+
{
83+
if (!customRequestHeaders.ContainsKey(name))
84+
{
85+
customRequestHeaders.Add(name, value);
86+
}
87+
else
88+
{
89+
customRequestHeaders[name] = value;
90+
}
91+
}
92+
93+
public void WithHeaders(Dictionary<string, string> headers)
94+
{
95+
foreach (KeyValuePair<string, string> kvp in headers)
96+
{
97+
if (!customRequestHeaders.ContainsKey(kvp.Key))
98+
{
99+
customRequestHeaders.Add(kvp.Key, kvp.Value);
100+
}
101+
else
102+
{
103+
customRequestHeaders[kvp.Key] = kvp.Value;
104+
}
105+
}
106+
}
107+
108+
protected void ClearCustomRequestHeaders()
109+
{
110+
customRequestHeaders = new Dictionary<string, string>();
111+
}
78112
}
79113
}

CallbackDelegates.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@ namespace IBM.Cloud.SDK
2424
/// </summary>
2525
/// <typeparam name="T">Type of the returned object.</typeparam>
2626
/// <param name="response">The returned DetailedResponse.</param>
27-
/// <param name="customData">user defined custom data including raw json.</param>
2827
public delegate void Callback<T>(DetailedResponse<T> response, IBMError error);
2928
}

RequestObject.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,5 @@ public class RequestObject<T> : RESTConnector.Request
3030
/// The success callback.
3131
/// </summary>
3232
public Callback<T> Callback { get; set; }
33-
/// <summary>
34-
/// Custom data.
35-
/// </summary>
36-
public Dictionary<string, object> CustomData { get; set; }
3733
}
3834
}

Utilities/Constants.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,6 @@ public static class String
4949
/// <exclude />
5050
public const string DebugDispalyQuality = "Quality: {0}";
5151
/// <summary>
52-
/// Name for creating custom headers in CustomData.
53-
/// </summary>
54-
public const string CUSTOM_REQUEST_HEADERS = "request_headers";
55-
/// <summary>
56-
/// Name for accessing response headers in CustomData.
57-
/// </summary>
58-
public const string RESPONSE_HEADERS = "response_headers";
59-
/// <summary>
60-
/// Name for accessing json.
61-
/// </summary>
62-
public const string JSON = "json";
63-
/// <summary>
6452
/// URL for IBM Cloud onboarding
6553
/// </summary>
6654
public const string IBM_CLOUD_URL = "http://console.bluemix.net/registration";

Utilities/Credentials.cs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ public bool DisableSslVerification
139139
/// </summary>
140140
/// <typeparam name="T">Type of the returned object.</typeparam>
141141
/// <param name="response">The returned DetailedResponse.</param>
142-
/// <param name="customData">user defined custom data including raw json.</param>
143142
public delegate void Callback<T>(DetailedResponse<T> response, IBMError error);
144143
#endregion
145144

@@ -278,9 +277,8 @@ private void OnGetToken(DetailedResponse<IamTokenData> response, IBMError error)
278277
/// </summary>
279278
/// <param name="callback">The request callback.</param>
280279
/// <param name="error"> The request error.</param>
281-
/// <param name="customData">Dictionary of custom data.</param>
282280
/// <returns></returns>
283-
public bool RequestIamToken(Callback<IamTokenData> callback, Dictionary<string, object> customData = null)
281+
public bool RequestIamToken(Callback<IamTokenData> callback)
284282
{
285283
if (callback == null)
286284
throw new ArgumentNullException("successCallback");
@@ -297,14 +295,6 @@ public bool RequestIamToken(Callback<IamTokenData> callback, Dictionary<string,
297295
req.Headers.Add("Authorization", "Basic Yng6Yng=");
298296
req.OnResponse = OnRequestIamTokenResponse;
299297
req.DisableSslVerification = DisableSslVerification;
300-
req.CustomData = customData == null ? new Dictionary<string, object>() : customData;
301-
if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS))
302-
{
303-
foreach (KeyValuePair<string, string> kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary<string, string>)
304-
{
305-
req.Headers.Add(kvp.Key, kvp.Value);
306-
}
307-
}
308298
req.Forms = new Dictionary<string, RESTConnector.Form>();
309299
req.Forms["grant_type"] = new RESTConnector.Form("urn:ibm:params:oauth:grant-type:apikey");
310300
req.Forms["apikey"] = new RESTConnector.Form(_iamApiKey);
@@ -315,7 +305,6 @@ public bool RequestIamToken(Callback<IamTokenData> callback, Dictionary<string,
315305

316306
private class RequestIamTokenRequest : RESTConnector.Request
317307
{
318-
public Dictionary<string, object> CustomData { get; set; }
319308
public Callback<IamTokenData> Callback { get; set; }
320309
}
321310

@@ -362,9 +351,8 @@ private void OnRequestIamTokenResponse(RESTConnector.Request req, RESTConnector.
362351
/// </summary>
363352
/// <param name="callback">The success callback.</param>
364353
/// <param name="failCallback">The fail callback.</param>
365-
/// <param name="customData">Dictionary of custom data.</param>
366354
/// <returns></returns>
367-
public bool RefreshIamToken(Callback<IamTokenData> callback, Dictionary<string, object> customData = null)
355+
public bool RefreshIamToken(Callback<IamTokenData> callback)
368356
{
369357
if (callback == null)
370358
throw new ArgumentNullException("callback");
@@ -381,14 +369,6 @@ public bool RefreshIamToken(Callback<IamTokenData> callback, Dictionary<string,
381369
req.Headers.Add("Authorization", "Basic Yng6Yng=");
382370
req.OnResponse = OnRefreshIamTokenResponse;
383371
req.DisableSslVerification = DisableSslVerification;
384-
req.CustomData = customData == null ? new Dictionary<string, object>() : customData;
385-
if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS))
386-
{
387-
foreach (KeyValuePair<string, string> kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary<string, string>)
388-
{
389-
req.Headers.Add(kvp.Key, kvp.Value);
390-
}
391-
}
392372
req.Forms = new Dictionary<string, RESTConnector.Form>();
393373
req.Forms["grant_type"] = new RESTConnector.Form("refresh_token");
394374
req.Forms["refresh_token"] = new RESTConnector.Form(_iamTokenData.RefreshToken);
@@ -399,7 +379,6 @@ public bool RefreshIamToken(Callback<IamTokenData> callback, Dictionary<string,
399379
private class RefreshIamTokenRequest : RESTConnector.Request
400380
{
401381
public Callback<IamTokenData> Callback { get; set; }
402-
public Dictionary<string, object> CustomData { get; set; }
403382
}
404383

405384
private void OnRefreshIamTokenResponse(RESTConnector.Request req, RESTConnector.Response resp)

0 commit comments

Comments
 (0)