async public Task <EtaResponse <Catalog> > GetCatalogInfoAsync(string catalogId, string publicKey)
        {
            var options = new EtaApiQueryStringParameterOptions();

            options.AddParm("catalog", catalogId);

            var eta = await ApiRawAsync("/api/v1/catalog/info/", options);

            if (eta.HasErrors)
            {
                return(new EtaResponse <Catalog>(eta.Uri, eta.Error));
            }

            var jsonstr = eta.Result;

            var result = await TaskEx.Run <Catalog>(() =>
            {
                Catalog catalog = null;
                if (!string.IsNullOrWhiteSpace(jsonstr))
                {
                    var json = JsonValue.Parse(jsonstr);
                    catalog  = Catalog.FromJson(json);
                }
                return(catalog);
            });

            return(new EtaResponse <Catalog>(eta.Uri, result));
        }
        async public Task <EtaResponse <Store> > GetStoreInfoAsync(EtaApiQueryStringParameterOptions options)
        {
            if (options == null)
            {
                options = new EtaApiQueryStringParameterOptions();
                options.AddParm("store", "0a63T");
            }

            var eta = await ApiRawAsync("/api/v1/store/info/", options);

            if (eta.HasErrors)
            {
                return(new EtaResponse <Store>(eta.Uri, eta.Error));
            }
            var jsonstr = eta.Result;
            var result  = await TaskEx.Run <EtaResponse <Store> >(() =>
            {
                if (!string.IsNullOrWhiteSpace(jsonstr))
                {
                    var json  = JsonValue.Parse(jsonstr);
                    var store = Store.FromJson(json["data"], isRoot: true);
                    return(new EtaResponse <Store>(eta.Uri, store));
                }
                return(new EtaResponse <Store>(eta.Uri, new Exception("response is null or empty")));
            });

            return(result);
        }
Example #3
0
        async public Task <EtaResponse <JsonValue> > GetOfferInfoAsync(EtaApiQueryStringParameterOptions options)
        {
            if (options == null)
            {
                options = new EtaApiQueryStringParameterOptions();
                options.AddParm("type", "all");
            }

            var eta = await ApiRawAsync("/api/v1/offer/info/", options);

            if (eta.HasErrors)
            {
                return(new EtaResponse <JsonValue>(eta.Uri, eta.Error));
            }

            var jsonstr = eta.Result;

            var result = await TaskEx.Run <EtaResponse <JsonValue> >(() =>
            {
                if (!string.IsNullOrWhiteSpace(jsonstr))
                {
                    var json = JsonValue.Parse(jsonstr);
                    return(new EtaResponse <JsonValue>(eta.Uri, json));
                }
                return(new EtaResponse <JsonValue>(eta.Uri, new Exception("Jsonstr value is null or empty")));
            });

            return(result);
        }
        async public Task LoadStores()
        {
            if (IsStoresLoading)
            {
                return;
            }
            IsStoresLoading = true;
            HasStors        = null;

            var options = new EtaApiQueryStringParameterOptions();

            options.AddParm(EtaApiConstants.EtaApi_Latitude, UserViewModel.Location.Latitude.ToString("0.00000"));
            options.AddParm(EtaApiConstants.EtaApi_Longitude, UserViewModel.Location.Longitude.ToString("0.00000"));
            options.AddParm(EtaApiConstants.EtaApi_LocationDetermined, UNIXTime.GetTimestamp(DateTime.Now));
            options.AddParm(EtaApiConstants.EtaApi_Geocoded, UserViewModel.Location.IsGeoCoded ? "1" : "1");
            options.AddParm(EtaApiConstants.EtaApi_Ditance, UserViewModel.Distance.ToString());

            var response = await Api.GetStoreListAsync(options);

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                if (Stores.Any())
                {
                    Stores.Clear();
                }
                if (response.HasErrors)
                {
                    IsStoresLoaded = false;
                }
                else
                {
                    foreach (var store in response.Result)
                    {
                        Stores.Add(store);
                    }
                    IsStoresLoaded = true;
                }
                HasStors        = Stores.Any();
                IsStoresLoading = false;
            });
        }
        async public Task LoadSuggestedOffers()
        {
            if (IsSuggestedOffersLoading)
            {
                return;
            }
            IsSuggestedOffersLoading = true;
            HasSuggestedOffers       = null;

            var options = new EtaApiQueryStringParameterOptions();

            options.AddParm(EtaApiConstants.EtaApi_Latitude, UserViewModel.Location.Latitude.ToString("0.00000"));
            options.AddParm(EtaApiConstants.EtaApi_Longitude, UserViewModel.Location.Longitude.ToString("0.00000"));
            options.AddParm(EtaApiConstants.EtaApi_LocationDetermined, UNIXTime.GetTimestamp(DateTime.Now));
            options.AddParm(EtaApiConstants.EtaApi_Geocoded, UserViewModel.Location.IsGeoCoded ? "0" : "0");
            options.AddParm(EtaApiConstants.EtaApi_Accuracy, "0");//userModel.Location.Accuracy.ToString());
            options.AddParm(EtaApiConstants.EtaApi_Ditance, UserViewModel.Distance.ToString());

            options.AddParm("type", "suggested");
            options.AddParm("from", UNIXTime.GetTimestamp(DateTime.Now));
            options.AddParm("to", UNIXTime.GetTimestamp(DateTime.Now.AddDays(14)));

            var response = await Api.GetOfferListAsync(options);

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                if (SuggestedOffers.Any())
                {
                    SuggestedOffers.Clear();
                }
                if (response.HasErrors)
                {
                    IsSuggestedOffersLoaded = false;
                }
                else
                {
                    foreach (var offer in response.Result)
                    {
                        SuggestedOffers.Add(offer);
                    }
                    IsSuggestedOffersLoaded = true;
                }
                HasSuggestedOffers       = SuggestedOffers.Any();
                IsSuggestedOffersLoading = false;
            });
        }
        async public Task LoadStoreOffers()
        {
            if (IsStoreOffersLoading)
            {
                return;
            }
            IsStoreOffersLoading = true;

            var options = new EtaApiQueryStringParameterOptions();

            options.AddParm(EtaApiConstants.EtaApi_Latitude, App.ViewModel.UserViewModel.Location.Latitude.ToString("0.00000"));
            options.AddParm(EtaApiConstants.EtaApi_Longitude, App.ViewModel.UserViewModel.Location.Longitude.ToString("0.00000"));
            options.AddParm(EtaApiConstants.EtaApi_LocationDetermined, UNIXTime.GetTimestamp(DateTime.Now));
            options.AddParm(EtaApiConstants.EtaApi_Geocoded, App.ViewModel.UserViewModel.Location.IsGeoCoded ? "0" : "0");
            options.AddParm(EtaApiConstants.EtaApi_Accuracy, "0");//userModel.Location.Accuracy.ToString());
            options.AddParm(EtaApiConstants.EtaApi_Ditance, "700000");
            options.AddParm("store", Store.Id);
            options.AddParm("dealer", Store.Dealer.Id);
            options.AddParm("type", "all");

            var response = await Api.GetOfferListAsync(options);

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                if (StoreOffers.Any())
                {
                    StoreOffers.Clear();
                }
                if (response.HasErrors)
                {
                    IsStoreOffersLoaded = false;
                    HasOffers           = false;
                }
                else
                {
                    foreach (var offer in response.Result)
                    {
                        StoreOffers.Add(offer);
                    }
                    IsStoreOffersLoaded = true;
                    HasOffers           = true;
                }
                IsStoreOffersLoading = false;
                ShowText             = !HasOffers;
            });
        }
        async public Task <EtaResponse <List <CatalogHotspot> > > GetCatalogHotspotAsync(EtaApiQueryStringParameterOptions options)
        {
            if (options == null)
            {
                options = new EtaApiQueryStringParameterOptions();
                options.AddParm(EtaApiConstants.EtaApi_Latitude, "55.77012");
                options.AddParm(EtaApiConstants.EtaApi_Longitude, "12.46320");
                options.AddParm(EtaApiConstants.EtaApi_LocationDetermined, UNIXTime.GetTimestamp(DateTime.Now));
                options.AddParm(EtaApiConstants.EtaApi_Geocoded, "0");
                options.AddParm(EtaApiConstants.EtaApi_Accuracy, "0");
                options.AddParm(EtaApiConstants.EtaApi_Ditance, "10000");
            }

            var eta = await ApiRawAsync("/api/v1/catalog/hotspot/list/", options);

            if (eta.HasErrors)
            {
                return(new EtaResponse <List <CatalogHotspot> >(eta.Uri, eta.Error));
            }
            var jsonstr = eta.Result;

            var result = await TaskEx.Run <EtaResponse <List <CatalogHotspot> > >(() =>
            {
                if (!string.IsNullOrWhiteSpace(jsonstr))
                {
                    List <CatalogHotspot> cataloghotSpots = new List <CatalogHotspot>();
                    var json = JsonValue.Parse(jsonstr);
                    cataloghotSpots.Add(CatalogHotspot.FromJson(json["data"] as JsonValue));
                    return(new EtaResponse <List <CatalogHotspot> >(eta.Uri, cataloghotSpots));
                }
                return(new EtaResponse <List <CatalogHotspot> >(eta.Uri, new Exception("json response is null or empty")));
            });

            return(result);
        }
Example #8
0
        async public Task <EtaResponse <List <Offer> > > GetOfferSearchAsync(EtaApiQueryStringParameterOptions options, string query)
        {
            if (options == null)
            {
                options = new EtaApiQueryStringParameterOptions();

                options.AddParm(EtaApiConstants.EtaApi_Latitude, "55.77012");
                options.AddParm(EtaApiConstants.EtaApi_Longitude, "12.46320");
                options.AddParm(EtaApiConstants.EtaApi_LocationDetermined, UNIXTime.GetTimestamp(DateTime.Now));
                options.AddParm(EtaApiConstants.EtaApi_Geocoded, "0");
                options.AddParm(EtaApiConstants.EtaApi_Accuracy, "0");
                options.AddParm(EtaApiConstants.EtaApi_Ditance, "10000");
            }

            options.AddParm("q", query);

            var eta = await ApiRawAsync("/api/v1/offer/search/", options);

            if (eta.HasErrors)
            {
                return(new EtaResponse <List <Offer> >(eta.Uri, eta.Error));
            }
            var jsonstr = eta.Result;

            var result = await TaskEx.Run <EtaResponse <List <Offer> > >(() =>
            {
                return(ParseOffers(eta.Uri, jsonstr));
            });

            return(result);
        }
Example #9
0
        async public Task <EtaResponse <List <Offer> > > GetOfferListAsync(EtaApiQueryStringParameterOptions options)
        {
            if (options == null)
            {
                options = new EtaApiQueryStringParameterOptions();
                options.AddParm("from", EtaSDK.Utils.UNIXTime.GetTimestamp(DateTime.Now));
                options.AddParm("to", EtaSDK.Utils.UNIXTime.GetTimestamp(DateTime.Now.AddDays(14)));

                options.AddParm(EtaApiConstants.EtaApi_Latitude, "55.77012");
                options.AddParm(EtaApiConstants.EtaApi_Longitude, "12.46320");
                options.AddParm(EtaApiConstants.EtaApi_LocationDetermined, UNIXTime.GetTimestamp(DateTime.Now));
                options.AddParm(EtaApiConstants.EtaApi_Geocoded, "0");
                options.AddParm(EtaApiConstants.EtaApi_Accuracy, "0");
                options.AddParm(EtaApiConstants.EtaApi_Ditance, "10000");

                //options.AddParm(EtaApiConstants.EtaApi_OfferId, "");
                options.AddParm("store", "5d6dBY"); // 5d6dBY
                options.AddParm("type", "suggested");
            }

            var eta = await ApiRawAsync("/api/v1/offer/list/", options);

            if (eta.HasErrors)
            {
                return(new EtaResponse <List <Offer> >(eta.Uri, eta.Error));
            }

            var jsonstr = eta.Result;

            var result = await TaskEx.Run <EtaResponse <List <Offer> > >(() =>
            {
                return(ParseOffers(eta.Uri, jsonstr));
            });

            return(result);
        }
Example #10
0
        async public Task GetOfferListSuggested_test()
        {
            var options = new EtaApiQueryStringParameterOptions();

            options.AddParm(EtaApiConstants.EtaApi_Latitude, "55.77012");
            options.AddParm(EtaApiConstants.EtaApi_Longitude, "12.46320");
            options.AddParm(EtaApiConstants.EtaApi_LocationDetermined, UNIXTime.GetTimestamp(DateTime.Now));
            options.AddParm(EtaApiConstants.EtaApi_Geocoded, "0");
            options.AddParm(EtaApiConstants.EtaApi_Accuracy, "50");
            options.AddParm(EtaApiConstants.EtaApi_Ditance, "10000");

            //options.AddParm(EtaApiConstants.EtaApi_OfferId, "");
            options.AddParm("type", "suggested");
            //options.AddParm("api_limit", "100");
            options.AddParm("from", UNIXTime.GetTimestamp(DateTime.Now));
            options.AddParm("to", UNIXTime.GetTimestamp(DateTime.Now.AddDays(14)));

            var api = new EtaSDK.v3.EtaApi();

            var response = await api.GetOfferListAsync(options);

            if (response.HasErrors)
            {
                TestCompleteWithErrorsUISafe("suggeted offers search error: " + response.Error.Message);
            }
            else
            {
                var offers = response.Result;

                if (offers.Any())
                {
                    TestCompleteUISafe();
                }
                else
                {
                    TestCompleteWithErrorsUISafe("Suggested Offers Search result is null or Empty");
                }
            }
        }
        async public Task <EtaResponse <List <Store> > > GetStoreListAsync(EtaApiQueryStringParameterOptions options)
        {
            // Offer Id el. Catalog id med som key
            if (options == null)
            {
                options = new EtaApiQueryStringParameterOptions();
                options.AddParm(EtaApiConstants.EtaApi_Latitude, "55.77012");
                options.AddParm(EtaApiConstants.EtaApi_Longitude, "12.46320");
                options.AddParm(EtaApiConstants.EtaApi_LocationDetermined, UNIXTime.GetTimestamp(DateTime.Now));
                options.AddParm(EtaApiConstants.EtaApi_Geocoded, "0");
                options.AddParm(EtaApiConstants.EtaApi_Accuracy, "0");
                options.AddParm(EtaApiConstants.EtaApi_Ditance, "10000");
                //options.AddParm(EtaApiConstants.EtaApi_OfferId, "");
                //options.AddParm(EtaApiConstants.EtaApi_CatalogId, "");
                options.AddParm("type", "suggested");
            }

            var eta = await ApiRawAsync("/api/v1/store/list/", options);

            if (eta.HasErrors)
            {
                return(new EtaResponse <List <Store> >(eta.Uri, eta.Error));
            }
            var jsonstr = eta.Result;

            var result = await TaskEx.Run <EtaResponse <List <Store> > >(() =>
            {
                if (!string.IsNullOrWhiteSpace(jsonstr))
                {
                    List <Store> stores = new List <Store>();
                    var json            = JsonValue.Parse(jsonstr);
                    foreach (var item in json["data"] as JsonArray)
                    {
                        var store = Store.FromJson(item, isRoot: true);
                        stores.Add(store);
                    }
                    return(new EtaResponse <List <Store> >(eta.Uri, stores));
                }
                return(new EtaResponse <List <Store> >(eta.Uri, new Exception("JsonValue is null or empty")));
            });

            return(result);
        }
        async public Task LoadSearchOffers(string q)
        {
            if (string.IsNullOrWhiteSpace(q))
            {
                return;
            }

            if (IsSearchOffersLoading)
            {
                return;
            }
            HasSearchOffers       = null;
            IsSearchOffersLoading = true;

            var options = new EtaApiQueryStringParameterOptions();

            options.AddParm(EtaApiConstants.EtaApi_Latitude, UserViewModel.Location.Latitude.ToString("0.00000"));
            options.AddParm(EtaApiConstants.EtaApi_Longitude, UserViewModel.Location.Longitude.ToString("0.00000"));
            options.AddParm(EtaApiConstants.EtaApi_LocationDetermined, UNIXTime.GetTimestamp(DateTime.Now));
            options.AddParm(EtaApiConstants.EtaApi_Geocoded, UserViewModel.Location.IsGeoCoded ? "0" : "0");
            options.AddParm(EtaApiConstants.EtaApi_Accuracy, "1");//userModel.Location.Accuracy.ToString());
            options.AddParm(EtaApiConstants.EtaApi_Ditance, UserViewModel.Distance.ToString());

            var response = await Api.GetOfferSearchAsync(options, q);

            await Deployment.Current.Dispatcher.InvokeAsync(() =>
            {
                if (OffersSearch.Any())
                {
                    OffersSearch.Clear();
                }
                if (response.HasErrors)
                {
                    IsSearchLoaded = false;
                }
                else
                {
                    foreach (var offer in response.Result)
                    {
                        OffersSearch.Add(offer);
                    }
                    IsSearchLoaded = true;
                }
                HasSearchOffers       = OffersSearch.Any();
                IsSearchOffersLoading = false;
            });
        }
        async public Task LoadCatalogs()
        {
            if (IsCatalogsLoading || !IsUserViewModelLoaded)
            {
                return;
            }
            IsCatalogsLoading = true;
            hasCatalogs       = null;

            var options = new EtaApiQueryStringParameterOptions();

            options.AddParm(EtaApiConstants.EtaApi_Latitude, UserViewModel.Location.Latitude.ToString("0.00000"));
            options.AddParm(EtaApiConstants.EtaApi_Longitude, UserViewModel.Location.Longitude.ToString("0.00000"));
            options.AddParm(EtaApiConstants.EtaApi_LocationDetermined, UNIXTime.GetTimestamp(DateTime.Now));
            options.AddParm(EtaApiConstants.EtaApi_Geocoded, UserViewModel.Location.IsGeoCoded ? "0" : "0");
            options.AddParm(EtaApiConstants.EtaApi_Accuracy, "0");//userModel.Location.Accuracy.ToString());
            options.AddParm(EtaApiConstants.EtaApi_Ditance, UserViewModel.Distance.ToString());

            var response = await Api.GetCatalogListAsync(options);

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                if (Catalogs.Any())
                {
                    Catalogs.Clear();
                }

                if (response.HasErrors)
                {
                    IsCatalogsLoaded = false;
                }
                else
                {
                    foreach (var catalog in response.Result)
                    {
                        Catalogs.Add(catalog);
                    }
                    IsCatalogsLoaded = true;
                }
                HasCatalogs       = Catalogs.Any();
                IsCatalogsLoading = false;
            });
        }