/// <summary>
        /// Gets cities; credentials supplied as authorization header value
        /// </summary>
        /// <param name="authHdr"></param>
        /// <returns></returns>
        private static async Task <IEnumerable <City> > GetCitiesInternalAsync(string authHdr)
        {
            var cfg = ServiceConfig.Read();

            //Note: cities are obtained by calling the auth endpoint

            var authCall = await ApiCall <AuthRaw>(
                cfg.Endpoint,
                cfg.Routes.Auth,
                authHdr
                );

            if (authCall == null)
            {
                return(null);
            }

            //at this stage should have some data - in particular cities
            var cities = authCall.Cities.AsCities().ToArray();


            //need to obtain location for each city
            foreach (var city in cities)
            {
                var rawLocations = await ApiCall <LocationRaw[]>(
                    cfg.Endpoint,
                    cfg.Routes.CityLocations.Replace("{city_code}", city.Code),
                    authHdr
                    );

                if (rawLocations == null)
                {
                    continue;
                }

                var locations = rawLocations.AsLocations();

                foreach (var cityLoc in city.Locations)
                {
                    var loc = locations.FirstOrDefault(x => x.Id == cityLoc.Id);
                    cityLoc.Lo = loc?.Lo;
                    cityLoc.La = loc?.La;
                }
            }

            return(cities);
        }
示例#2
0
        /// <summary>
        /// Reads transactions data for given city & location and returns raw response; credentials supplied as authorization header value
        /// </summary>
        /// <param name="authHdr"></param>
        /// <param name="cityCode"></param>
        /// <param name="locationId"></param>
        /// <param name="dateFrom"></param>
        /// <param name="dateTo"></param>
        /// <returns></returns>
        private static async Task <TransactionDataResponse> GetTransactionsDataPassThroughInternalAsync(string authHdr, string cityCode, string locationId, DateTime?dateFrom, DateTime?dateTo)
        {
            var cfg = ServiceConfig.Read();

            try
            {
                var dateFromFixed = GetDateFrom(dateFrom);
                var dateToFixed   = GetDateTo(dateTo);
                if (dateToFixed == dateFromFixed)
                {
                    dateToFixed = new DateTime(dateToFixed.Year, dateToFixed.Month, dateToFixed.Day, 23, 59, 59);
                }

                var transactionsData = await ApiCall <TransactionDataResponse>(
                    cfg.Endpoint,
                    cfg.Routes.LocationTransactions
                    .Replace("{city_code}", cityCode)
                    .Replace("{location_id}", locationId)
                    .Replace("{date_from}", dateFromFixed.ToString("s"))
                    .Replace("{date_to}", dateToFixed.ToString("s")),
                    authHdr
                    );

                if (transactionsData?.Data == null || !transactionsData.Data.Any())
                {
                    return(null);
                }

                return(transactionsData);
            }
            catch
            {
                //ignore
            }

            return(null);
        }