From f72e87cb96ea9071c205eb4a35324031f7805201 Mon Sep 17 00:00:00 2001 From: Ajiemar Santiago Date: Wed, 30 May 2018 19:17:26 -0500 Subject: [PATCH 1/3] Add DeleteUserData() to speech to text --- .../Services/SpeechToText/v1/SpeechToText.cs | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/Scripts/Services/SpeechToText/v1/SpeechToText.cs b/Scripts/Services/SpeechToText/v1/SpeechToText.cs index 94cf49a77..caa9b04bc 100644 --- a/Scripts/Services/SpeechToText/v1/SpeechToText.cs +++ b/Scripts/Services/SpeechToText/v1/SpeechToText.cs @@ -3614,6 +3614,107 @@ private void OnAddAcousticResourceResp(RESTConnector.Request req, RESTConnector. } #endregion + #region Delete User Data + /// + /// Deletes all data associated with a specified customer ID. The method has no effect if no data is associated with the customer ID. + /// You associate a customer ID with data by passing the X-Watson-Metadata header with a request that passes data. + /// For more information about personal data and customer IDs, see [**Information security**](https://console.bluemix.net/docs/services/discovery/information-security.html). + /// + /// The function that is called when the operation is successful. + /// The function that is called when the operation fails. + /// The customer ID for which all data is to be deleted. + /// object + /// A Dictionary of data that will be passed to the callback. The raw json output from the REST call will be passed in this object as the value of the 'json' key. + public bool DeleteUserData(SuccessCallback successCallback, FailCallback failCallback, string customerId, Dictionary customData = null) + { + if (successCallback == null) + throw new ArgumentNullException("successCallback"); + if (failCallback == null) + throw new ArgumentNullException("failCallback"); + if (string.IsNullOrEmpty(customerId)) + throw new ArgumentNullException("customerId"); + + DeleteUserDataRequestObj req = new DeleteUserDataRequestObj(); + req.SuccessCallback = successCallback; + req.FailCallback = failCallback; + req.CustomData = customData == null ? new Dictionary() : customData; + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + { + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + { + req.Headers.Add(kvp.Key, kvp.Value); + } + } + req.Parameters["customer_id"] = customerId; + req.Delete = true; + + req.OnResponse = OnDeleteUserDataResponse; + + RESTConnector connector = RESTConnector.GetConnector(Credentials, "/v1/user_data"); + if (connector == null) + return false; + + return connector.Send(req); + } + + private class DeleteUserDataRequestObj : RESTConnector.Request + { + /// + /// The success callback. + /// + public SuccessCallback SuccessCallback { get; set; } + /// + /// The fail callback. + /// + public FailCallback FailCallback { get; set; } + /// + /// Custom data. + /// + public Dictionary CustomData { get; set; } + } + + private void OnDeleteUserDataResponse(RESTConnector.Request req, RESTConnector.Response resp) + { + object result = new object(); + fsData data = null; + Dictionary customData = ((DeleteUserDataRequestObj)req).CustomData; + customData.Add(Constants.String.RESPONSE_HEADERS, resp.Headers); + + if (resp.Success) + { + try + { + fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + + object obj = result; + r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + + customData.Add("json", data); + } + catch (Exception e) + { + Log.Error("SpeechToText.OnDeleteUserDataResponse()", "Exception: {0}", e.ToString()); + resp.Success = false; + } + } + + if (resp.Success) + { + if (((DeleteUserDataRequestObj)req).SuccessCallback != null) + ((DeleteUserDataRequestObj)req).SuccessCallback(result, customData); + } + else + { + if (((DeleteUserDataRequestObj)req).FailCallback != null) + ((DeleteUserDataRequestObj)req).FailCallback(resp.Error, customData); + } + } + #endregion + #region IWatsonService interface /// public string GetServiceID() From 8ebd7ac4afa28c46f57c45da912e2c6fbbe2f4b9 Mon Sep 17 00:00:00 2001 From: Ajiemar Santiago Date: Wed, 30 May 2018 19:17:38 -0500 Subject: [PATCH 2/3] Add DeleteUserData() to text to speech --- .../Services/TextToSpeech/v1/TextToSpeech.cs | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/Scripts/Services/TextToSpeech/v1/TextToSpeech.cs b/Scripts/Services/TextToSpeech/v1/TextToSpeech.cs index 6b00a2937..4713ae9b7 100755 --- a/Scripts/Services/TextToSpeech/v1/TextToSpeech.cs +++ b/Scripts/Services/TextToSpeech/v1/TextToSpeech.cs @@ -1540,6 +1540,107 @@ private void OnAddCustomizationWordResp(RESTConnector.Request req, RESTConnector } #endregion + #region Delete User Data + /// + /// Deletes all data associated with a specified customer ID. The method has no effect if no data is associated with the customer ID. + /// You associate a customer ID with data by passing the X-Watson-Metadata header with a request that passes data. + /// For more information about personal data and customer IDs, see [**Information security**](https://console.bluemix.net/docs/services/discovery/information-security.html). + /// + /// The function that is called when the operation is successful. + /// The function that is called when the operation fails. + /// The customer ID for which all data is to be deleted. + /// object + /// A Dictionary of data that will be passed to the callback. The raw json output from the REST call will be passed in this object as the value of the 'json' key. + public bool DeleteUserData(SuccessCallback successCallback, FailCallback failCallback, string customerId, Dictionary customData = null) + { + if (successCallback == null) + throw new ArgumentNullException("successCallback"); + if (failCallback == null) + throw new ArgumentNullException("failCallback"); + if (string.IsNullOrEmpty(customerId)) + throw new ArgumentNullException("customerId"); + + DeleteUserDataRequestObj req = new DeleteUserDataRequestObj(); + req.SuccessCallback = successCallback; + req.FailCallback = failCallback; + req.CustomData = customData == null ? new Dictionary() : customData; + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + { + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + { + req.Headers.Add(kvp.Key, kvp.Value); + } + } + req.Parameters["customer_id"] = customerId; + req.Delete = true; + + req.OnResponse = OnDeleteUserDataResponse; + + RESTConnector connector = RESTConnector.GetConnector(Credentials, "/v1/user_data"); + if (connector == null) + return false; + + return connector.Send(req); + } + + private class DeleteUserDataRequestObj : RESTConnector.Request + { + /// + /// The success callback. + /// + public SuccessCallback SuccessCallback { get; set; } + /// + /// The fail callback. + /// + public FailCallback FailCallback { get; set; } + /// + /// Custom data. + /// + public Dictionary CustomData { get; set; } + } + + private void OnDeleteUserDataResponse(RESTConnector.Request req, RESTConnector.Response resp) + { + object result = new object(); + fsData data = null; + Dictionary customData = ((DeleteUserDataRequestObj)req).CustomData; + customData.Add(Constants.String.RESPONSE_HEADERS, resp.Headers); + + if (resp.Success) + { + try + { + fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + + object obj = result; + r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + + customData.Add("json", data); + } + catch (Exception e) + { + Log.Error("TextToSpeech.OnDeleteUserDataResponse()", "Exception: {0}", e.ToString()); + resp.Success = false; + } + } + + if (resp.Success) + { + if (((DeleteUserDataRequestObj)req).SuccessCallback != null) + ((DeleteUserDataRequestObj)req).SuccessCallback(result, customData); + } + else + { + if (((DeleteUserDataRequestObj)req).FailCallback != null) + ((DeleteUserDataRequestObj)req).FailCallback(resp.Error, customData); + } + } + #endregion + #region IWatsonService interface /// public string GetServiceID() From 898c1fed8f7b24eb571d605fd70b006ac60b7fb1 Mon Sep 17 00:00:00 2001 From: Ajiemar Santiago Date: Wed, 30 May 2018 19:17:48 -0500 Subject: [PATCH 3/3] Add DeleteUserData() to visual recognition --- .../VisualRecognition/v3/VisualRecognition.cs | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/Scripts/Services/VisualRecognition/v3/VisualRecognition.cs b/Scripts/Services/VisualRecognition/v3/VisualRecognition.cs index 9ee9feca4..42a2f19c8 100644 --- a/Scripts/Services/VisualRecognition/v3/VisualRecognition.cs +++ b/Scripts/Services/VisualRecognition/v3/VisualRecognition.cs @@ -1307,6 +1307,109 @@ private void OnDownloadCoreMLModelFail(RESTConnector.Error error, Dictionary + /// Deletes all data associated with a specified customer ID. The method has no effect if no data is associated with the customer ID. + /// You associate a customer ID with data by passing the X-Watson-Metadata header with a request that passes data. + /// For more information about personal data and customer IDs, see [**Information security**](https://console.bluemix.net/docs/services/discovery/information-security.html). + /// + /// The function that is called when the operation is successful. + /// The function that is called when the operation fails. + /// The customer ID for which all data is to be deleted. + /// object + /// A Dictionary of data that will be passed to the callback. The raw json output from the REST call will be passed in this object as the value of the 'json' key. + public bool DeleteUserData(SuccessCallback successCallback, FailCallback failCallback, string customerId, Dictionary customData = null) + { + if (successCallback == null) + throw new ArgumentNullException("successCallback"); + if (failCallback == null) + throw new ArgumentNullException("failCallback"); + if (string.IsNullOrEmpty(customerId)) + throw new ArgumentNullException("customerId"); + + DeleteUserDataRequestObj req = new DeleteUserDataRequestObj(); + req.SuccessCallback = successCallback; + req.FailCallback = failCallback; + req.CustomData = customData == null ? new Dictionary() : customData; + if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) + { + foreach (KeyValuePair kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary) + { + req.Headers.Add(kvp.Key, kvp.Value); + } + } + req.Parameters["customer_id"] = customerId; + if (Credentials.HasApiKey()) + req.Parameters["api_key"] = Credentials.ApiKey; + req.Delete = true; + + req.OnResponse = OnDeleteUserDataResponse; + + RESTConnector connector = RESTConnector.GetConnector(Credentials, "/v3/user_data"); + if (connector == null) + return false; + + return connector.Send(req); + } + + private class DeleteUserDataRequestObj : RESTConnector.Request + { + /// + /// The success callback. + /// + public SuccessCallback SuccessCallback { get; set; } + /// + /// The fail callback. + /// + public FailCallback FailCallback { get; set; } + /// + /// Custom data. + /// + public Dictionary CustomData { get; set; } + } + + private void OnDeleteUserDataResponse(RESTConnector.Request req, RESTConnector.Response resp) + { + object result = new object(); + fsData data = null; + Dictionary customData = ((DeleteUserDataRequestObj)req).CustomData; + customData.Add(Constants.String.RESPONSE_HEADERS, resp.Headers); + + if (resp.Success) + { + try + { + fsResult r = fsJsonParser.Parse(Encoding.UTF8.GetString(resp.Data), out data); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + + object obj = result; + r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); + if (!r.Succeeded) + throw new WatsonException(r.FormattedMessages); + + customData.Add("json", data); + } + catch (Exception e) + { + Log.Error("VisualRecognition.OnDeleteUserDataResponse()", "Exception: {0}", e.ToString()); + resp.Success = false; + } + } + + if (resp.Success) + { + if (((DeleteUserDataRequestObj)req).SuccessCallback != null) + ((DeleteUserDataRequestObj)req).SuccessCallback(result, customData); + } + else + { + if (((DeleteUserDataRequestObj)req).FailCallback != null) + ((DeleteUserDataRequestObj)req).FailCallback(resp.Error, customData); + } + } + #endregion + #region private methods private string GetMimeType(string imagePath) {