Ejemplo n.º 1
0
        private void ProcessDeepLink(string url = "")
        {
            string linkUrl = url;

            #if UNITY_ANDROID
            linkUrl = CustomUrlSchemeAndroid.GetLaunchedUrl(true);
            CustomUrlSchemeAndroid.ClearSavedData();
            #endif


            #if UNITY_IOS
            //there is no link override on iOS
            #endif


            if (!string.IsNullOrEmpty(linkUrl))
            {
                Debug.Log("Unity URL returned: " + linkUrl);

                Dictionary <string, string> urlParams = linkUrl.ParseURI();

                //blindcode as unable to test this without API update
                if (urlParams.ContainsKey("code"))
                {
                    //string code = split[1];
                    AuthorizationCodeReceived(urlParams["code"]);
                }
                else if (linkUrl.Contains("requestId="))
                {
                    string transferId = urlParams["requestId"];

                    foreach (TransferAPIRequest r in currentTransferAPIRequests)
                    {
                        Debug.Log("Current requests id: " + r.requestId);
                    }

                    //get request from ongoing
                    TransferAPIRequest transferRequest = currentTransferAPIRequests.Find(t => t.requestId == transferId);
                    if (transferRequest == null)
                    {
                        Debug.LogError("Transfer id is invalid: " + transferId);
                        transferRequest.failedDelegate("Invalid transfer id: " + transferId);
                    }

                    if (urlParams.ContainsKey("error"))
                    {
                        //all requests are validated positivelly currently
                        transferRequest.failedDelegate(urlParams["error"]);
                    }
                    else
                    {
                        transferRequest.txId = urlParams["txId"];
                        Debug.Log("tx id:" + transferRequest.txId);

                        transferRequest.successDelegate(transferRequest.txId);
                    }

                    currentTransferAPIRequests.Remove(transferRequest);
                }
                else
                {
                    Debug.Log("NOT IMPLEMENTED URL: " + linkUrl);
                }
            }
        }
Ejemplo n.º 2
0
        private IEnumerator CreateTransferRequestCall(TransferAPIRequest request)
        {
            Debug.Log("CreateTransferRequestCall");

            Dictionary <string, string> headers = new Dictionary <string, string>(AuthorizationHeader);

            headers.Add("Authorization", "Bearer " + AccessToken);


            Dictionary <string, object> data = new Dictionary <string, object>();

            data.Add("tokens", request.tokens);
            if (!string.IsNullOrEmpty(request.description))
            {
                data.Add("description", request.description);
            }
            data.Add("app_id", QuartersInit.Instance.APP_ID);


            string dataJson = JsonConvert.SerializeObject(data);

            Debug.Log(dataJson);
            byte[] dataBytes = System.Text.Encoding.UTF8.GetBytes(dataJson);


            WWW www = new WWW(API_URL + "requests", dataBytes, headers);

            Debug.Log(www.url);

            while (!www.isDone)
            {
                yield return(new WaitForEndOfFrame());
            }

            if (!string.IsNullOrEmpty(www.error))
            {
                Debug.LogError(www.error);

                request.failedDelegate("Creating transfer failed: " + www.error);
            }
            else
            {
                Debug.Log(www.text);

                string response = www.text;
                Debug.Log("Response: " + response);

                TransferRequest transferRequest = new TransferRequest(response);

                request.requestId = transferRequest.id;
                Debug.Log("request id is: " + transferRequest.id);
                currentTransferAPIRequests.Add(request);

                //continue outh forward
                string url = QUARTERS_URL + "/requests/" + transferRequest.id + "?inline=true" + "&redirect_uri=" + URL_SCHEME;
                Application.OpenURL(url);


                //OnSucess(transferRequest);
            }
        }