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() 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() diff --git a/Scripts/Services/VisualRecognition/v3/VisualRecognition.cs b/Scripts/Services/VisualRecognition/v3/VisualRecognition.cs index 14d06f0e3..9f3eae601 100644 --- a/Scripts/Services/VisualRecognition/v3/VisualRecognition.cs +++ b/Scripts/Services/VisualRecognition/v3/VisualRecognition.cs @@ -1260,6 +1260,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) {