Exemple #1
0
    public void AddToTape(DataspinWebRequest request)
    {
        Dictionary <string, object> record = new Dictionary <string, object>();

        //if(request.Dict != null) record["json"] = Json.Serialize(request.Dict);
        if (request.URL != null)
        {
            record["url"] = request.URL;
        }
        if (request.ExtraData != null)
        {
            record["extra_data"] = request.ExtraData;
        }

        record["http_method"] = (int)request.HTTPMethod;
        record["ds_method"]   = (int)request.DSMethod;

        if (jsonList == null)
        {
            jsonList = new List <object>();
        }
        jsonList.Add(record);         //Add record to list

        StartSaveTimer();
    }
Exemple #2
0
    public void RequestDidComplete(DataspinWebRequest req)
    {
        if (req.isError())
        {
            Log("Connection Error! Method: " + req.DSMethod.ToString() + ", Error Code: " + req.Error.Code.ToString() + ", Message: " + req.Error.Message);
        }
        else
        {
            Dictionary <string, object> dict = null;
            try {
                dict = Json.Deserialize(req.Response) as Dictionary <string, object>;
            }
            catch {
                Log("Error! Couldn't parse JSON to dictionary! Method: " + req.DSMethod.ToString() + ", ResponseJson: " + req.Response);
            }

            if (dict != null)
            {
                if ((string)dict["result"] == "OK")
                {
                    Log("Request " + req.DSMethod.ToString() + " complete!");
                    try {
                        switch (req.DSMethod)
                        {
                        case DataspinRequestMethod.Dataspin_GetUid:
                            try {
                                uid = GetInt(dict["uid"]).ToString();
                                DataspinUidRetrieved(uid);
                                Log("Uid set - " + uid);
                                if (CurrentConfiguration.ShouldStartSessionAuto)
                                {
                                    StartSession();
                                }
                            }
                            catch {
                                Log("Server response error! Parameter 'uid' missing! Method: " + req.DSMethod.ToString() + ", ResponseJson: " + req.Response);
                            }
                            break;

                        case DataspinRequestMethod.Dataspin_StartSession:
                            sessionId           = ((int)(long)dict["sessid"]).ToString();
                            isSessionInProgress = true;
                            DataspinTape.Instance.GetTape();
                            DataspinSessionStarted();
                            Log("Session started! Id: " + sessionId);
                            break;

                        case DataspinRequestMethod.Dataspin_EndSession:
                            isSessionInProgress = false;
                            DataspinSessionEnded();
                            sessionId = null;
                            Log("Session ended!");
                            break;

                        case DataspinRequestMethod.Dataspin_CustomEvent:
                            Log("Custom Event sent!");
                            break;

                        case DataspinRequestMethod.Dataspin_GetBalance:
                            DataspinBank.Instance.setDataspinBank(GetInt(dict["total_coins"]), GetInt(dict["total_coins_B"]), GetInt(dict["purchases_no"]));
                            DataspinBankChanged();
                            Log("Get Balance finished!");
                            break;

                        case DataspinRequestMethod.Dataspin_AddBalance:

                            DataspinBank.Instance.setDataspinBank(GetInt(dict["purse_a"]), GetInt(dict["purse_b"]));
                            //I'm not sure about that. Still doesn't work on vr2 domain. I suppose Marcin changed it only in beta DS version.

                            DataspinBankChanged();
                            Log("Add Balance success!");
                            break;

                        case DataspinRequestMethod.Dataspin_GetAppItems:
                            try {
                                DataspinBank.Instance.SetPurchasesList((List <object>)dict["purchases"]);
                            }
                            catch {
                                Log("Get App items requested without purchases.");
                            }

                            DataspinBank.Instance.SetItemsList((List <object>)dict["items"]);
                            Log("Get App Items success!");
                            break;

                        case DataspinRequestMethod.Dataspin_PurchaseItem:                                  //It would be purrrfect if server could return purchase or purchasesArray
                            if ((string)dict["message"] == "ok")
                            {
                                DataspinPurchaseSuccess();
                                Log("Purchase successful!");
                            }
                            else
                            {
                                Log("Something is wrong with purchase!");
                                DataspinPurchaseFailed((string)dict["message"]);
                            }
                            break;

                        case DataspinRequestMethod.Dataspin_CheckCoupon:
                            if ((string)dict["message"] == "BAD CODE")
                            {
                                DataspinCouponDeclined("BAD CODE");
                                Log("Bad code entered!");
                            }
                            else if ((string)dict["message"] == "CODE EXPIRED")
                            {
                                DataspinCouponDeclined("CODE EXPIRED");
                                Log("Entered code is expired!");
                            }
                            else if ((string)dict["message"] == "CODE NOT ACTIVE YET")
                            {
                                DataspinCouponDeclined("CODE NOT ACTIVE YET");
                                Log("Entered code is not ready!");
                            }
                            else
                            {
                                Log("Good code!");
                                if (GetInt(dict["used_already"]) != 0)
                                {
                                    DataspinCouponDeclined("USED ALREADY");
                                    Log("But already used!");
                                }
                                else
                                {
                                    Log("And code is valid!");
                                    DataspinCouponAccepted((string)dict["params"]);
                                }
                            }
                            break;

                        case DataspinRequestMethod.Dataspin_RegisterMail:
                            Log("Mail registered!");
                            DataspinMailRegistered();
                            break;

                        case DataspinRequestMethod.Dataspin_RegisterNickname:
                            if (((string)dict["message"]).Contains("NOT UNIQUE"))
                            {
                                DataspinNicknameChangeFailed();
                            }
                            else
                            {
                                DataspinNicknameChanged((string)dict["nick"]);
                            }
                            break;

                        case DataspinRequestMethod.Dataspin_RegisterGPlusId:
                            DataspinGooglePlusIdRegistered();
                            break;

                        case DataspinRequestMethod.Dataspin_GetGooglePlusIds:
                            Log("Google plus ids retrieved!");
                            DataspinGooglePlusIds((List <object>)dict["ids"]);
                            break;

                        case DataspinRequestMethod.Dataspin_PostRace:
                            Log("Info about race sent! Total distance: " + ((long)dict["distance"]).ToString());
                            break;

                        case DataspinRequestMethod.Dataspin_UpdateAdID:
                            Log("Ad id registered!");
                            break;

                        default:
                            LogWarning("Unsupported response! Message: " + (string)dict["message"]);
                            break;
                        }
                    }
                    catch (Exception e) {
                        //LogWarning("Response parameters couldn't be parsed.");
                        DataspinError(new Error("Couldn't parse json. MSG: " + (string)dict["message"] + " Details: " + e.Message + ", " + e.StackTrace, req.DSMethod));
                    }
                }
                else if ((string)dict["result"] == "ERROR")
                {
                    if (req.DSMethod == DataspinRequestMethod.Dataspin_PurchaseItem)
                    {
                        if (((string)dict["message"]).Contains("not enough B"))
                        {
                            DataspinPurchaseFailed("notEnoughCurrency_B");
                        }
                        else if (((string)dict["message"]).Contains("not enough A"))
                        {
                            DataspinPurchaseFailed("notEnoughCurrency_A");
                        }
                        else
                        {
                            DataspinError(new Error(req.Response, req.DSMethod));
                        }
                    }
                }
                else
                {
                    if (req.DSMethod == DataspinRequestMethod.Dataspin_RegisterNickname)
                    {
                        if (((string)dict["message"]).Contains("NOT UNIQUE"))
                        {
                            DataspinNicknameChangeFailed();
                        }
                    }
                    else
                    {
                        DataspinError(new Error(req.Response, req.DSMethod));
                    }
                }
            }
            else
            {
                DataspinError(new Error("Dictionary is null!"));
            }
        }
    }
Exemple #3
0
    void OnGUI()
    {
        if (shouldShowGUI)
        {
            if (GUI.Button(new Rect(spacing, 10, buttonWidth, buttonHeight), "Start Session"))
            {
                Dataspin.Instance.StartSession();
            }

            if (GUI.Button(new Rect(spacing, 50, buttonWidth, buttonHeight), "End Session"))
            {
                Dataspin.Instance.EndSession();
            }

            if (GUI.Button(new Rect(spacing, 90, buttonWidth, buttonHeight), "Get Balance"))
            {
                Dataspin.Instance.GetBalance();
            }

            if (GUI.Button(new Rect(spacing, 130, buttonWidth, buttonHeight), "Get App Items"))
            {
                Dataspin.Instance.GetAppItems();
            }

            if (GUI.Button(new Rect(spacing, 170, buttonWidth, buttonHeight), "Custom Event"))
            {
                Dataspin.Instance.CustomEvent(customEventId);
            }

            if (GUI.Button(new Rect(spacing, 210, buttonWidth, buttonHeight), "Post Race"))
            {
                Dataspin.Instance.PostRace(raceScore, raceDistance);
            }

            if (GUI.Button(new Rect(spacing, 250, buttonWidth, buttonHeight), "Report Nofif"))
            {
                Dataspin.Instance.ReportNotification(DataspinNotificationDeliveryType.tapped);
            }

            if (GUI.Button(new Rect(spacing, 290, buttonWidth, buttonHeight), "Add to tape"))
            {
                Dictionary <string, object> jsonDict = new Dictionary <string, object>();

                jsonDict.Add("action", "scores");
                jsonDict.Add("uid", Dataspin.Instance.Uid);
                jsonDict.Add("s", 452345);

                DataspinWebRequest req = new DataspinWebRequest(jsonDict, HttpRequestMethod.HttpMethod_Get,
                                                                DataspinRequestMethod.Dataspin_PostRace);
                DataspinTape.Instance.AddToTape(req);
            }

            if (GUI.Button(new Rect(spacing, 330, buttonWidth, buttonHeight), "Register Ad Id"))
            {
                Dataspin.Instance.RegisterAdID("abcd");
            }

            if (GUI.Button(new Rect(spacing * 2 + buttonWidth, 10, buttonWidth, buttonHeight), "Add Balance"))
            {
                Dataspin.Instance.AddBalance(addBalanceAmount, addBalanceSource);
            }

            if (GUI.Button(new Rect(spacing * 2 + buttonWidth, 50, buttonWidth, buttonHeight), "Purchase Item"))
            {
                Dataspin.Instance.PurchaseItem(purchaseItemSku, purchaseItemQuantity);
            }

            if (GUI.Button(new Rect(spacing * 2 + buttonWidth, 90, buttonWidth, buttonHeight), "Register G+ ID"))
            {
                Dataspin.Instance.RegisterGooglePlusId(googlePlusId);
            }

            if (GUI.Button(new Rect(spacing * 2 + buttonWidth, 130, buttonWidth, buttonHeight), "Register Mail"))
            {
                Dataspin.Instance.RegisterMail(exampleMail);
            }

            if (GUI.Button(new Rect(spacing * 2 + buttonWidth, 170, buttonWidth, buttonHeight), "Register Nick"))
            {
                Dataspin.Instance.RegisterNickname(nickname);
            }

            if (GUI.Button(new Rect(spacing * 2 + buttonWidth, 210, buttonWidth, buttonHeight), "Get G+ Ids"))
            {
                Dataspin.Instance.GetRandomGooglePlusIds(5);
            }

            if (GUI.Button(new Rect(spacing * 2 + buttonWidth, 250, buttonWidth + 25, buttonHeight), "Purchase coinpack"))
            {
                Dataspin.Instance.PurchaseCoinpack(productSKU, productSource, true);
            }

            if (GUI.Button(new Rect(spacing * 2 + buttonWidth, 290, buttonWidth, buttonHeight), "Test encrypt"))
            {
                DataspinTape.Instance.TestAES();
            }

            if (GUI.Button(new Rect(spacing * 2 + buttonWidth, 330, buttonWidth, buttonHeight), "Delete Tape"))
            {
                DataspinTape.Instance.DeleteTape();
            }
        }
    }
Exemple #4
0
 private string prepareDataspinWebRequestStoringJson(DataspinWebRequest request)
 {
     //Parse DataspinWebRequest into JSON, decode it
     return(null);
 }