private bool GetTranslation(SuccessCallback <Translations> successCallback, FailCallback failCallback, string json, Dictionary <string, object> customData = null) { if (successCallback == null) { throw new ArgumentNullException("successCallback"); } if (failCallback == null) { throw new ArgumentNullException("failCallback"); } if (string.IsNullOrEmpty(json)) { throw new ArgumentNullException("json"); } RESTConnector connector = RESTConnector.GetConnector(Credentials, "/v2/translate"); if (connector == null) { return(false); } TranslateReq req = new TranslateReq(); req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary <string, object>() : customData; req.OnResponse = TranslateResponse; req.Send = Encoding.UTF8.GetBytes(json); req.Headers["accept"] = "application/json"; req.Headers["Content-Type"] = "application/json"; return(connector.Send(req)); }
private bool GetTranslation(SuccessCallback <Translations> successCallback, FailCallback failCallback, string json, Dictionary <string, object> customData = null) { if (successCallback == null) { throw new ArgumentNullException("successCallback"); } if (failCallback == null) { throw new ArgumentNullException("failCallback"); } if (string.IsNullOrEmpty(json)) { throw new ArgumentNullException("json"); } RESTConnector connector = RESTConnector.GetConnector(Credentials, "/v3/translate"); if (connector == null) { return(false); } TranslateReq req = new TranslateReq(); req.Parameters["version"] = VersionDate; req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.HttpMethod = UnityWebRequest.kHttpVerbPOST; req.DisableSslVerification = DisableSslVerification; req.CustomData = customData == null ? new Dictionary <string, object>() : customData; if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { foreach (KeyValuePair <string, string> kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary <string, string> ) { req.Headers.Add(kvp.Key, kvp.Value); } } req.OnResponse = TranslateResponse; req.Headers["X-IBMCloud-SDK-Analytics"] = "service_name=language_translator;service_version=v3;operation_id=GetTranslation"; req.Send = Encoding.UTF8.GetBytes(json); req.Headers["accept"] = "application/json"; req.Headers["Content-Type"] = "application/json"; return(connector.Send(req)); }
private bool GetTranslation(SuccessCallback <Translations> successCallback, FailCallback failCallback, string json, Dictionary <string, object> customData = null) { if (successCallback == null) { throw new ArgumentNullException("successCallback"); } if (failCallback == null) { throw new ArgumentNullException("failCallback"); } if (string.IsNullOrEmpty(json)) { throw new ArgumentNullException("json"); } RESTConnector connector = RESTConnector.GetConnector(Credentials, "/v3/translate"); if (connector == null) { return(false); } TranslateReq req = new TranslateReq(); req.Parameters["version"] = VersionDate; req.SuccessCallback = successCallback; req.FailCallback = failCallback; req.CustomData = customData == null ? new Dictionary <string, object>() : customData; if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS)) { foreach (KeyValuePair <string, string> kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary <string, string> ) { req.Headers.Add(kvp.Key, kvp.Value); } } req.OnResponse = TranslateResponse; req.Send = Encoding.UTF8.GetBytes(json); req.Headers["accept"] = "application/json"; req.Headers["Content-Type"] = "application/json"; return(connector.Send(req)); }
private bool GetTranslation(string json, TranslateCallback callback) { if (callback == null) { throw new ArgumentNullException("callback"); } RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, "/v2/translate"); if (connector == null) { return(false); } TranslateReq req = new TranslateReq(); req.Callback = callback; req.OnResponse = TranslateResponse; req.Send = Encoding.UTF8.GetBytes(json); req.Headers["accept"] = "application/json"; req.Headers["Content-Type"] = "application/json"; return(connector.Send(req)); }