/// <summary> /// Create a WSConnector for the given service and function. /// </summary> /// <param name="serviceID">The ID of the service.</param> /// <param name="function">The name of the function to connect.</param> /// <param name="args">Additional function arguments.</param> /// <returns>The WSConnector object or null or error.</returns> public static WSConnector CreateConnector(Credentials credentials, string url, string function, string args) { WSConnector connector = new WSConnector(); connector.URL = FixupURL(credentials.Url) + function + args; connector.Authentication = credentials; return connector; }
/// <summary> /// Create a WSConnector for the given service and function. /// </summary> /// <param name="credentials">The credentials for the service.</param> /// <param name="function">The name of the function to connect.</param> /// <param name="args">Additional function arguments.</param> /// <returns>The WSConnector object or null or error.</returns> public static WSConnector CreateConnector(Credentials credentials, string function, string args) { WSConnector connector = new WSConnector(); if (credentials.HasAuthorizationToken()) { args += "&watson-token=" + credentials.AuthenticationToken; } else if (credentials.HasCredentials()) { connector.Authentication = credentials; } connector.URL = FixupURL(credentials.Url) + function + args; return(connector); }
/// <summary> /// Create a WSConnector for the given service and function. /// </summary> /// <param name="serviceID">The ID of the service.</param> /// <param name="function">The name of the function to connect.</param> /// <param name="args">Additional function arguments.</param> /// <returns>The WSConnector object or null or error.</returns> public static WSConnector CreateConnector(string serviceID, string function, string args) { WSConnector connector = null; Config cfg = Config.Instance; Config.CredentialInfo cred = cfg.FindCredentials(serviceID); if (cred == null) { Log.Error("Config", "Failed to find BLueMix Credentials for service {0}.", serviceID); return(null); } connector = new WSConnector(); connector.URL = FixupURL(cred.m_URL) + function + args; connector.Authentication = new Credentials(cred.m_User, cred.m_Password); return(connector); }
/// <summary> /// Create a WSConnector for the given service and function. /// </summary> /// <param name="credentials">The credentials for the service.</param> /// <param name="function">The name of the function to connect.</param> /// <param name="args">Additional function arguments.</param> /// <returns>The WSConnector object or null or error.</returns> public static WSConnector CreateConnector(Credentials credentials, string function, string args) { WSConnector connector = new WSConnector(); if (credentials.HasWatsonAuthenticationToken()) { args += "&watson-token=" + credentials.WatsonAuthenticationToken; } else if (credentials.HasCredentials()) { connector.Authentication = credentials; } else if (credentials.HasIamTokenData()) { credentials.GetToken(); connector.Headers.Add(AUTHENTICATION_AUTHORIZATION_HEADER, string.Format("Bearer {0}", credentials.IamAccessToken)); } connector.URL = FixupURL(credentials.Url) + function + args; return(connector); }
/// <summary> /// Create a WSConnector for the given service and function. /// </summary> /// <param name="serviceID">The ID of the service.</param> /// <param name="function">The name of the function to connect.</param> /// <param name="args">Additional function arguments.</param> /// <returns>The WSConnector object or null or error.</returns> public static WSConnector CreateConnector(string serviceID, string function, string args) { WSConnector connector = null; string connectorID = serviceID + function; Config cfg = Config.Instance; string serviceType = null; if (cfg.EnableGateway && sm_GatewayServiceTypes.TryGetValue(connectorID, out serviceType)) { connector = new WSConnector(); connector.UsingGateway = true; connector.URL = FixupURL(cfg.GatewayURL) + "/" + serviceType; // + args; Dictionary <string, object> auth = new Dictionary <string, object>(); auth["ROBOT_KEY"] = cfg.ProductKey; auth["MAC_ID"] = "UnitySDK"; connector.Send(new TextMessage(MiniJSON.Json.Serialize(auth)), true); // just queue, we want to let the user do any fix-ups before we actually try to connect return(connector); } Config.CredentialInfo cred = cfg.FindCredentials(serviceID); if (cred == null) { Log.Error("Config", "Failed to find BLueMix Credentials for service {0}.", serviceID); return(null); } connector = new WSConnector(); connector.UsingGateway = false; connector.URL = FixupURL(cred.m_URL) + function + args; connector.Authentication = new Credentials(cred.m_User, cred.m_Password); return(connector); }