Exemple #1
0
        public async Task <IEnumerable <Estate> > GetObjects(KskWebClientOptions options)
        {
            var estates = new List <Estate>();

            var firstPage = await GetPage(options, 1, options.MarketingUsageObjectType);

            estates.AddRange(firstPage.Embedded.Estate);

            for (int page = 2; page <= firstPage.PageCount; page++)
            {
                var pageContent = await GetPage(options, page, options.MarketingUsageObjectType);

                estates.AddRange(pageContent.Embedded.Estate);
            }

            return(estates);
        }
Exemple #2
0
        private async Task <string> GetRawPage(KskWebClientOptions options, int page, string marketingUsageObjectType)
        {
            using var request = new HttpRequestMessage(new HttpMethod("POST"),
                                                       "https://www.kskbb.de/content/myif/ksk-boeblingen/work/filiale/de/home/misc/vps/gate/_jcr_content.bin/sip/api");
            request.Content = new StringContent(
                $"{{\"route\":\"estate\",\"page\":\"{page}\",\"zip_city_estate_id\":\"{options.Zip}\",\"marketing_usage_object_type\":\"{marketingUsageObjectType}\",\"perimeter\":\"{options.RadiusInKm}\",\"sort_by\":\"distance_asc\",\"limit\":\"{options.Limit}\",\"regio_client_id\":\"{options.RegioClientId}\",\"return_data\":\"overview\"}}");
            request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

            var result = await _client.SendAsync(request);

            var resultString = await result.Content.ReadAsStringAsync();

            if (resultString.StartsWith("{\"pending"))
            {
                return(await GetRawPage(options, page, marketingUsageObjectType));
            }

            return(resultString);
        }
Exemple #3
0
        public async Task <Root> GetPage(KskWebClientOptions options, int page, string marketingUsageObjectType)
        {
            var resultString = await GetRawPage(options, page, marketingUsageObjectType);

            try
            {
                return(JsonSerializer.Deserialize <Root>(resultString));
            }
            catch (JsonException e)
            {
                if (e.Message.Contains("'<' is an invalid start of a value"))
                {
                    // sometimes the KSK doesn't send valid json. This is just ignored as it works mostly the next time
                    return(new Root {
                        Embedded = new Embedded {
                            Estate = new List <Estate>()
                        }
                    });
                }

                throw;
            }
        }