private void OnKnetikWebCall(KnetikWebCallEvent e) { if (string.IsNullOrEmpty(BaseUrl)) { throw new KnetikException("You must have a valid base URL for the REST Api!"); } StringBuilder urlBuilder = new StringBuilder(); urlBuilder.Append(BaseUrl); urlBuilder.Append(e.WebPath); if (e.QueryParams.Count > 0) { urlBuilder.Append("?"); List <string> keys = e.QueryParams.Keys.ToList(); for (int i = 0; i < keys.Count; ++i) { urlBuilder.AppendFormat("{0}={1}", keys[i], e.QueryParams[keys[i]]); if (i < (keys.Count - 1)) { urlBuilder.Append("&"); } } } string fullUrl = urlBuilder.ToString(); KnetikLogger.Log(string.Format("Sending request to URL {0}", fullUrl)); UnityWebRequest webRequest = new UnityWebRequest(fullUrl, GetUnityVerbFromRequestType(e.RequestType)); if (!string.IsNullOrEmpty(e.PostBody)) { webRequest.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(e.PostBody)) { contentType = ContentType }; } webRequest.downloadHandler = new DownloadHandlerBuffer(); UpdateParamsForAuth(e.HeaderParams, e.AuthSettings); // add header parameters, if any foreach (KeyValuePair <string, string> param in e.HeaderParams) { webRequest.SetRequestHeader(param.Key, param.Value); } // Set the content type, always webRequest.SetRequestHeader(AcceptTypeHeader, ContentType); webRequest.SetRequestHeader(ContentTypeHeader, ContentType); StartCoroutine(HandleAsyncWebRequest(e.Context, webRequest)); }
private static void GetUserComplete(long responseCode, UserResource response) { KnetikLogger.Log("*** USER RETRIEVED SUCCESSFULLY ***"); KnetikLogger.Log(response.ToString()); KnetikLogger.Log("=== POLYMORPHIC TEST CONFIRMATION ==="); foreach (string key in response.AdditionalProperties.Keys) { KnetikLogger.Log(string.Format("{0}\n{1}", key, response.AdditionalProperties[key])); } }
private static void OnClientAuthenticateResponse(KnetikClientAuthenticateResponseEvent <OAuth2Resource> e) { KnetikLogger.Log("*** CLIENT AUTHENTICATED SUCCESSFULLY ***"); GetUserId(); }