Ejemplo n.º 1
0
        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);
            });
        }
Ejemplo n.º 2
0
        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);
            });
        }
Ejemplo n.º 3
0
        public void GetStoreInfo(EtaApiQueryStringParameterOptions options, Action <Store> callback, Action <Exception> error)
        {
            if (options == null)
            {
                options = new EtaApiQueryStringParameterOptions();
                options.AddParm("store", "0a63T");
            }

            ApiRaw("/api/v1/store/info/", options, onresult =>
            {
                var json = JsonValue.Parse(onresult);
                if (json.ContainsKey("data"))
                {
                    var store = Store.FromJson(json["data"], isRoot: true);
                    callback(store);
                }
                else
                {
                    callback(null);
                }
            }, (onerror, uri) =>
            {
                error(onerror);
            });
        }
Ejemplo n.º 4
0
        public void GetOfferPopularSearches(Action <string> callback, Action <Exception> error)
        {
            var options = new EtaApiQueryStringParameterOptions();

            ApiRaw("/api/v1/offer/search/list/", options, onresult =>
            {
                var json = JsonValue.Parse(onresult);

                callback(onresult);
            }, (onerror, uri) =>
            {
                error(onerror);
            });
        }
        public void GetCatalogInfo(string catalogId, string publicKey, Action <Catalog> callback, Action <Exception> error)
        {
            var options = new EtaApiQueryStringParameterOptions();

            options.AddParm("catalog", catalogId);

            ApiRaw("/api/v1/catalog/info/", options, _onresult =>
            {
                string onresult = _onresult;
                var json        = JsonValue.Parse(onresult);
                var catalog     = Catalog.FromJson(json);
                callback(catalog);
            }, (onerror, uri) =>
            {
                error(onerror);
            });
        }
Ejemplo n.º 6
0
        public void GetOfferInfo(EtaApiQueryStringParameterOptions options, Action <string> callback, Action <Exception> error)
        {
            if (options == null)
            {
                options = new EtaApiQueryStringParameterOptions();
                options.AddParm("type", "all");
            }

            ApiRaw("/api/v1/store/list/", options, onresult =>
            {
                var json = JsonValue.Parse(onresult);

                callback(onresult);
            }, (onerror, uri) =>
            {
                error(onerror);
            });
        }
        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);
            });
        }
Ejemplo n.º 8
0
        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);
            });
        }
Ejemplo n.º 9
0
        public void ApiRaw(string resourceUri, EtaApiQueryStringParameterOptions options, Action <string> callback, Action <Exception, Uri> error)
        {
            if (!resourceUri.StartsWith("/api/v1/"))
            {
                throw new ArgumentOutOfRangeException("resourceUri", "API reource must begin with /api/v1/");
            }
            var requestUri = new Uri(
                new Uri(Resources.Eta_BaseUri),
                resourceUri + options.AsQueryString());

            var request = HttpWebRequest.CreateHttp(requestUri);

            request.Method = options.webMethod;
            request.Accept = options.responseType;

            Observable.FromAsyncPattern <WebResponse>(request.BeginGetResponse, request.EndGetResponse)()
            .ObserveOn(Scheduler.ThreadPool)
            .Select(response =>
            {
                if (response == null)
                {
                    return(null);
                }
                else
                {
                    return(response.GetResponseStream());
                }
            })
            .Select(stream =>
            {
                if (stream == null)
                {
                    return(null);;
                }
                string result;
                using (var reader = new StreamReader(stream))
                {
                    result = reader.ReadToEnd();
                }
                return(result);
            })
            .Subscribe(result =>
            {
                string next = result;
                if (string.IsNullOrWhiteSpace(next))
                {
                    error(new ArgumentNullException("result from server is null, empty or with errors"), request.RequestUri);
                    Debug.WriteLine("request rescived with errors");
                }
                else
                {
                    if (next.StartsWith("<textarea>"))
                    {
                        next = next.Remove(0, 10);
                        next = next.Remove(next.Length - 11, 11);
                    }
                    callback(next);
                    Debug.WriteLine("request rescived");
                }
            }, err =>
            {
                var exception = err is WebException ? err as WebException : err;
                error(exception, request.RequestUri);
                Debug.WriteLine("request failed, uri: " + request.RequestUri.ToString());
            }, () =>
            {
                Debug.WriteLine("request done");
            });
        }