diff --git a/Scripts/Services/Assistant/V1/AssistantService.cs b/Scripts/Services/Assistant/V1/AssistantService.cs index 15a2b238e..e3cddd9da 100644 --- a/Scripts/Services/Assistant/V1/AssistantService.cs +++ b/Scripts/Services/Assistant/V1/AssistantService.cs @@ -72,6 +72,7 @@ public AssistantService(string versionDate) : this(versionDate, ConfigBasedAuthe public AssistantService(string versionDate, Authenticator authenticator) : base(versionDate, authenticator, serviceId) { Authenticator = authenticator; + if (string.IsNullOrEmpty(versionDate)) { throw new ArgumentNullException("A versionDate (format `yyyy-mm-dd`) is required to create an instance of AssistantService"); @@ -81,7 +82,6 @@ public AssistantService(string versionDate, Authenticator authenticator) : base( VersionDate = versionDate; } - if (string.IsNullOrEmpty(GetServiceUrl())) { SetServiceUrl(defaultServiceUrl); @@ -169,13 +169,10 @@ public bool Message(Callback callback, string workspaceId, Mess req.OnResponse = OnMessageResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/message", workspaceId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/message", workspaceId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnMessageResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -261,13 +258,10 @@ public bool ListWorkspaces(Callback callback, long? pageLim req.OnResponse = OnListWorkspacesResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/workspaces", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/workspaces"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListWorkspacesResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -373,13 +367,10 @@ public bool CreateWorkspace(Callback callback, string name = null, st req.OnResponse = OnCreateWorkspaceResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/workspaces", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/workspaces"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateWorkspaceResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -467,13 +458,10 @@ public bool GetWorkspace(Callback callback, string workspaceId, bool? req.OnResponse = OnGetWorkspaceResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}", workspaceId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}", workspaceId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetWorkspaceResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -593,13 +581,10 @@ public bool UpdateWorkspace(Callback callback, string workspaceId, st req.OnResponse = OnUpdateWorkspaceResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}", workspaceId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}", workspaceId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateWorkspaceResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -666,13 +651,10 @@ public bool DeleteWorkspace(Callback callback, string workspaceId) req.OnResponse = OnDeleteWorkspaceResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}", workspaceId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}", workspaceId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteWorkspaceResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -769,13 +751,10 @@ public bool ListIntents(Callback callback, string workspaceId, req.OnResponse = OnListIntentsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/intents", workspaceId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/intents", workspaceId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListIntentsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -864,13 +843,10 @@ public bool CreateIntent(Callback callback, string workspaceId, string i req.OnResponse = OnCreateIntentResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/intents", workspaceId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/intents", workspaceId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateIntentResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -954,13 +930,10 @@ public bool GetIntent(Callback callback, string workspaceId, string inte req.OnResponse = OnGetIntentResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/intents/{1}", workspaceId, intent), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/intents/{1}", workspaceId, intent); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetIntentResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1051,13 +1024,10 @@ public bool UpdateIntent(Callback callback, string workspaceId, string i req.OnResponse = OnUpdateIntentResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/intents/{1}", workspaceId, intent), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/intents/{1}", workspaceId, intent); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateIntentResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1127,13 +1097,10 @@ public bool DeleteIntent(Callback callback, string workspaceId, string i req.OnResponse = OnDeleteIntentResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/intents/{1}", workspaceId, intent), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/intents/{1}", workspaceId, intent); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteIntentResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1225,13 +1192,10 @@ public bool ListExamples(Callback callback, string workspaceI req.OnResponse = OnListExamplesResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/intents/{1}/examples", workspaceId, intent), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/intents/{1}/examples", workspaceId, intent); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListExamplesResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1319,13 +1283,10 @@ public bool CreateExample(Callback callback, string workspaceId, string req.OnResponse = OnCreateExampleResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/intents/{1}/examples", workspaceId, intent), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/intents/{1}/examples", workspaceId, intent); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateExampleResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1404,13 +1365,10 @@ public bool GetExample(Callback callback, string workspaceId, string in req.OnResponse = OnGetExampleResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/intents/{1}/examples/{2}", workspaceId, intent, text), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/intents/{1}/examples/{2}", workspaceId, intent, text); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetExampleResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1500,13 +1458,10 @@ public bool UpdateExample(Callback callback, string workspaceId, string req.OnResponse = OnUpdateExampleResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/intents/{1}/examples/{2}", workspaceId, intent, text), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/intents/{1}/examples/{2}", workspaceId, intent, text); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateExampleResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1579,13 +1534,10 @@ public bool DeleteExample(Callback callback, string workspaceId, string req.OnResponse = OnDeleteExampleResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/intents/{1}/examples/{2}", workspaceId, intent, text), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/intents/{1}/examples/{2}", workspaceId, intent, text); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteExampleResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1675,13 +1627,10 @@ public bool ListCounterexamples(Callback callback, str req.OnResponse = OnListCounterexamplesResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/counterexamples", workspaceId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/counterexamples", workspaceId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListCounterexamplesResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1765,13 +1714,10 @@ public bool CreateCounterexample(Callback callback, string works req.OnResponse = OnCreateCounterexampleResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/counterexamples", workspaceId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/counterexamples", workspaceId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateCounterexampleResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1848,13 +1794,10 @@ public bool GetCounterexample(Callback callback, string workspac req.OnResponse = OnGetCounterexampleResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/counterexamples/{1}", workspaceId, text), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/counterexamples/{1}", workspaceId, text); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetCounterexampleResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1938,13 +1881,10 @@ public bool UpdateCounterexample(Callback callback, string works req.OnResponse = OnUpdateCounterexampleResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/counterexamples/{1}", workspaceId, text), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/counterexamples/{1}", workspaceId, text); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateCounterexampleResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2015,13 +1955,10 @@ public bool DeleteCounterexample(Callback callback, string workspaceId, req.OnResponse = OnDeleteCounterexampleResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/counterexamples/{1}", workspaceId, text), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/counterexamples/{1}", workspaceId, text); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteCounterexampleResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2118,13 +2055,10 @@ public bool ListEntities(Callback callback, string workspaceId req.OnResponse = OnListEntitiesResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/entities", workspaceId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/entities", workspaceId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListEntitiesResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2220,13 +2154,10 @@ public bool CreateEntity(Callback callback, string workspaceId, string e req.OnResponse = OnCreateEntityResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/entities", workspaceId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/entities", workspaceId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateEntityResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2310,13 +2241,10 @@ public bool GetEntity(Callback callback, string workspaceId, string enti req.OnResponse = OnGetEntityResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/entities/{1}", workspaceId, entity), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/entities/{1}", workspaceId, entity); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetEntityResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2413,13 +2341,10 @@ public bool UpdateEntity(Callback callback, string workspaceId, string e req.OnResponse = OnUpdateEntityResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/entities/{1}", workspaceId, entity), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/entities/{1}", workspaceId, entity); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateEntityResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2489,13 +2414,10 @@ public bool DeleteEntity(Callback callback, string workspaceId, string e req.OnResponse = OnDeleteEntityResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/entities/{1}", workspaceId, entity), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/entities/{1}", workspaceId, entity); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteEntityResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2579,13 +2501,10 @@ public bool ListMentions(Callback callback, string work req.OnResponse = OnListMentionsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/entities/{1}/mentions", workspaceId, entity), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/entities/{1}/mentions", workspaceId, entity); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListMentionsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2684,13 +2603,10 @@ public bool ListValues(Callback callback, string workspaceId, s req.OnResponse = OnListValuesResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/entities/{1}/values", workspaceId, entity), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/entities/{1}/values", workspaceId, entity); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListValuesResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2794,13 +2710,10 @@ public bool CreateValue(Callback callback, string workspaceId, string ent req.OnResponse = OnCreateValueResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/entities/{1}/values", workspaceId, entity), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/entities/{1}/values", workspaceId, entity); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateValueResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2886,13 +2799,10 @@ public bool GetValue(Callback callback, string workspaceId, string entity req.OnResponse = OnGetValueResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/entities/{1}/values/{2}", workspaceId, entity, value), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/entities/{1}/values/{2}", workspaceId, entity, value); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetValueResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2998,13 +2908,10 @@ public bool UpdateValue(Callback callback, string workspaceId, string ent req.OnResponse = OnUpdateValueResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/entities/{1}/values/{2}", workspaceId, entity, value), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/entities/{1}/values/{2}", workspaceId, entity, value); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateValueResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3077,13 +2984,10 @@ public bool DeleteValue(Callback callback, string workspaceId, string en req.OnResponse = OnDeleteValueResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/entities/{1}/values/{2}", workspaceId, entity, value), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/entities/{1}/values/{2}", workspaceId, entity, value); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteValueResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3178,13 +3082,10 @@ public bool ListSynonyms(Callback callback, string workspaceI req.OnResponse = OnListSynonymsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/entities/{1}/values/{2}/synonyms", workspaceId, entity, value), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/entities/{1}/values/{2}/synonyms", workspaceId, entity, value); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListSynonymsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3272,13 +3173,10 @@ public bool CreateSynonym(Callback callback, string workspaceId, string req.OnResponse = OnCreateSynonymResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/entities/{1}/values/{2}/synonyms", workspaceId, entity, value), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/entities/{1}/values/{2}/synonyms", workspaceId, entity, value); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateSynonymResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3360,13 +3258,10 @@ public bool GetSynonym(Callback callback, string workspaceId, string en req.OnResponse = OnGetSynonymResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/entities/{1}/values/{2}/synonyms/{3}", workspaceId, entity, value, synonym), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/entities/{1}/values/{2}/synonyms/{3}", workspaceId, entity, value, synonym); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetSynonymResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3455,13 +3350,10 @@ public bool UpdateSynonym(Callback callback, string workspaceId, string req.OnResponse = OnUpdateSynonymResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/entities/{1}/values/{2}/synonyms/{3}", workspaceId, entity, value, synonym), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/entities/{1}/values/{2}/synonyms/{3}", workspaceId, entity, value, synonym); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateSynonymResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3537,13 +3429,10 @@ public bool DeleteSynonym(Callback callback, string workspaceId, string req.OnResponse = OnDeleteSynonymResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/entities/{1}/values/{2}/synonyms/{3}", workspaceId, entity, value, synonym), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/entities/{1}/values/{2}/synonyms/{3}", workspaceId, entity, value, synonym); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteSynonymResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3632,13 +3521,10 @@ public bool ListDialogNodes(Callback callback, string work req.OnResponse = OnListDialogNodesResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/dialog_nodes", workspaceId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/dialog_nodes", workspaceId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListDialogNodesResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3783,13 +3669,10 @@ public bool CreateDialogNode(Callback callback, string workspaceId, req.OnResponse = OnCreateDialogNodeResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/dialog_nodes", workspaceId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/dialog_nodes", workspaceId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateDialogNodeResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3865,13 +3748,10 @@ public bool GetDialogNode(Callback callback, string workspaceId, str req.OnResponse = OnGetDialogNodeResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/dialog_nodes/{1}", workspaceId, dialogNode), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/dialog_nodes/{1}", workspaceId, dialogNode); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetDialogNodeResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4019,13 +3899,10 @@ public bool UpdateDialogNode(Callback callback, string workspaceId, req.OnResponse = OnUpdateDialogNodeResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/dialog_nodes/{1}", workspaceId, dialogNode), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/dialog_nodes/{1}", workspaceId, dialogNode); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateDialogNodeResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4095,13 +3972,10 @@ public bool DeleteDialogNode(Callback callback, string workspaceId, stri req.OnResponse = OnDeleteDialogNodeResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/dialog_nodes/{1}", workspaceId, dialogNode), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/dialog_nodes/{1}", workspaceId, dialogNode); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteDialogNodeResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4193,13 +4067,10 @@ public bool ListLogs(Callback callback, string workspaceId, strin req.OnResponse = OnListLogsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/workspaces/{0}/logs", workspaceId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/workspaces/{0}/logs", workspaceId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListLogsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4290,13 +4161,10 @@ public bool ListAllLogs(Callback callback, string filter, string req.OnResponse = OnListAllLogsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/logs", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/logs"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListAllLogsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4370,13 +4238,10 @@ public bool DeleteUserData(Callback callback, string customerId) req.OnResponse = OnDeleteUserDataResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/user_data", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/user_data"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteUserDataResponse(RESTConnector.Request req, RESTConnector.Response resp) diff --git a/Scripts/Services/Assistant/V2/AssistantService.cs b/Scripts/Services/Assistant/V2/AssistantService.cs index e3f09c4a7..a5bc7fcf7 100644 --- a/Scripts/Services/Assistant/V2/AssistantService.cs +++ b/Scripts/Services/Assistant/V2/AssistantService.cs @@ -72,6 +72,7 @@ public AssistantService(string versionDate) : this(versionDate, ConfigBasedAuthe public AssistantService(string versionDate, Authenticator authenticator) : base(versionDate, authenticator, serviceId) { Authenticator = authenticator; + if (string.IsNullOrEmpty(versionDate)) { throw new ArgumentNullException("A versionDate (format `yyyy-mm-dd`) is required to create an instance of AssistantService"); @@ -81,7 +82,6 @@ public AssistantService(string versionDate, Authenticator authenticator) : base( VersionDate = versionDate; } - if (string.IsNullOrEmpty(GetServiceUrl())) { SetServiceUrl(defaultServiceUrl); @@ -132,13 +132,10 @@ public bool CreateSession(Callback callback, string assistantId req.OnResponse = OnCreateSessionResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v2/assistants/{0}/sessions", assistantId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v2/assistants/{0}/sessions", assistantId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateSessionResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -211,13 +208,10 @@ public bool DeleteSession(Callback callback, string assistantId, string req.OnResponse = OnDeleteSessionResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v2/assistants/{0}/sessions/{1}", assistantId, sessionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v2/assistants/{0}/sessions/{1}", assistantId, sessionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteSessionResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -305,13 +299,10 @@ public bool Message(Callback callback, string assistantId, stri req.OnResponse = OnMessageResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v2/assistants/{0}/sessions/{1}/message", assistantId, sessionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v2/assistants/{0}/sessions/{1}/message", assistantId, sessionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnMessageResponse(RESTConnector.Request req, RESTConnector.Response resp) diff --git a/Scripts/Services/CompareComply/V1/CompareComplyService.cs b/Scripts/Services/CompareComply/V1/CompareComplyService.cs index 190c1e379..4d437d7b3 100644 --- a/Scripts/Services/CompareComply/V1/CompareComplyService.cs +++ b/Scripts/Services/CompareComply/V1/CompareComplyService.cs @@ -72,6 +72,7 @@ public CompareComplyService(string versionDate) : this(versionDate, ConfigBasedA public CompareComplyService(string versionDate, Authenticator authenticator) : base(versionDate, authenticator, serviceId) { Authenticator = authenticator; + if (string.IsNullOrEmpty(versionDate)) { throw new ArgumentNullException("A versionDate (format `yyyy-mm-dd`) is required to create an instance of CompareComplyService"); @@ -81,7 +82,6 @@ public CompareComplyService(string versionDate, Authenticator authenticator) : b VersionDate = versionDate; } - if (string.IsNullOrEmpty(GetServiceUrl())) { SetServiceUrl(defaultServiceUrl); @@ -140,13 +140,10 @@ public bool ConvertToHtml(Callback callback, System.IO.MemoryStream req.OnResponse = OnConvertToHtmlResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/html_conversion", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/html_conversion"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnConvertToHtmlResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -225,13 +222,10 @@ public bool ClassifyElements(Callback callback, System.IO.Memory req.OnResponse = OnClassifyElementsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/element_classification", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/element_classification"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnClassifyElementsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -310,13 +304,10 @@ public bool ExtractTables(Callback callback, System.IO.MemoryStream req.OnResponse = OnExtractTablesResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/tables", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/tables"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnExtractTablesResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -413,13 +404,10 @@ public bool CompareDocuments(Callback callback, System.IO.MemoryS req.OnResponse = OnCompareDocumentsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/comparison", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/comparison"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCompareDocumentsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -500,13 +488,10 @@ public bool AddFeedback(Callback callback, FeedbackDataInput fee req.OnResponse = OnAddFeedbackResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/feedback", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/feedback"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnAddFeedbackResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -672,13 +657,10 @@ public bool ListFeedback(Callback callback, string feedbackType = req.OnResponse = OnListFeedbackResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/feedback", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/feedback"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListFeedbackResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -751,13 +733,10 @@ public bool GetFeedback(Callback callback, string feedbackId, strin req.OnResponse = OnGetFeedbackResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/feedback/{0}", feedbackId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/feedback/{0}", feedbackId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetFeedbackResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -830,13 +809,10 @@ public bool DeleteFeedback(Callback callback, string feedbackId req.OnResponse = OnDeleteFeedbackResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/feedback/{0}", feedbackId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/feedback/{0}", feedbackId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteFeedbackResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -969,13 +945,10 @@ public bool CreateBatch(Callback callback, string function, System. req.OnResponse = OnCreateBatchResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/batches", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/batches"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateBatchResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1037,13 +1010,10 @@ public bool ListBatches(Callback callback) req.OnResponse = OnListBatchesResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/batches", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/batches"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListBatchesResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1108,13 +1078,10 @@ public bool GetBatch(Callback callback, string batchId) req.OnResponse = OnGetBatchResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/batches/{0}", batchId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/batches/{0}", batchId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetBatchResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1195,13 +1162,10 @@ public bool UpdateBatch(Callback callback, string batchId, string a req.OnResponse = OnUpdateBatchResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/batches/{0}", batchId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/batches/{0}", batchId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateBatchResponse(RESTConnector.Request req, RESTConnector.Response resp) diff --git a/Scripts/Services/Discovery/V1/DiscoveryService.cs b/Scripts/Services/Discovery/V1/DiscoveryService.cs index ea1650165..f8189832c 100644 --- a/Scripts/Services/Discovery/V1/DiscoveryService.cs +++ b/Scripts/Services/Discovery/V1/DiscoveryService.cs @@ -72,6 +72,7 @@ public DiscoveryService(string versionDate) : this(versionDate, ConfigBasedAuthe public DiscoveryService(string versionDate, Authenticator authenticator) : base(versionDate, authenticator, serviceId) { Authenticator = authenticator; + if (string.IsNullOrEmpty(versionDate)) { throw new ArgumentNullException("A versionDate (format `yyyy-mm-dd`) is required to create an instance of DiscoveryService"); @@ -81,7 +82,6 @@ public DiscoveryService(string versionDate, Authenticator authenticator) : base( VersionDate = versionDate; } - if (string.IsNullOrEmpty(GetServiceUrl())) { SetServiceUrl(defaultServiceUrl); @@ -144,13 +144,10 @@ public bool CreateEnvironment(Callback callback, string name, req.OnResponse = OnCreateEnvironmentResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/environments", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/environments"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateEnvironmentResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -217,13 +214,10 @@ public bool ListEnvironments(Callback callback, string req.OnResponse = OnListEnvironmentsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/environments", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/environments"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListEnvironmentsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -286,13 +280,10 @@ public bool GetEnvironment(Callback callback, string environme req.OnResponse = OnGetEnvironmentResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}", environmentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}", environmentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetEnvironmentResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -373,13 +364,10 @@ public bool UpdateEnvironment(Callback callback, string enviro req.OnResponse = OnUpdateEnvironmentResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}", environmentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}", environmentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateEnvironmentResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -442,13 +430,10 @@ public bool DeleteEnvironment(Callback callback, stri req.OnResponse = OnDeleteEnvironmentResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}", environmentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}", environmentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteEnvironmentResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -520,13 +505,10 @@ public bool ListFields(Callback callback, string e req.OnResponse = OnListFieldsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/fields", environmentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/fields", environmentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListFieldsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -625,13 +607,10 @@ public bool CreateConfiguration(Callback callback, string environ req.OnResponse = OnCreateConfigurationResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/configurations", environmentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/configurations", environmentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateConfigurationResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -701,13 +680,10 @@ public bool ListConfigurations(Callback callback, st req.OnResponse = OnListConfigurationsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/configurations", environmentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/configurations", environmentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListConfigurationsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -773,13 +749,10 @@ public bool GetConfiguration(Callback callback, string environmen req.OnResponse = OnGetConfigurationResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/configurations/{1}", environmentId, configurationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/configurations/{1}", environmentId, configurationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetConfigurationResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -880,13 +853,10 @@ public bool UpdateConfiguration(Callback callback, string environ req.OnResponse = OnUpdateConfigurationResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/configurations/{1}", environmentId, configurationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/configurations/{1}", environmentId, configurationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateConfigurationResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -957,13 +927,10 @@ public bool DeleteConfiguration(Callback callback, req.OnResponse = OnDeleteConfigurationResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/configurations/{1}", environmentId, configurationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/configurations/{1}", environmentId, configurationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteConfigurationResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1047,13 +1014,10 @@ public bool CreateCollection(Callback callback, string environmentId req.OnResponse = OnCreateCollectionResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections", environmentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections", environmentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateCollectionResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1123,13 +1087,10 @@ public bool ListCollections(Callback callback, string e req.OnResponse = OnListCollectionsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections", environmentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections", environmentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListCollectionsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1195,13 +1156,10 @@ public bool GetCollection(Callback callback, string environmentId, s req.OnResponse = OnGetCollectionResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetCollectionResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1234,12 +1192,12 @@ private void OnGetCollectionResponse(RESTConnector.Request req, RESTConnector.Re /// The callback function that is invoked when the operation completes. /// The ID of the environment. /// The ID of the collection. - /// The name of the collection. + /// The name of the collection. (optional, default to ) /// A description of the collection. (optional, default to ) /// The ID of the configuration in which the collection is to be updated. /// (optional, default to ) /// Collection - public bool UpdateCollection(Callback callback, string environmentId, string collectionId, string name, string description = null, string configurationId = null) + public bool UpdateCollection(Callback callback, string environmentId, string collectionId, string name = null, string description = null, string configurationId = null) { if (callback == null) throw new ArgumentNullException("`callback` is required for `UpdateCollection`"); @@ -1282,13 +1240,10 @@ public bool UpdateCollection(Callback callback, string environmentId req.OnResponse = OnUpdateCollectionResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateCollectionResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1354,13 +1309,10 @@ public bool DeleteCollection(Callback callback, string req.OnResponse = OnDeleteCollectionResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteCollectionResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1428,13 +1380,10 @@ public bool ListCollectionFields(Callback callback req.OnResponse = OnListCollectionFieldsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/fields", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/fields", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListCollectionFieldsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1503,13 +1452,10 @@ public bool ListExpansions(Callback callback, string environmentId, req.OnResponse = OnListExpansionsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/expansions", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/expansions", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListExpansionsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1600,13 +1546,10 @@ public bool CreateExpansions(Callback callback, string environmentId req.OnResponse = OnCreateExpansionsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/expansions", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/expansions", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateExpansionsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1675,13 +1618,10 @@ public bool DeleteExpansions(Callback callback, string environmentId, st req.OnResponse = OnDeleteExpansionsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/expansions", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/expansions", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteExpansionsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1749,13 +1689,10 @@ public bool GetTokenizationDictionaryStatus(Callback ca req.OnResponse = OnGetTokenizationDictionaryStatusResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/word_lists/tokenization_dictionary", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/word_lists/tokenization_dictionary", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetTokenizationDictionaryStatusResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1833,13 +1770,10 @@ public bool CreateTokenizationDictionary(Callback callb req.OnResponse = OnCreateTokenizationDictionaryResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/word_lists/tokenization_dictionary", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/word_lists/tokenization_dictionary", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateTokenizationDictionaryResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1907,13 +1841,10 @@ public bool DeleteTokenizationDictionary(Callback callback, string envir req.OnResponse = OnDeleteTokenizationDictionaryResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/word_lists/tokenization_dictionary", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/word_lists/tokenization_dictionary", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteTokenizationDictionaryResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1981,13 +1912,10 @@ public bool GetStopwordListStatus(Callback callback, st req.OnResponse = OnGetStopwordListStatusResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/word_lists/stopwords", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/word_lists/stopwords", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetStopwordListStatusResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2066,13 +1994,10 @@ public bool CreateStopwordList(Callback callback, strin req.OnResponse = OnCreateStopwordListResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/word_lists/stopwords", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/word_lists/stopwords", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateStopwordListResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2141,13 +2066,10 @@ public bool DeleteStopwordList(Callback callback, string environmentId, req.OnResponse = OnDeleteStopwordListResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/word_lists/stopwords", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/word_lists/stopwords", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteStopwordListResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2256,13 +2178,10 @@ public bool AddDocument(Callback callback, string environmentI req.OnResponse = OnAddDocumentResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/documents", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/documents", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnAddDocumentResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2335,13 +2254,10 @@ public bool GetDocumentStatus(Callback callback, string environm req.OnResponse = OnGetDocumentStatusResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/documents/{2}", environmentId, collectionId, documentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/documents/{2}", environmentId, collectionId, documentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetDocumentStatusResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2435,13 +2351,10 @@ public bool UpdateDocument(Callback callback, string environme req.OnResponse = OnUpdateDocumentResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/documents/{2}", environmentId, collectionId, documentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/documents/{2}", environmentId, collectionId, documentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateDocumentResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2513,13 +2426,10 @@ public bool DeleteDocument(Callback callback, string env req.OnResponse = OnDeleteDocumentResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/documents/{2}", environmentId, collectionId, documentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/documents/{2}", environmentId, collectionId, documentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteDocumentResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2698,13 +2608,10 @@ public bool Query(Callback callback, string environmentId, string req.OnResponse = OnQueryResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/query", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/query", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnQueryResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2886,13 +2793,10 @@ public bool QueryNotices(Callback callback, string environ req.OnResponse = OnQueryNoticesResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/notices", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/notices", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnQueryNoticesResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2928,7 +2832,8 @@ private void OnQueryNoticesResponse(RESTConnector.Request req, RESTConnector.Res /// /// The callback function that is invoked when the operation completes. /// The ID of the environment. - /// A comma-separated list of collection IDs to be queried against. + /// A comma-separated list of collection IDs to be queried against. + /// (optional) /// A cacheable query that excludes documents that don't mention the query content. Filter /// searches are better for metadata-type searches and for assessing the concepts in the data set. /// (optional) @@ -2984,7 +2889,7 @@ private void OnQueryNoticesResponse(RESTConnector.Request req, RESTConnector.Res /// If `true`, queries are not stored in the Discovery **Logs** endpoint. /// (optional, default to false) /// QueryResponse - public bool FederatedQuery(Callback callback, string environmentId, string collectionIds, string filter = null, string query = null, string naturalLanguageQuery = null, bool? passages = null, string aggregation = null, long? count = null, string _return = null, long? offset = null, string sort = null, bool? highlight = null, string passagesFields = null, long? passagesCount = null, long? passagesCharacters = null, bool? deduplicate = null, string deduplicateField = null, bool? similar = null, string similarDocumentIds = null, string similarFields = null, string bias = null, bool? xWatsonLoggingOptOut = null) + public bool FederatedQuery(Callback callback, string environmentId, string collectionIds = null, string filter = null, string query = null, string naturalLanguageQuery = null, bool? passages = null, string aggregation = null, long? count = null, string _return = null, long? offset = null, string sort = null, bool? highlight = null, string passagesFields = null, long? passagesCount = null, long? passagesCharacters = null, bool? deduplicate = null, string deduplicateField = null, bool? similar = null, string similarDocumentIds = null, string similarFields = null, string bias = null, bool? xWatsonLoggingOptOut = null) { if (callback == null) throw new ArgumentNullException("`callback` is required for `FederatedQuery`"); @@ -3064,13 +2969,10 @@ public bool FederatedQuery(Callback callback, string environmentI req.OnResponse = OnFederatedQueryResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/query", environmentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/query", environmentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnFederatedQueryResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3232,13 +3134,10 @@ public bool FederatedQueryNotices(Callback callback, strin req.OnResponse = OnFederatedQueryNoticesResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/notices", environmentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/notices", environmentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnFederatedQueryNoticesResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3326,13 +3225,10 @@ public bool GetAutocompletion(Callback callback, string environment req.OnResponse = OnGetAutocompletionResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/autocompletion", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/autocompletion", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetAutocompletionResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3400,13 +3296,10 @@ public bool ListTrainingData(Callback callback, string environm req.OnResponse = OnListTrainingDataResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/training_data", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/training_data", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListTrainingDataResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3490,13 +3383,10 @@ public bool AddTrainingData(Callback callback, string environment req.OnResponse = OnAddTrainingDataResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/training_data", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/training_data", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnAddTrainingDataResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3564,13 +3454,10 @@ public bool DeleteAllTrainingData(Callback callback, string environmentI req.OnResponse = OnDeleteAllTrainingDataResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/training_data", environmentId, collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/training_data", environmentId, collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteAllTrainingDataResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3641,13 +3528,10 @@ public bool GetTrainingData(Callback callback, string environment req.OnResponse = OnGetTrainingDataResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/training_data/{2}", environmentId, collectionId, queryId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/training_data/{2}", environmentId, collectionId, queryId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetTrainingDataResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3718,13 +3602,10 @@ public bool DeleteTrainingData(Callback callback, string environmentId, req.OnResponse = OnDeleteTrainingDataResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/training_data/{2}", environmentId, collectionId, queryId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/training_data/{2}", environmentId, collectionId, queryId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteTrainingDataResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3795,13 +3676,10 @@ public bool ListTrainingExamples(Callback callback, string req.OnResponse = OnListTrainingExamplesResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/training_data/{2}/examples", environmentId, collectionId, queryId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/training_data/{2}/examples", environmentId, collectionId, queryId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListTrainingExamplesResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3886,13 +3764,10 @@ public bool CreateTrainingExample(Callback callback, string env req.OnResponse = OnCreateTrainingExampleResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/training_data/{2}/examples", environmentId, collectionId, queryId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/training_data/{2}/examples", environmentId, collectionId, queryId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateTrainingExampleResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3966,13 +3841,10 @@ public bool DeleteTrainingExample(Callback callback, string environmentI req.OnResponse = OnDeleteTrainingExampleResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/training_data/{2}/examples/{3}", environmentId, collectionId, queryId, exampleId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/training_data/{2}/examples/{3}", environmentId, collectionId, queryId, exampleId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteTrainingExampleResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4057,13 +3929,10 @@ public bool UpdateTrainingExample(Callback callback, string env req.OnResponse = OnUpdateTrainingExampleResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/training_data/{2}/examples/{3}", environmentId, collectionId, queryId, exampleId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/training_data/{2}/examples/{3}", environmentId, collectionId, queryId, exampleId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateTrainingExampleResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4137,13 +4006,10 @@ public bool GetTrainingExample(Callback callback, string enviro req.OnResponse = OnGetTrainingExampleResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/collections/{1}/training_data/{2}/examples/{3}", environmentId, collectionId, queryId, exampleId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/collections/{1}/training_data/{2}/examples/{3}", environmentId, collectionId, queryId, exampleId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetTrainingExampleResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4217,13 +4083,10 @@ public bool DeleteUserData(Callback callback, string customerId) req.OnResponse = OnDeleteUserDataResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/user_data", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/user_data"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteUserDataResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4301,13 +4164,10 @@ public bool CreateEvent(Callback callback, string type, Eve req.OnResponse = OnCreateEventResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/events", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/events"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateEventResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4403,13 +4263,10 @@ public bool QueryLog(Callback callback, string filter = null, req.OnResponse = OnQueryLogResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/logs", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/logs"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnQueryLogResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4488,13 +4345,10 @@ public bool GetMetricsQuery(Callback callback, DateTime? startTi req.OnResponse = OnGetMetricsQueryResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/metrics/number_of_queries", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/metrics/number_of_queries"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetMetricsQueryResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4575,13 +4429,10 @@ public bool GetMetricsQueryEvent(Callback callback, DateTime? st req.OnResponse = OnGetMetricsQueryEventResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/metrics/number_of_queries_with_event", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/metrics/number_of_queries_with_event"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetMetricsQueryEventResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4661,13 +4512,10 @@ public bool GetMetricsQueryNoResults(Callback callback, DateTime req.OnResponse = OnGetMetricsQueryNoResultsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/metrics/number_of_queries_with_no_search_results", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/metrics/number_of_queries_with_no_search_results"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetMetricsQueryNoResultsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4748,13 +4596,10 @@ public bool GetMetricsEventRate(Callback callback, DateTime? sta req.OnResponse = OnGetMetricsEventRateResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/metrics/event_rate", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/metrics/event_rate"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetMetricsEventRateResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4824,13 +4669,10 @@ public bool GetMetricsQueryTokenEvent(Callback callback, lo req.OnResponse = OnGetMetricsQueryTokenEventResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/metrics/top_query_tokens_with_event_rate", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/metrics/top_query_tokens_with_event_rate"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetMetricsQueryTokenEventResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4897,13 +4739,10 @@ public bool ListCredentials(Callback callback, string environme req.OnResponse = OnListCredentialsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/credentials", environmentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/credentials", environmentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListCredentialsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4996,13 +4835,10 @@ public bool CreateCredentials(Callback callback, string enviro req.OnResponse = OnCreateCredentialsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/credentials", environmentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/credentials", environmentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateCredentialsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -5073,13 +4909,10 @@ public bool GetCredentials(Callback callback, string environme req.OnResponse = OnGetCredentialsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/credentials/{1}", environmentId, credentialId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/credentials/{1}", environmentId, credentialId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetCredentialsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -5174,13 +5007,10 @@ public bool UpdateCredentials(Callback callback, string enviro req.OnResponse = OnUpdateCredentialsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/credentials/{1}", environmentId, credentialId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/credentials/{1}", environmentId, credentialId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateCredentialsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -5248,13 +5078,10 @@ public bool DeleteCredentials(Callback callback, string envir req.OnResponse = OnDeleteCredentialsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/credentials/{1}", environmentId, credentialId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/credentials/{1}", environmentId, credentialId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteCredentialsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -5319,13 +5146,10 @@ public bool ListGateways(Callback callback, string environmentId) req.OnResponse = OnListGatewaysResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/gateways", environmentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/gateways", environmentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListGatewaysResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -5398,13 +5222,10 @@ public bool CreateGateway(Callback callback, string environmentId, stri req.OnResponse = OnCreateGatewayResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/gateways", environmentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/gateways", environmentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateGatewayResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -5472,13 +5293,10 @@ public bool GetGateway(Callback callback, string environmentId, string req.OnResponse = OnGetGatewayResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/gateways/{1}", environmentId, gatewayId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/gateways/{1}", environmentId, gatewayId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetGatewayResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -5546,13 +5364,10 @@ public bool DeleteGateway(Callback callback, string environmentId req.OnResponse = OnDeleteGatewayResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/environments/{0}/gateways/{1}", environmentId, gatewayId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/environments/{0}/gateways/{1}", environmentId, gatewayId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteGatewayResponse(RESTConnector.Request req, RESTConnector.Response resp) diff --git a/Scripts/Services/LanguageTranslator/V3/LanguageTranslatorService.cs b/Scripts/Services/LanguageTranslator/V3/LanguageTranslatorService.cs index c8441f8d6..a9fe3e417 100644 --- a/Scripts/Services/LanguageTranslator/V3/LanguageTranslatorService.cs +++ b/Scripts/Services/LanguageTranslator/V3/LanguageTranslatorService.cs @@ -72,6 +72,7 @@ public LanguageTranslatorService(string versionDate) : this(versionDate, ConfigB public LanguageTranslatorService(string versionDate, Authenticator authenticator) : base(versionDate, authenticator, serviceId) { Authenticator = authenticator; + if (string.IsNullOrEmpty(versionDate)) { throw new ArgumentNullException("A versionDate (format `yyyy-mm-dd`) is required to create an instance of LanguageTranslatorService"); @@ -81,7 +82,6 @@ public LanguageTranslatorService(string versionDate, Authenticator authenticator VersionDate = versionDate; } - if (string.IsNullOrEmpty(GetServiceUrl())) { SetServiceUrl(defaultServiceUrl); @@ -144,13 +144,10 @@ public bool Translate(Callback callback, List text, s req.OnResponse = OnTranslateResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v3/translate", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v3/translate"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnTranslateResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -213,13 +210,10 @@ public bool ListIdentifiableLanguages(Callback callback) req.OnResponse = OnListIdentifiableLanguagesResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v3/identifiable_languages", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v3/identifiable_languages"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListIdentifiableLanguagesResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -287,13 +281,10 @@ public bool Identify(Callback callback, string text) req.OnResponse = OnIdentifyResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v3/identify", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v3/identify"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnIdentifyResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -373,13 +364,10 @@ public bool ListModels(Callback callback, string source = nul req.OnResponse = OnListModelsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v3/models", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v3/models"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListModelsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -485,13 +473,10 @@ public bool CreateModel(Callback callback, string baseModelId, req.OnResponse = OnCreateModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v3/models", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v3/models"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -556,13 +541,10 @@ public bool DeleteModel(Callback callback, string modelId) req.OnResponse = OnDeleteModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v3/models/{0}", modelId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v3/models/{0}", modelId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -629,13 +611,10 @@ public bool GetModel(Callback callback, string modelId) req.OnResponse = OnGetModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v3/models/{0}", modelId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v3/models/{0}", modelId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -697,13 +676,10 @@ public bool ListDocuments(Callback callback) req.OnResponse = OnListDocumentsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v3/documents", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v3/documents"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListDocumentsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -805,13 +781,10 @@ public bool TranslateDocument(Callback callback, System.IO.Memor req.OnResponse = OnTranslateDocumentResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v3/documents", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v3/documents"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnTranslateDocumentResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -876,13 +849,10 @@ public bool GetDocumentStatus(Callback callback, string document req.OnResponse = OnGetDocumentStatusResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v3/documents/{0}", documentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v3/documents/{0}", documentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetDocumentStatusResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -947,13 +917,10 @@ public bool DeleteDocument(Callback callback, string documentId) req.OnResponse = OnDeleteDocumentResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v3/documents/{0}", documentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v3/documents/{0}", documentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteDocumentResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1027,13 +994,10 @@ public bool GetTranslatedDocument(Callback callback, string documentId, req.OnResponse = OnGetTranslatedDocumentResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v3/documents/{0}/translated_document", documentId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v3/documents/{0}/translated_document", documentId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetTranslatedDocumentResponse(RESTConnector.Request req, RESTConnector.Response resp) diff --git a/Scripts/Services/NaturalLanguageClassifier/V1/NaturalLanguageClassifierService.cs b/Scripts/Services/NaturalLanguageClassifier/V1/NaturalLanguageClassifierService.cs index c844b4fb3..2f05653e3 100644 --- a/Scripts/Services/NaturalLanguageClassifier/V1/NaturalLanguageClassifierService.cs +++ b/Scripts/Services/NaturalLanguageClassifier/V1/NaturalLanguageClassifierService.cs @@ -34,8 +34,6 @@ public partial class NaturalLanguageClassifierService : BaseService private const string serviceId = "natural_language_classifier"; private const string defaultServiceUrl = "https://gateway.watsonplatform.net/natural-language-classifier/api"; - #region VersionDate - #endregion #region DisableSslVerification private bool disableSslVerification = false; @@ -52,13 +50,11 @@ public bool DisableSslVerification /// /// NaturalLanguageClassifierService constructor. /// - public NaturalLanguageClassifierService() : this(ConfigBasedAuthenticatorFactory.GetAuthenticator(serviceId)) {} /// /// NaturalLanguageClassifierService constructor. /// - /// The service authenticator. public NaturalLanguageClassifierService(Authenticator authenticator) : base(authenticator, serviceId) { @@ -118,13 +114,10 @@ public bool Classify(Callback callback, string classifierId, str req.OnResponse = OnClassifyResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/classifiers/{0}/classify", classifierId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/classifiers/{0}/classify", classifierId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnClassifyResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -201,13 +194,10 @@ public bool ClassifyCollection(Callback callback, stri req.OnResponse = OnClassifyCollectionResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/classifiers/{0}/classify_collection", classifierId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/classifiers/{0}/classify_collection", classifierId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnClassifyCollectionResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -290,13 +280,10 @@ public bool CreateClassifier(Callback callback, System.IO.MemoryStre req.OnResponse = OnCreateClassifierResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/classifiers", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/classifiers"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateClassifierResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -357,13 +344,10 @@ public bool ListClassifiers(Callback callback) req.OnResponse = OnListClassifiersResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/classifiers", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/classifiers"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListClassifiersResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -427,13 +411,10 @@ public bool GetClassifier(Callback callback, string classifierId) req.OnResponse = OnGetClassifierResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/classifiers/{0}", classifierId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/classifiers/{0}", classifierId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetClassifierResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -495,13 +476,10 @@ public bool DeleteClassifier(Callback callback, string classifierId) req.OnResponse = OnDeleteClassifierResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/classifiers/{0}", classifierId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/classifiers/{0}", classifierId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteClassifierResponse(RESTConnector.Request req, RESTConnector.Response resp) diff --git a/Scripts/Services/NaturalLanguageUnderstanding/V1/NaturalLanguageUnderstandingService.cs b/Scripts/Services/NaturalLanguageUnderstanding/V1/NaturalLanguageUnderstandingService.cs index be77684b2..11ae1ce4b 100644 --- a/Scripts/Services/NaturalLanguageUnderstanding/V1/NaturalLanguageUnderstandingService.cs +++ b/Scripts/Services/NaturalLanguageUnderstanding/V1/NaturalLanguageUnderstandingService.cs @@ -72,6 +72,7 @@ public NaturalLanguageUnderstandingService(string versionDate) : this(versionDat public NaturalLanguageUnderstandingService(string versionDate, Authenticator authenticator) : base(versionDate, authenticator, serviceId) { Authenticator = authenticator; + if (string.IsNullOrEmpty(versionDate)) { throw new ArgumentNullException("A versionDate (format `yyyy-mm-dd`) is required to create an instance of NaturalLanguageUnderstandingService"); @@ -81,7 +82,6 @@ public NaturalLanguageUnderstandingService(string versionDate, Authenticator aut VersionDate = versionDate; } - if (string.IsNullOrEmpty(GetServiceUrl())) { SetServiceUrl(defaultServiceUrl); @@ -187,13 +187,10 @@ public bool Analyze(Callback callback, Features features, strin req.OnResponse = OnAnalyzeResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/analyze", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/analyze"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnAnalyzeResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -257,13 +254,10 @@ public bool ListModels(Callback callback) req.OnResponse = OnListModelsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/models", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/models"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListModelsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -328,13 +322,10 @@ public bool DeleteModel(Callback callback, string modelId) req.OnResponse = OnDeleteModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/models/{0}", modelId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/models/{0}", modelId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteModelResponse(RESTConnector.Request req, RESTConnector.Response resp) diff --git a/Scripts/Services/PersonalityInsights/V3/PersonalityInsightsService.cs b/Scripts/Services/PersonalityInsights/V3/PersonalityInsightsService.cs index b7a56605a..2589807ee 100644 --- a/Scripts/Services/PersonalityInsights/V3/PersonalityInsightsService.cs +++ b/Scripts/Services/PersonalityInsights/V3/PersonalityInsightsService.cs @@ -72,6 +72,7 @@ public PersonalityInsightsService(string versionDate) : this(versionDate, Config public PersonalityInsightsService(string versionDate, Authenticator authenticator) : base(versionDate, authenticator, serviceId) { Authenticator = authenticator; + if (string.IsNullOrEmpty(versionDate)) { throw new ArgumentNullException("A versionDate (format `yyyy-mm-dd`) is required to create an instance of PersonalityInsightsService"); @@ -81,7 +82,6 @@ public PersonalityInsightsService(string versionDate, Authenticator authenticato VersionDate = versionDate; } - if (string.IsNullOrEmpty(GetServiceUrl())) { SetServiceUrl(defaultServiceUrl); @@ -217,13 +217,10 @@ public bool Profile(Callback callback, Content content, string contentT req.OnResponse = OnProfileResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v3/profile", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v3/profile"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnProfileResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -379,13 +376,10 @@ public bool ProfileAsCsv(Callback callback, Content cont req.OnResponse = OnProfileAsCsvResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v3/profile", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v3/profile"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnProfileAsCsvResponse(RESTConnector.Request req, RESTConnector.Response resp) diff --git a/Scripts/Services/SpeechToText/V1/SpeechToTextService.cs b/Scripts/Services/SpeechToText/V1/SpeechToTextService.cs index 76434aadd..7fae9dbe6 100644 --- a/Scripts/Services/SpeechToText/V1/SpeechToTextService.cs +++ b/Scripts/Services/SpeechToText/V1/SpeechToTextService.cs @@ -34,8 +34,6 @@ public partial class SpeechToTextService : BaseService private const string serviceId = "speech_to_text"; private const string defaultServiceUrl = "https://stream.watsonplatform.net/speech-to-text/api"; - #region VersionDate - #endregion #region DisableSslVerification private bool disableSslVerification = false; @@ -52,13 +50,11 @@ public bool DisableSslVerification /// /// SpeechToTextService constructor. /// - public SpeechToTextService() : this(ConfigBasedAuthenticatorFactory.GetAuthenticator(serviceId)) {} /// /// SpeechToTextService constructor. /// - /// The service authenticator. public SpeechToTextService(Authenticator authenticator) : base(authenticator, serviceId) { @@ -108,13 +104,10 @@ public bool ListModels(Callback callback) req.OnResponse = OnListModelsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/models", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/models"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListModelsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -183,13 +176,10 @@ public bool GetModel(Callback callback, string modelId) req.OnResponse = OnGetModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/models/{0}", modelId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/models/{0}", modelId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -542,13 +532,10 @@ public bool Recognize(Callback callback, byte[] audio, req.OnResponse = OnRecognizeResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/recognize", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/recognize"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnRecognizeResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -654,13 +641,10 @@ public bool RegisterCallback(Callback callback, string callbackU req.OnResponse = OnRegisterCallbackResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/register_callback", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/register_callback"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnRegisterCallbackResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -733,13 +717,10 @@ public bool UnregisterCallback(Callback callback, string callbackUrl) req.OnResponse = OnUnregisterCallbackResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/unregister_callback", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/unregister_callback"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUnregisterCallbackResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1171,13 +1152,10 @@ public bool CreateJob(Callback callback, byte[] audio, string co req.OnResponse = OnCreateJobResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/recognitions", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/recognitions"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateJobResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1246,13 +1224,10 @@ public bool CheckJobs(Callback callback) req.OnResponse = OnCheckJobsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/recognitions", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/recognitions"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCheckJobsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1328,13 +1303,10 @@ public bool CheckJob(Callback callback, string id) req.OnResponse = OnCheckJobResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/recognitions/{0}", id), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/recognitions/{0}", id); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCheckJobResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1405,13 +1377,10 @@ public bool DeleteJob(Callback callback, string id) req.OnResponse = OnDeleteJobResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/recognitions/{0}", id), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/recognitions/{0}", id); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteJobResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1524,13 +1493,10 @@ public bool CreateLanguageModel(Callback callback, string name, s req.OnResponse = OnCreateLanguageModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/customizations", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/customizations"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateLanguageModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1604,13 +1570,10 @@ public bool ListLanguageModels(Callback callback, string languag req.OnResponse = OnListLanguageModelsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/customizations", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/customizations"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListLanguageModelsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1680,13 +1643,10 @@ public bool GetLanguageModel(Callback callback, string customizat req.OnResponse = OnGetLanguageModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetLanguageModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1757,13 +1717,10 @@ public bool DeleteLanguageModel(Callback callback, string customizationI req.OnResponse = OnDeleteLanguageModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteLanguageModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1884,13 +1841,10 @@ public bool TrainLanguageModel(Callback callback, string custo req.OnResponse = OnTrainLanguageModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/train", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/train", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnTrainLanguageModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1962,13 +1916,10 @@ public bool ResetLanguageModel(Callback callback, string customizationId req.OnResponse = OnResetLanguageModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/reset", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/reset", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnResetLanguageModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2048,13 +1999,10 @@ public bool UpgradeLanguageModel(Callback callback, string customization req.OnResponse = OnUpgradeLanguageModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/upgrade_model", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/upgrade_model", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpgradeLanguageModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2125,13 +2073,10 @@ public bool ListCorpora(Callback callback, string customizationId) req.OnResponse = OnListCorporaResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/corpora", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/corpora", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListCorporaResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2271,13 +2216,10 @@ public bool AddCorpus(Callback callback, string customizationId, string req.OnResponse = OnAddCorpusResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/corpora/{1}", customizationId, corpusName), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/corpora/{1}", customizationId, corpusName); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnAddCorpusResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2351,13 +2293,10 @@ public bool GetCorpus(Callback callback, string customizationId, string req.OnResponse = OnGetCorpusResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/corpora/{1}", customizationId, corpusName), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/corpora/{1}", customizationId, corpusName); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetCorpusResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2434,13 +2373,10 @@ public bool DeleteCorpus(Callback callback, string customizationId, stri req.OnResponse = OnDeleteCorpusResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/corpora/{1}", customizationId, corpusName), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/corpora/{1}", customizationId, corpusName); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteCorpusResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2533,13 +2469,10 @@ public bool ListWords(Callback callback, string customizationId, string w req.OnResponse = OnListWordsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/words", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/words", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListWordsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2660,13 +2593,10 @@ public bool AddWords(Callback callback, string customizationId, List callback, string customizationId, string wo req.OnResponse = OnAddWordResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/words/{1}", customizationId, wordName), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/words/{1}", customizationId, wordName); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnAddWordResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2877,13 +2804,10 @@ public bool GetWord(Callback callback, string customizationId, string word req.OnResponse = OnGetWordResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/words/{1}", customizationId, wordName), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/words/{1}", customizationId, wordName); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetWordResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -2962,13 +2886,10 @@ public bool DeleteWord(Callback callback, string customizationId, string req.OnResponse = OnDeleteWordResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/words/{1}", customizationId, wordName), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/words/{1}", customizationId, wordName); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteWordResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3039,13 +2960,10 @@ public bool ListGrammars(Callback callback, string customizationId) req.OnResponse = OnListGrammarsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/grammars", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/grammars", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListGrammarsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3185,13 +3103,10 @@ public bool AddGrammar(Callback callback, string customizationId, string req.OnResponse = OnAddGrammarResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/grammars/{1}", customizationId, grammarName), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/grammars/{1}", customizationId, grammarName); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnAddGrammarResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3265,13 +3180,10 @@ public bool GetGrammar(Callback callback, string customizationId, strin req.OnResponse = OnGetGrammarResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/grammars/{1}", customizationId, grammarName), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/grammars/{1}", customizationId, grammarName); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetGrammarResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3348,13 +3260,10 @@ public bool DeleteGrammar(Callback callback, string customizationId, str req.OnResponse = OnDeleteGrammarResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/grammars/{1}", customizationId, grammarName), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/grammars/{1}", customizationId, grammarName); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteGrammarResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3446,13 +3355,10 @@ public bool CreateAcousticModel(Callback callback, string name, s req.OnResponse = OnCreateAcousticModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/acoustic_customizations", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/acoustic_customizations"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateAcousticModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3526,13 +3432,10 @@ public bool ListAcousticModels(Callback callback, string languag req.OnResponse = OnListAcousticModelsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/acoustic_customizations", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/acoustic_customizations"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListAcousticModelsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3602,13 +3505,10 @@ public bool GetAcousticModel(Callback callback, string customizat req.OnResponse = OnGetAcousticModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/acoustic_customizations/{0}", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/acoustic_customizations/{0}", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetAcousticModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3679,13 +3579,10 @@ public bool DeleteAcousticModel(Callback callback, string customizationI req.OnResponse = OnDeleteAcousticModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/acoustic_customizations/{0}", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/acoustic_customizations/{0}", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteAcousticModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3802,13 +3699,10 @@ public bool TrainAcousticModel(Callback callback, string custo req.OnResponse = OnTrainAcousticModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/acoustic_customizations/{0}/train", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/acoustic_customizations/{0}/train", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnTrainAcousticModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3882,13 +3776,10 @@ public bool ResetAcousticModel(Callback callback, string customizationId req.OnResponse = OnResetAcousticModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/acoustic_customizations/{0}/reset", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/acoustic_customizations/{0}/reset", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnResetAcousticModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -3993,13 +3884,10 @@ public bool UpgradeAcousticModel(Callback callback, string customization req.OnResponse = OnUpgradeAcousticModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/acoustic_customizations/{0}/upgrade_model", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/acoustic_customizations/{0}/upgrade_model", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpgradeAcousticModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4072,13 +3960,10 @@ public bool ListAudio(Callback callback, string customizationId) req.OnResponse = OnListAudioResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/acoustic_customizations/{0}/audio", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/acoustic_customizations/{0}/audio", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListAudioResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4284,13 +4169,10 @@ public bool AddAudio(Callback callback, string customizationId, string a req.OnResponse = OnAddAudioResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/acoustic_customizations/{0}/audio/{1}", customizationId, audioName), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/acoustic_customizations/{0}/audio/{1}", customizationId, audioName); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnAddAudioResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4377,13 +4259,10 @@ public bool GetAudio(Callback callback, string customizationId, st req.OnResponse = OnGetAudioResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/acoustic_customizations/{0}/audio/{1}", customizationId, audioName), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/acoustic_customizations/{0}/audio/{1}", customizationId, audioName); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetAudioResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4462,13 +4341,10 @@ public bool DeleteAudio(Callback callback, string customizationId, strin req.OnResponse = OnDeleteAudioResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/acoustic_customizations/{0}/audio/{1}", customizationId, audioName), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/acoustic_customizations/{0}/audio/{1}", customizationId, audioName); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteAudioResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -4545,13 +4421,10 @@ public bool DeleteUserData(Callback callback, string customerId) req.OnResponse = OnDeleteUserDataResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/user_data", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/user_data"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteUserDataResponse(RESTConnector.Request req, RESTConnector.Response resp) diff --git a/Scripts/Services/TextToSpeech/V1/TextToSpeechService.cs b/Scripts/Services/TextToSpeech/V1/TextToSpeechService.cs index 14f2e1a4e..847077547 100644 --- a/Scripts/Services/TextToSpeech/V1/TextToSpeechService.cs +++ b/Scripts/Services/TextToSpeech/V1/TextToSpeechService.cs @@ -34,8 +34,6 @@ public partial class TextToSpeechService : BaseService private const string serviceId = "text_to_speech"; private const string defaultServiceUrl = "https://stream.watsonplatform.net/text-to-speech/api"; - #region VersionDate - #endregion #region DisableSslVerification private bool disableSslVerification = false; @@ -52,13 +50,11 @@ public bool DisableSslVerification /// /// TextToSpeechService constructor. /// - public TextToSpeechService() : this(ConfigBasedAuthenticatorFactory.GetAuthenticator(serviceId)) {} /// /// TextToSpeechService constructor. /// - /// The service authenticator. public TextToSpeechService(Authenticator authenticator) : base(authenticator, serviceId) { @@ -109,13 +105,10 @@ public bool ListVoices(Callback callback) req.OnResponse = OnListVoicesResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/voices", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/voices"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListVoicesResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -193,13 +186,10 @@ public bool GetVoice(Callback callback, string voice, string customizatio req.OnResponse = OnGetVoiceResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/voices/{0}", voice), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/voices/{0}", voice); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetVoiceResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -347,13 +337,10 @@ public bool Synthesize(Callback callback, string text, string accept = n req.OnResponse = OnSynthesizeResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/synthesize", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/synthesize"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnSynthesizeResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -441,13 +428,10 @@ public bool GetPronunciation(Callback callback, string text, stri req.OnResponse = OnGetPronunciationResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/pronunciation", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/pronunciation"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetPronunciationResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -533,13 +517,10 @@ public bool CreateVoiceModel(Callback callback, string name, string req.OnResponse = OnCreateVoiceModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/customizations", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/customizations"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateVoiceModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -615,13 +596,10 @@ public bool ListVoiceModels(Callback callback, string language = nu req.OnResponse = OnListVoiceModelsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/customizations", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/customizations"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListVoiceModelsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -727,13 +705,10 @@ public bool UpdateVoiceModel(Callback callback, string customizationId, req.OnResponse = OnUpdateVoiceModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateVoiceModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -805,13 +780,10 @@ public bool GetVoiceModel(Callback callback, string customizationId) req.OnResponse = OnGetVoiceModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetVoiceModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -882,13 +854,10 @@ public bool DeleteVoiceModel(Callback callback, string customizationId) req.OnResponse = OnDeleteVoiceModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteVoiceModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -992,13 +961,10 @@ public bool AddWords(Callback callback, string customizationId, List callback, string customizationId) req.OnResponse = OnListWordsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/words", customizationId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/words", customizationId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListWordsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1187,13 +1150,10 @@ public bool AddWord(Callback callback, string customizationId, string wo req.OnResponse = OnAddWordResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/words/{1}", customizationId, word), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/words/{1}", customizationId, word); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnAddWordResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1268,13 +1228,10 @@ public bool GetWord(Callback callback, string customizationId, stri req.OnResponse = OnGetWordResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/words/{1}", customizationId, word), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/words/{1}", customizationId, word); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetWordResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1348,13 +1305,10 @@ public bool DeleteWord(Callback callback, string customizationId, string req.OnResponse = OnDeleteWordResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v1/customizations/{0}/words/{1}", customizationId, word), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v1/customizations/{0}/words/{1}", customizationId, word); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteWordResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1431,13 +1385,10 @@ public bool DeleteUserData(Callback callback, string customerId) req.OnResponse = OnDeleteUserDataResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v1/user_data", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v1/user_data"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteUserDataResponse(RESTConnector.Request req, RESTConnector.Response resp) diff --git a/Scripts/Services/ToneAnalyzer/V3/ToneAnalyzerService.cs b/Scripts/Services/ToneAnalyzer/V3/ToneAnalyzerService.cs index e1a4f41e4..b501494a6 100644 --- a/Scripts/Services/ToneAnalyzer/V3/ToneAnalyzerService.cs +++ b/Scripts/Services/ToneAnalyzer/V3/ToneAnalyzerService.cs @@ -72,6 +72,7 @@ public ToneAnalyzerService(string versionDate) : this(versionDate, ConfigBasedAu public ToneAnalyzerService(string versionDate, Authenticator authenticator) : base(versionDate, authenticator, serviceId) { Authenticator = authenticator; + if (string.IsNullOrEmpty(versionDate)) { throw new ArgumentNullException("A versionDate (format `yyyy-mm-dd`) is required to create an instance of ToneAnalyzerService"); @@ -81,7 +82,6 @@ public ToneAnalyzerService(string versionDate, Authenticator authenticator) : ba VersionDate = versionDate; } - if (string.IsNullOrEmpty(GetServiceUrl())) { SetServiceUrl(defaultServiceUrl); @@ -188,13 +188,10 @@ public bool Tone(Callback callback, ToneInput toneInput, string co req.OnResponse = OnToneResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v3/tone", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v3/tone"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnToneResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -297,13 +294,10 @@ public bool ToneChat(Callback callback, List utter req.OnResponse = OnToneChatResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v3/tone_chat", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v3/tone_chat"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnToneChatResponse(RESTConnector.Request req, RESTConnector.Response resp) diff --git a/Scripts/Services/VisualRecognition/V3/VisualRecognitionService.cs b/Scripts/Services/VisualRecognition/V3/VisualRecognitionService.cs index 5a0bfa4b2..9877d9500 100644 --- a/Scripts/Services/VisualRecognition/V3/VisualRecognitionService.cs +++ b/Scripts/Services/VisualRecognition/V3/VisualRecognitionService.cs @@ -71,6 +71,7 @@ public VisualRecognitionService(string versionDate) : this(versionDate, ConfigBa public VisualRecognitionService(string versionDate, Authenticator authenticator) : base(versionDate, authenticator, serviceId) { Authenticator = authenticator; + if (string.IsNullOrEmpty(versionDate)) { throw new ArgumentNullException("A versionDate (format `yyyy-mm-dd`) is required to create an instance of VisualRecognitionService"); @@ -80,7 +81,6 @@ public VisualRecognitionService(string versionDate, Authenticator authenticator) VersionDate = versionDate; } - if (string.IsNullOrEmpty(GetServiceUrl())) { SetServiceUrl(defaultServiceUrl); @@ -175,13 +175,10 @@ public bool Classify(Callback callback, System.IO.MemoryStream req.OnResponse = OnClassifyResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v3/classify", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v3/classify"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnClassifyResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -294,13 +291,10 @@ public bool CreateClassifier(Callback callback, string name, Diction req.OnResponse = OnCreateClassifierResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v3/classifiers", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v3/classifiers"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateClassifierResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -366,13 +360,10 @@ public bool ListClassifiers(Callback callback, bool? verbose = null req.OnResponse = OnListClassifiersResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v3/classifiers", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v3/classifiers"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListClassifiersResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -437,13 +428,10 @@ public bool GetClassifier(Callback callback, string classifierId) req.OnResponse = OnGetClassifierResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v3/classifiers/{0}", classifierId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v3/classifiers/{0}", classifierId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetClassifierResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -553,13 +541,10 @@ public bool UpdateClassifier(Callback callback, string classifierId, req.OnResponse = OnUpdateClassifierResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v3/classifiers/{0}", classifierId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v3/classifiers/{0}", classifierId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateClassifierResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -622,13 +607,10 @@ public bool DeleteClassifier(Callback callback, string classifierId) req.OnResponse = OnDeleteClassifierResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v3/classifiers/{0}", classifierId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v3/classifiers/{0}", classifierId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteClassifierResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -694,13 +676,10 @@ public bool GetCoreMlModel(Callback callback, string classifierId) req.OnResponse = OnGetCoreMlModelResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v3/classifiers/{0}/core_ml_model", classifierId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v3/classifiers/{0}/core_ml_model", classifierId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetCoreMlModelResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -764,13 +743,10 @@ public bool DeleteUserData(Callback callback, string customerId) req.OnResponse = OnDeleteUserDataResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v3/user_data", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v3/user_data"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteUserDataResponse(RESTConnector.Request req, RESTConnector.Response resp) diff --git a/Scripts/Services/VisualRecognition/V4/VisualRecognitionService.cs b/Scripts/Services/VisualRecognition/V4/VisualRecognitionService.cs index 80b1b2e79..e62e63ba6 100644 --- a/Scripts/Services/VisualRecognition/V4/VisualRecognitionService.cs +++ b/Scripts/Services/VisualRecognition/V4/VisualRecognitionService.cs @@ -16,7 +16,6 @@ */ using System.Collections.Generic; -using System.IO; using System.Text; using IBM.Cloud.SDK; using IBM.Cloud.SDK.Authentication; @@ -74,6 +73,7 @@ public VisualRecognitionService(string versionDate) : this(versionDate, ConfigBa public VisualRecognitionService(string versionDate, Authenticator authenticator) : base(versionDate, authenticator, serviceId) { Authenticator = authenticator; + if (string.IsNullOrEmpty(versionDate)) { throw new ArgumentNullException("A versionDate (format `yyyy-mm-dd`) is required to create an instance of VisualRecognitionService"); @@ -83,7 +83,6 @@ public VisualRecognitionService(string versionDate, Authenticator authenticator) VersionDate = versionDate; } - if (string.IsNullOrEmpty(GetServiceUrl())) { SetServiceUrl(defaultServiceUrl); @@ -178,13 +177,10 @@ public bool Analyze(Callback callback, List collectionI req.OnResponse = OnAnalyzeResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v4/analyze", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v4/analyze"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnAnalyzeResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -264,13 +260,10 @@ public bool CreateCollection(Callback callback, string name = null, req.OnResponse = OnCreateCollectionResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v4/collections", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v4/collections"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnCreateCollectionResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -332,13 +325,10 @@ public bool ListCollections(Callback callback) req.OnResponse = OnListCollectionsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v4/collections", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v4/collections"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListCollectionsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -403,13 +393,10 @@ public bool GetCollection(Callback callback, string collectionId) req.OnResponse = OnGetCollectionResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v4/collections/{0}", collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v4/collections/{0}", collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetCollectionResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -489,13 +476,10 @@ public bool UpdateCollection(Callback callback, string collectionId, req.OnResponse = OnUpdateCollectionResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v4/collections/{0}", collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v4/collections/{0}", collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnUpdateCollectionResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -560,13 +544,10 @@ public bool DeleteCollection(Callback callback, string collectionId) req.OnResponse = OnDeleteCollectionResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v4/collections/{0}", collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v4/collections/{0}", collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteCollectionResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -671,13 +652,10 @@ public bool AddImages(Callback callback, string collectionId, req.OnResponse = OnAddImagesResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v4/collections/{0}/images", collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v4/collections/{0}/images", collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnAddImagesResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -742,13 +720,10 @@ public bool ListImages(Callback callback, string collectionId) req.OnResponse = OnListImagesResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v4/collections/{0}/images", collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v4/collections/{0}/images", collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnListImagesResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -816,13 +791,10 @@ public bool GetImageDetails(Callback callback, string collectionId req.OnResponse = OnGetImageDetailsResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v4/collections/{0}/images/{1}", collectionId, imageId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v4/collections/{0}/images/{1}", collectionId, imageId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetImageDetailsResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -890,13 +862,10 @@ public bool DeleteImage(Callback callback, string collectionId, string i req.OnResponse = OnDeleteImageResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v4/collections/{0}/images/{1}", collectionId, imageId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v4/collections/{0}/images/{1}", collectionId, imageId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteImageResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -969,13 +938,10 @@ public bool GetJpegImage(Callback callback, string collectionId, string req.OnResponse = OnGetJpegImageResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v4/collections/{0}/images/{1}/jpeg", collectionId, imageId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v4/collections/{0}/images/{1}/jpeg", collectionId, imageId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnGetJpegImageResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1032,13 +998,10 @@ public bool Train(Callback callback, string collectionId) req.OnResponse = OnTrainResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v4/collections/{0}/train", collectionId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v4/collections/{0}/train", collectionId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnTrainResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1121,13 +1084,10 @@ public bool AddImageTrainingData(Callback callback, string req.OnResponse = OnAddImageTrainingDataResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, string.Format("/v4/collections/{0}/images/{1}/training_data", collectionId, imageId), GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + string.Format("/v4/collections/{0}/images/{1}/training_data", collectionId, imageId); + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnAddImageTrainingDataResponse(RESTConnector.Request req, RESTConnector.Response resp) @@ -1201,13 +1161,10 @@ public bool DeleteUserData(Callback callback, string customerId) req.OnResponse = OnDeleteUserDataResponse; - RESTConnector connector = RESTConnector.GetConnector(Authenticator, "/v4/user_data", GetServiceUrl()); - if (connector == null) - { - return false; - } + Connector.URL = GetServiceUrl() + "/v4/user_data"; + Authenticator.Authenticate(Connector); - return connector.Send(req); + return Connector.Send(req); } private void OnDeleteUserDataResponse(RESTConnector.Request req, RESTConnector.Response resp)