private static async Task <(API.GeoPoint coordinates, string address)> GuessBuyerLocationAsync(string locationArgument) { API.GeoPoint coordinates = null; if (!GuessLocationUtils.TryParse(locationArgument, out API.GuessLocationRequest requestLocation)) { coordinates = new API.GeoPoint( double.Parse(API.Configuration.Instance["console:location:longitude"]), double.Parse(API.Configuration.Instance["console:location:latitude"]) ); requestLocation = new API.GuessLocationRequest(coordinates); } var responseLocation = await API.GuessLocation.RunAsync(requestLocation); return(responseLocation.Coordinates ?? coordinates, responseLocation.Address); }
public EstimateDeliveryItem( string productName, string siren, string sellerName, string sellerAddress, API.GeoPoint sellerCoordinates, string buyerAddress, API.EstimateDeliveryResponse estimateDelivery ) { ProductName = productName; Siren = siren; SellerName = sellerName; SellerAddress = sellerAddress; SellerCoordinates = sellerCoordinates; BuyerAddress = buyerAddress; EstimateDelivery = estimateDelivery; }
private static async Task <IEnumerable <EstimateDeliveryItem> > GetEstimateDeliveryItemsAsync( Uri uri, API.GeoPoint buyerCoordinates, string buyerAddress ) { var items = new List <EstimateDeliveryItem>(); var responseProduct = await API.ScrapProduct.RunAsync(new API.ScrapProductRequest(uri)); if (responseProduct.IsValid && responseProduct.SellerIDs.Any()) { var responseToken = await API.GetSireneAccessToken.RunAsync(new API.GetSireneAccessTokenRequest()); if (responseToken.IsValid) { foreach (var sellerID in responseProduct.SellerIDs.Distinct()) { var responseSeller = await API.ScrapSeller.RunAsync(new API.ScrapSellerRequest(responseProduct.MarketPlaceID, sellerID)); if (responseSeller.IsValid && !string.IsNullOrEmpty(responseSeller.Siren)) { var responseSirene = await API.QuerySirene.RunAsync( API.QuerySireneRequest.FromSiren(responseToken.Token, responseSeller.Siren) ); if (responseSirene.IsValid && responseSirene.Organizations.Count() > 0) { var organization = responseSirene.Organizations.First(); var responseBAN = await API.QueryBAN.RunAsync( new API.QueryBANRequest(organization.Address) ); if (responseBAN.IsValid) { var responseDelivery = await API.EstimateDelivery.RunAsync( new API.EstimateDeliveryRequest(responseBAN.Coordinates, buyerCoordinates) ); if (responseDelivery.IsValid) { items.Add( new EstimateDeliveryItem( responseProduct.ProductName, responseSeller.Siren, organization.Name, responseBAN.Address, responseBAN.Coordinates, buyerAddress, responseDelivery ) ); } } } } } } } return(items); }