Пример #1
0
    static void Get_Notification_Key_Response(object[] data, Action <object[]> concluding_method)
    {
        Response_Status status = Http_Client.Parse_Status(data[0]);

        if (status < Response_Status.Network_Error)
        {
            SimpleJSON.JSONNode raw = SimpleJSON.JSON.Parse((string)data[2]);

            if (status == Response_Status.Ok)
            {
                if (raw["notification_key"] != null)
                {
                    Debug.Log("Notification key is " + raw["notification_key"].Value);
                    concluding_method?.Invoke(new object[] { status, raw["notification_key"].Value });
                }
                else
                {
                    Debug.LogError("Correct HTTP response but notification key is null!");
                }
            }
            else
            {
                concluding_method?.Invoke(new object[] { status, raw["error"].Value });
            }
        }
    }
Пример #2
0
    static void Send_Notification_Response(object[] data, Action <object[]> concluding_method)
    {
        Response_Status status = Http_Client.Parse_Status(data[0]);

        if (status < Response_Status.Network_Error)
        {
            SimpleJSON.JSONNode raw = SimpleJSON.JSON.Parse((string)data[2]);

            if (status == Response_Status.Ok)
            {
                if (raw["failure"].Value == "0")
                {
                    Debug.Log("Success on sending notification.");
                    concluding_method?.Invoke(new object[] { status, raw["success"].Value, "0" });
                }
                else
                {
                    Debug.LogWarning("Correct HTTP response but sending failures exists! (" + raw["success"].Value + " success, " + raw["failure"].Value + " failures)");
                    concluding_method?.Invoke(new object[] { status, raw["success"].Value, raw["failure"].Value });
                }
            }
            else
            {
                concluding_method?.Invoke(new object[] { status, raw["error"].Value, "-1" });
            }
        }
    }
Пример #3
0
    // ______________________________________
    //
    // 6. NOTIFICATION SENDING.
    // ______________________________________
    //


    public static void Send_Notification(FCM_Params param)
    {
        if (param.Notification_Key == "")
        {
            Get_Notification_Key("user_id" + param.User_Id.ToString(), (object[] data_get) =>
            {
                Response_Status status_get = Http_Client.Parse_Status(data_get[0]);

                if (status_get == Response_Status.Ok)
                {
                    param.Notification_Key = (string)data_get[1];
                    Send_Notification(param);
                }
                else
                {
                    Debug.LogWarning("Could not send notification due to error on getting the notification_key!");
                    param.Concluding_Method?.Invoke(new object[] { Response_Status.HTTP_Error, "notification_key not found", "-1" });
                }
            });
            return;
        }

        string content =
            "{" +
            s + "to" + s + ":" + s + param.Notification_Key + s + "," +
            s + "data" + s +
            ":{";

        if (param.Data_Pairs != null)
        {
            foreach (KeyValuePair <string, string> data in param.Data_Pairs)
            {
                content += s + data.Key + s + ":" + s + data.Value + s + ",";
            }
        }

        if (content[content.Length - 1] == ',')
        {
            content = content.Substring(0, content.Length - 1);
        }

        content +=
            "}" +
            s + "notification" + s + ": " +
            "{" +
            s + "title" + s + ": " + s + param.Title + s + "," +
            s + "body" + s + ": " + s + param.Body + s + "," +
            s + "priority" + s + ": " + param.Priority +
            "}" +
            "}";

        Http_Client.Send_HTTP_Request(
            "https://fcm.googleapis.com/fcm/send",
            Http_Client.Request_Type.POST,
            default_header,
            Send_Notification_Response,
            param.Concluding_Method,
            content
            );
    }
Пример #4
0
 void Awake()
 {
     if (Singleton == null)
     {
         Singleton = this;
     }
 }
Пример #5
0
    public static void Update_Data(string user = "", string psswd = "", bool load = true, bool save = false, Action On_Success = null, Action OnFailure = null)
    {
        Scroll_Updater.User_Loaded = 0;

        if (user == "")
        {
            user  = User_Info.Username;
            psswd = Psswd;
        }

        string[] field_names  = { "REQUEST_TYPE", "username", "psswd" };
        string[] field_values = { "get_user_data", user, psswd };
        Psswd = psswd;

        Http_Client.Send_Post(
            field_names,
            field_values,
            (string response, Handler_Type type) =>
        {
            Scroll_Updater.User_Loaded = 2;
            Parse_User_Data(response, load, save);
        },
            Handler_Type.none,
            false
            );

        On_Success_temp = On_Success;
        OnFailure_temp  = OnFailure;
    }
Пример #6
0
 public void Update_App()
 {
     string[] field_names  = { "REQUEST_TYPE" };
     string[] field_values = { "get_version" };
     Http_Client.Send_Post(field_names, field_values, Handle_Version_Response);
     Loading_Screen.Set_Active(true);
 }
Пример #7
0
    protected virtual void Initialize()
    {
        Title.text = news_entry.Title;
        string month = news_entry.Creation_time.ToString("MMMM").ToUpper().Substring(0, 3);

        Creation_time.text = month + " " + news_entry.Creation_time.Day.ToString() + " de " + news_entry.Creation_time.Year;
        Detail.text        = news_entry.Details;

        if (news_entry.Imgs.Count > 0 && news_entry.Imgs[0] != "empty")
        {
            foreach (string image in news_entry.Imgs)
            {
                Http_Client.Download_Image(image, transform, Handle_Img_Response);
            }
        }

        Canvas.ForceUpdateCanvases();
        GetComponentInChildren <VerticalLayoutGroup>().SetLayoutVertical();

        if (!news_entry.Seen)
        {
            string[] field_names  = { "REQUEST_TYPE", "news_id", "id" };
            string[] field_values = { "set_news_seen", news_entry.Id.ToString(), User.User_Info.Id.ToString() };
            Http_Client.Send_Post(field_names, field_values, (string response, Handler_Type type) => { }, Handler_Type.none);
            news_entry.Seen = true;
            User.User_Info.News_Data.Add(news_entry.Id);
            Database_Handler.Update_Unread(Handler_Type.news);
        }
    }
Пример #8
0
    protected virtual void Initialize()
    {
        Title.text   = Doc.Title;
        Date.text    = Utils.Get_String(Doc.Creation_time);
        details.text = Doc.Details;

        foreach (string url in Doc.Urls)
        {
            Button button = Instantiate(url_prefab, transform).GetComponent <Button>();
            button.onClick.AddListener(() =>
            {
                Message.ShowMessage("Enlace copiado, abriéndolo en el navegador.");
                GUIUtility.systemCopyBuffer = url;
                Application.OpenURL(url);
            });

            button.GetComponentInChildren <Text>().text = url;
        }

        Date.transform.SetAsLastSibling();

        if (Doc.Imgs[0] != "empty")
        {
            foreach (string image in Doc.Imgs)
            {
                Http_Client.Download_Image(image, transform, Handle_Img_Response);
            }
        }

        Canvas.ForceUpdateCanvases();
        GetComponentInChildren <VerticalLayoutGroup>().SetLayoutVertical();
    }
Пример #9
0
    public void Save_Rhythm()
    {
        User.User_Info.Username = "******";
        User.Psswd = "1234567891011121";

        Rhythm_Data rhythm = Rhythms[0];

        string[] field_names = { "REQUEST_TYPE",
                                 "rhythm_id",
                                 "rhythm_name",
                                 "rhythm_details",
                                 "rhythm_ppm",
                                 "rhythm_date_update",
                                 "rhythm_date_creation",
                                 "rhythm_author_id",
                                 "rhythm_data" };

        string[] field_values = { "set_rhythms",
                                  rhythm.Id.ToString(),
                                  rhythm.Name,
                                  rhythm.Description,
                                  rhythm.PPM.ToString(),
                                  Utils.Get_String_SQL(rhythm.Last_Update),
                                  Utils.Get_String_SQL(rhythm.Creation),
                                  rhythm.Author_id.ToString(),
                                  rhythm.Get_Sounds_Json() };

        Http_Client.Send_Post(field_names, field_values, Handle_Save_Response);
    }
Пример #10
0
    // ______________________________________
    //
    // 5. RHYTHM LOADING / SAVING.
    // ______________________________________
    //


    public void Load_Rhythm()
    {
        User.User_Info.Username = "******";
        User.Psswd = "1234567891011121";

        string[] field_names  = { "REQUEST_TYPE" };
        string[] field_values = { "get_rhythms" };
        Http_Client.Send_Post(field_names, field_values, Handle_Data_Response);
    }
Пример #11
0
    public void Delete()
    {
        string[] field_names = { "REQUEST_TYPE", "data_id" };
        string[] field_values;

        if (Data.GetType().Equals(typeof(Poll)))
        {
            field_values = new string[] { "delete_poll", Data.Id.ToString() }
        }
        ;

        else if (Data.GetType().Equals(typeof(Calendar_Event)))
        {
            field_values = new string[] { "delete_event", Data.Id.ToString() }
        }
        ;

        else if (Data.GetType().Equals(typeof(News_Entry)))
        {
            field_values = new string[] { "delete_news", Data.Id.ToString() }
        }
        ;

        else
        {
            return;
        }


        Notification_UI_Pop.Show_Message(
            "Confirmar eliminación",
            "Seguro que quieres eliminar este archivo?",
            () =>
        {
            Type type = Data.Database_Handler_Type();
            List <Data_struct> data_list = Database_Handler.Data_List_Get(type);
            data_list.Remove(data_list.Find(a => a.Id == Data.Id));
            Database_Handler.Data_List_Set(type, data_list);

            Http_Client.Send_Post(
                field_names,
                field_values,
                Handle_Delete_Response
                );

            Menu.Singleton.Load_Scene_Menu_Item(Prev);
        },
            "Eliminar",
            "Cancelar");
    }
Пример #12
0
    // ______________________________________
    //
    // VOTE ON EVENTS.
    // ______________________________________
    //


    /// <summary>
    /// Updates user's choice of vote locally on the device and remotely on the server.
    /// </summary>
    public void Vote(int vote_type)
    {
        if (!initialized)
        {
            return;
        }

        temp_vote = vote_type;

        string[] field_names  = { "REQUEST_TYPE", "event_id", "event_response" };
        string[] field_values = { "set_event_vote", calendar_event.Id.ToString(), vote_type.ToString() };
        Http_Client.Send_Post(field_names, field_values, Handle_Event_Response);

        Set_Interactable(false);
    }
Пример #13
0
    public static void Get_Notification_Key(string notification_key_name = "", Action <object[]> concluding_method = null)
    {
        if (notification_key_name == "")
        {
            notification_key_name = "user_id" + User.User_Info.Id.ToString();
        }

        Http_Client.Send_HTTP_Request(
            "https://fcm.googleapis.com/fcm/notification?notification_key_name=" + notification_key_name,
            Http_Client.Request_Type.GET,
            default_header,
            Get_Notification_Key_Response,
            concluding_method
            );
    }
Пример #14
0
    // ______________________________________
    //
    // 4. NOTIFICATION KEY HANDLING.
    // ______________________________________
    //


    public static void Create_Notification_Key(string notification_key_name = "", string registration_token = "", Action <object[]> concluding_method = null)
    {
        if (notification_key_name == "" || registration_token == "")
        {
            notification_key_name = "user_id" + User.User_Info.Id.ToString();
            registration_token    = Own_Registration_Token;
        }

        string content =
            "{" +
            s + "operation" + s + ":" + s + "create" + s + "," +
            s + "notification_key_name" + s + ":" + s + notification_key_name + s + "," +
            s + "registration_ids" + s + ":[" + s + registration_token + s + "]" +
            "}";

        Http_Client.Send_HTTP_Request(
            "https://fcm.googleapis.com/fcm/notification",
            Http_Client.Request_Type.POST,
            default_header,
            Get_Notification_Key_Response,
            concluding_method,
            content
            );
    }
Пример #15
0
 public TransfersController(Http_Client _httpClient)
 {
     Http_Client = _httpClient;
 }
Пример #16
0
 public ConciliationsController(Http_Client _httpClient)
 {
     Http_Client = _httpClient;
 }
 public MultiPaymentsController(Http_Client _httpClient)
 {
     Http_Client = _httpClient;
 }
 public ClassicAccountsController(Http_Client _httpClient)
 {
     Http_Client = _httpClient;
 }
Пример #19
0
 public LaunchesController(Http_Client _httpClient)
 {
     Http_Client = _httpClient;
 }
Пример #20
0
 public BalancesController(Http_Client _httpClient)
 {
     Http_Client = _httpClient;
 }
Пример #21
0
 public RefundsController(Http_Client _httpClient)
 {
     Http_Client = _httpClient;
 }
Пример #22
0
 public SignaturesController(Http_Client _httpClient)
 {
     Http_Client = _httpClient;
 }
Пример #23
0
 public CustomersController(Http_Client _httpClient)
 {
     Http_Client = _httpClient;
 }
Пример #24
0
    // ______________________________________
    //
    // 5. REGISTRATION TOKEN HANDLING.
    // ______________________________________
    //


    public static void Modify_Registration_Token(Operation operation, FCM_Params param = null)
    {
        if (param == null)
        {
            param = new FCM_Params();
        }

        if (param.Notification_Key_Name == "")
        {
            param.Notification_Key_Name = "user_id" + User.User_Info.Id.ToString();
        }

        if (param.Registration_Token == "")
        {
            param.Registration_Token = Own_Registration_Token;
        }

        if (param.Notification_Key.Length <= 1)
        {
            if (Own_Notification_Key.Length > 1)
            {
                param.Notification_Key = Own_Notification_Key;
            }
            else
            {
                Get_Notification_Key("", (object[] data_get) =>
                {
                    switch (Http_Client.Parse_Status(data_get[0]))
                    {
                    case Response_Status.Ok:
                        Modify(data_get);
                        break;

                    case Response_Status.HTTP_Error:
                        if ((string)data_get[1] == "notification_key not found")
                        {
                            Create_Notification_Key("", "", (object[] data_create) =>
                            {
                                if (Http_Client.Parse_Status(data_create[0]) == Response_Status.Ok)
                                {
                                    Modify(data_create);
                                }
                                else
                                {
                                    Debug.LogError("Could not get notifiaction_key!");
                                }

                                param.Concluding_Method?.Invoke(data_create);
                            });
                        }
                        else
                        {
                            param.Concluding_Method?.Invoke(data_get);
                        }
                        break;

                    default:
                        Debug.LogError("Could not get the notification_key of notification_key_name " + param.Notification_Key_Name);
                        param.Concluding_Method?.Invoke(data_get);
                        break;
                    }

                    void Modify(object[] data_param)
                    {
                        Modify_Registration_Token(operation, new FCM_Params()
                        {
                            Notification_Key  = (string)data_param[1],
                            Concluding_Method = (object[] data_modify) =>
                            {
                                if (Http_Client.Parse_Status(data_modify[0]) == Response_Status.Ok)
                                {
                                    Debug.Log("Registration_token has been " + operation + "ed successfully from notification_key_name " + param.Notification_Key_Name);
                                }
#if !UNITY_EDITOR
                                else
                                {
                                    Debug.LogError("Could not " + operation.ToString() + " the registration_token " + param.Registration_Token + " from notification_key_name " +
                                                   param.Notification_Key_Name + " and notification_key " + param.Notification_Key);
                                }
#endif
                                param.Concluding_Method?.Invoke(data_modify);
                            }
                        });
                    }
                });
                return;
            }
        }

        string content =
            "{" +
            s + "operation" + s + ":" + s + operation.ToString() + s + "," +
            s + "notification_key_name" + s + ":" + s + param.Notification_Key_Name + s + "," +
            s + "notification_key" + s + ":" + s + param.Notification_Key + s + "," +
            s + "registration_ids" + s + ":[" + s + param.Registration_Token + s + "]" +
            "}";

        Http_Client.Send_HTTP_Request(
            "https://fcm.googleapis.com/fcm/notification",
            Http_Client.Request_Type.POST,
            default_header,
            Get_Notification_Key_Response,
            param.Concluding_Method,
            content
            );
    }
 public NotificationsController(Http_Client _httpClient)
 {
     Http_Client = _httpClient;
 }
 public TransparentAccountsController(Http_Client _httpClient)
 {
     Http_Client = _httpClient;
 }
Пример #27
0
    public void Save()
    {
        List <string> field_names = new List <string>()
        {
            "REQUEST_TYPE",
        };

        List <string> field_values = new List <string>()
        {
            "",
            Data.Id.ToString(),
            Encryption.Encrypt(Data.Title),
            Encryption.Encrypt(Data.Details),
            Data.Author_Id.ToString(),
            Data.Privacy.ToString()
        };

        if (Data.GetType().Equals(typeof(Poll)))
        {
            Poll data = (Poll)Data;
            field_names.AddRange(new List <string>()
            {
                "poll_id",
                "poll_name",
                "poll_details",
                "poll_author_id",
                "poll_privacy",
                "poll_date_creation",
                "poll_date_deadline",
                "poll_options"
            });

            field_values[0] = "set_poll";
            field_values.AddRange(new List <string>()
            {
                Utils.Get_String_SQL(data.Creation_Time),
                Utils.Get_String_SQL(data.Date_Deadline),
                Utils.List_To_String(data.Vote_Types)
            });
        }

        else if (Data.GetType().Equals(typeof(Calendar_Event)))
        {
            Calendar_Event data = (Calendar_Event)Data;
            field_names.AddRange(new List <string>()
            {
                "event_id",
                "event_name",
                "event_details",
                "event_author_id",
                "event_privacy",
                "event_location_event",
                "event_location_meeting",
                "event_date_event",
                "event_date_meeting",
                "event_date_deadline",
                "event_transportation",
                "event_cash",
                "event_food"
            });

            field_values[0] = "set_event";
            field_values.AddRange(new List <string>()
            {
                Encryption.Encrypt(data.Location_Event),
                Encryption.Encrypt(data.Location_Meeting),
                Utils.Get_String_SQL(data.Date_Event),
                Utils.Get_String_SQL(data.Date_Meeting),
                Utils.Get_String_SQL(data.Date_Deadline),
                Encryption.Encrypt(data.Transportation),
                Encryption.Encrypt(data.Cash),
                Encryption.Encrypt(data.Food)
            });
        }

        else if (Data.GetType().Equals(typeof(News_Entry)))
        {
            News_Entry data = (News_Entry)Data;
            field_names.AddRange(new List <string>()
            {
                "news_id",
                "news_name",
                "news_details",
                "news_author_id",
                "news_privacy",
                "news_date_creation",
                "news_images"
            });

            field_values[0] = "set_news";
            field_values.AddRange(new List <string>()
            {
                Utils.Get_String_SQL(data.Creation_time),
                Encryption.Encrypt(Utils.List_To_String(data.Imgs))
            });
        }

        else
        {
            return;
        }

        Database_Handler.Selected_Data = Data;

        if (Data.Id == 0)
        {
            Database_Handler.Data_List_Add(Data.Database_Handler_Type(), Data);
        }

        Http_Client.Send_Post(
            field_names.ToArray(),
            field_values.ToArray(),
            Handle_Save_Response
            );

        Save_Button.interactable = false;
    }
Пример #28
0
 public ExtractsController(Http_Client _httpClient)
 {
     Http_Client = _httpClient;
 }
Пример #29
0
 public MultiOrdersController(Http_Client _httpClient)
 {
     Http_Client = _httpClient;
 }
 /// <summary>
 /// Loads a database from the server.
 /// </summary>
 /// <param name="type">The child class type of Database_Handler that should load and parse the server's database.</param>
 public static void Load_Data_Server(Handler_Type type)
 {
     string[] field_names  = { "REQUEST_TYPE" };
     string[] field_values = { "get_" + type.ToString() };
     Http_Client.Send_Post(field_names, field_values, Handle_Data_Response, type);
 }