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); }
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); }
public void GetOfferSearch(EtaApiQueryStringParameterOptions options, string query, Action <List <Offer> > callback, Action <Exception, Uri> error) { 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); ApiRaw("/api/v1/offer/search/", options, onresult => { var json = JsonValue.Parse(onresult); List <Offer> offers = new List <Offer>(); foreach (var item in json["data"] as JsonArray) { var offer = Offer.FromJson(item); offers.Add(offer); } callback(offers); }, (onerror, uri) => { error(onerror, uri); }); }
public void GetStoreList(EtaApiQueryStringParameterOptions options, Action <List <Store> > callback, Action <Exception, Uri> error) { // 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"); } ApiRaw("/api/v1/store/list/", options, _onresult => { string onresult = _onresult; var json = JsonValue.Parse(onresult); List <Store> stores = new List <Store>(); foreach (var item in json["data"] as JsonArray) { var store = Store.FromJson(item, isRoot: true); stores.Add(store); } callback(stores); }, (onerror, uri) => { error(onerror, uri); }); }
/// <summary> /// Called to format the data parameters from a dictionary to a list of kvps. /// Also prepends the constant api data. This is needed to keep the list sorted. /// </summary> /// <param name="data">Dictionary of data</param> /// <returns>List of kvps with data.</returns> private List <KeyValuePair <string, string> > FormatParams(Dictionary <string, string> data) { List <KeyValuePair <string, string> > param = new List <KeyValuePair <string, string> >(); param.Add(new KeyValuePair <string, string>("api_key", this.apiKey)); param.Add(new KeyValuePair <string, string>("api_uuid", this.uuid)); param.Add(new KeyValuePair <string, string>("api_timestamp", UNIXTime.GetTimestamp(DateTime.Now))); foreach (KeyValuePair <string, string> kvp in data) { param.Add(kvp); } return(param); }
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 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; }); }
public void GetCatalogList(EtaApiQueryStringParameterOptions options, Action <List <Catalog> > callback, Action <Exception, Uri> error) { 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"); } ApiRaw("/api/v1/catalog/list/", options, _onresult => { string onresult = _onresult; if (!string.IsNullOrWhiteSpace(onresult)) { try { var json = JsonValue.Parse(onresult); List <Catalog> catalogs = new List <Catalog>(); foreach (var item in json["data"] as JsonArray) { var catalog = Catalog.FromJson(item); catalogs.Add(catalog); } callback(catalogs); } catch (Exception ex) { error(new ArgumentNullException("Ups ingen data fra serveren", ex), null); } } else { error(new ArgumentNullException("Ups ingen data fra serveren"), new Uri("")); } }, (onerror, uri) => { error(onerror, uri); }); }
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; }); }
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 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 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"); } } }
public void GetOfferList(EtaApiQueryStringParameterOptions options, Action <List <Offer> > callback, Action <Exception, Uri> error) { 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"); } ApiRaw("/api/v1/offer/list/", options, _onresult => { string onresult = _onresult; var json = JsonValue.Parse(onresult); List <Offer> offers = new List <Offer>(); foreach (var item in json["data"] as JsonArray) { var offer = Offer.FromJson(item); offers.Add(offer); } callback(offers); }, (onerror, uri) => { error(onerror, uri); }); }
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); }