Exemple #1
0
        private IEnumerator SendUrl(string url, ApiCallback callback)
        {
            using (WWW www = new WWW(url))
            {
                yield return(www);

                if (www.error != null)
                {
                    Debug.Log(www.error);
                    yield return(null);
                }
                else
                {
                    callback?.Invoke(www.text);
                }
            }
        }
Exemple #2
0
        public async Task Get <T>(ApiCallback <T> result, string location, bool showLoading = true) where T : Response
        {
            try
            {
                if (showLoading)
                {
                    Acr.UserDialogs.UserDialogs.Instance.ShowLoading(AppResources.Loading);
                }

                var uri = new Uri(url + location);

                T instance = default(T);

                HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);
                string             token          = Settings.Local.Get <String>("token");
                requestMessage.Headers.Add("Authorization", "Bearer " + token);
                HttpResponseMessage response = await client.SendAsync(requestMessage);

                if (response.IsSuccessStatusCode)
                {
                    //Registration succesfull.
                    instance = JsonConvert.DeserializeObject <T>(await response.Content.ReadAsStringAsync());
                    result(instance);

                    if (!instance.Success)
                    {
                        HandleError(instance);
                    }
                }
                else
                {
                    await caller.DisplayAlert(AppResources.Error, AuthenticationResources.ErrorLogin, AppResources.Ok);
                }
            }
            catch (Exception ex)
            {
                await caller.DisplayAlert(AppResources.Error, AuthenticationResources.ErrorLogin, AppResources.Ok);
            }
            finally
            {
                if (showLoading)
                {
                    Acr.UserDialogs.UserDialogs.Instance.HideLoading();
                }
            }
        }
Exemple #3
0
        public async Task Post <T, R>(ApiCallback <T> result, R request, string location) where T : Response
        {
            try
            {
                Acr.UserDialogs.UserDialogs.Instance.ShowLoading(AppResources.Loading);

                var uri = new Uri(url + location);

                T instance = default(T);

                string             text           = JsonConvert.SerializeObject(request);
                var                content        = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
                HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, uri);
                requestMessage.Content = content;
                string token = Settings.Local.Get <String>("token");
                requestMessage.Headers.Add("Authorization", "Bearer " + token);
                HttpResponseMessage response = await client.SendAsync(requestMessage);

                if (response.IsSuccessStatusCode)
                {
                    instance = JsonConvert.DeserializeObject <T>(await response.Content.ReadAsStringAsync());
                    if (instance.Success)
                    {
                        result(instance);
                    }
                    else
                    {
                        HandleError(instance);
                    }
                }
                else
                {
                    await caller.DisplayAlert(AppResources.Error, AuthenticationResources.ErrorLogin, AppResources.Ok);
                }
            }
            catch (Exception ex)
            {
                await caller.DisplayAlert(AppResources.Error, AuthenticationResources.ErrorLogin, AppResources.Ok);
            }
            finally
            {
                Acr.UserDialogs.UserDialogs.Instance.HideLoading();
            }
        }
Exemple #4
0
        private string RequestAdmobConfig(string appKey)
        {
            if (Application.internetReachability == NetworkReachability.NotReachable)
            {
                return("Please check your network. You can also fill in manually.");
            }

            string result = string.Empty;

            if (!string.IsNullOrEmpty(appKey))
            {
                string api = "https://sdk.mas.yodo1.com/v1/unity/setup/" + appKey;
#if UNITY_2018
                string response = HttpGet(api);
                Dictionary <string, object> obj = (Dictionary <string, object>)Yodo1JSON.Deserialize(response);
                Debug.Log("response:" + response);
                if (obj != null)
                {
                    if (obj.ContainsKey("app_key"))
                    {
                        app_key = (string)obj["app_key"];
                    }
                    if (obj.ContainsKey("name"))
                    {
                        app_name = (string)obj["name"];
                    }
                    if (obj.ContainsKey("bundle_id"))
                    {
                        app_bundle_id = (string)obj["bundle_id"];
                    }
                    if (obj.ContainsKey("platform"))
                    {
                        app_platform = (string)obj["platform"];
                    }
                    if (obj.ContainsKey("admob_key"))
                    {
                        app_admob_key = (string)obj["admob_key"];
                    }

                    if (app_platform == "ios")
                    {
                        this.adSettings.iOSSettings.AdmobAppID = app_admob_key;
                    }
                    else if (app_platform == "android")
                    {
                        this.adSettings.androidSettings.AdmobAppID = app_admob_key;
                    }
                }
                else
                {
                    result = "MAS App Key not found. please fill in correctly.";
                }
#else
                ApiCallback callback = delegate(string response)
                {
                    Dictionary <string, object> obj = (Dictionary <string, object>)Yodo1JSON.Deserialize(response);
                    Debug.Log("response:" + response);
                    if (obj != null)
                    {
                        if (obj.ContainsKey("app_key"))
                        {
                            app_key = (string)obj["app_key"];
                        }
                        if (obj.ContainsKey("name"))
                        {
                            app_name = (string)obj["name"];
                        }
                        if (obj.ContainsKey("bundle_id"))
                        {
                            app_bundle_id = (string)obj["bundle_id"];
                        }
                        if (obj.ContainsKey("platform"))
                        {
                            app_platform = (string)obj["platform"];
                        }
                        if (obj.ContainsKey("admob_key"))
                        {
                            app_admob_key = (string)obj["admob_key"];
                        }

                        if (app_platform == "ios")
                        {
                            this.adSettings.iOSSettings.AdmobAppID = app_admob_key;
                        }
                        else if (app_platform == "android")
                        {
                            this.adSettings.androidSettings.AdmobAppID = app_admob_key;
                        }
                    }
                    else
                    {
                        result = "MAS App Key not found. please fill in correctly.";
                    }
                };
                EditorCoroutineRunner.StartEditorCoroutine(SendUrl(api, callback));
#endif
            }
            else
            {
                result = "Please enter the correct MAS App Key.";
            }
            return(result);
        }
 public Handler(string name)
 {
     Name     = name;
     Callback = (id, param) => OnApiCallback(Name, param);
 }
 public void RegisterCallback(ApiCallback callback)
 {
     _callback = callback;
 }