public void ThrowWhenPlaceIdIsNullOrEmpty(string input) { var service = new GooglePlacesApiService(GoogleApiSettings.Builder.WithApiKey("testkey").Build()); var action = new Func <Task>(async() => await service.GetDetailsAsync(input, service.GetSessionToken())); action.Should() .Throw <ArgumentNullException>() .WithMessage($"Value cannot be null.{Environment.NewLine}Parameter name: placeId"); }
static async Task Main(string[] args) { var settings = GooglePlacesApi.Models.GoogleApiSettings.Builder .WithApiKey(Environment.GetEnvironmentVariable("GOOGLE_PLACES_API_KEY")) .WithType(GooglePlacesApi.Models.PlaceTypes.GeoCode) .Build(); var service = new GooglePlacesApiService(settings); var result = await service.GetPredictionsAsync("new y") .ConfigureAwait(false); if (result != null && result.Status.Equals("OK") && result.Items != null) { //foreach(var item in result.Items) //{ // Console.WriteLine("=========== PREDICTION ==========="); // Console.WriteLine(item.Description); // var details = await service.GetDetailsAsync(item.PlaceId) // .ConfigureAwait(false); // if(details != null) // { // Console.WriteLine("=========== DETAILS ==========="); // Console.WriteLine($"Id: {details.Place.Id}"); // Console.WriteLine($"PlaceId: {details.Place.PlaceId}"); // Console.WriteLine($"FormattedAddress: {details.Place.FormattedAddress}"); // Console.WriteLine($"Icon: {details.Place.Icon}"); // Console.WriteLine($"Icon: {details.Place.Reference}"); // } //} var item = result.Items.FirstOrDefault(); Console.WriteLine("=========== PREDICTION ==========="); Console.WriteLine(item.Description); var details = await service.GetDetailsAsync(item.PlaceId, service.GetSessionToken()) .ConfigureAwait(false); if (details != null) { Console.WriteLine("=========== DETAILS ==========="); Console.WriteLine($"Id: {details.Place.Id}"); Console.WriteLine($"PlaceId: {details.Place.PlaceId}"); Console.WriteLine($"FormattedAddress: {details.Place.FormattedAddress}"); Console.WriteLine($"Icon: {details.Place.Icon}"); Console.WriteLine($"Icon: {details.Place.Reference}"); } } }
public async Task GetDetailsAsync() { var settings = GoogleApiSettings.Builder .WithApiKey(Environment.GetEnvironmentVariable("GOOGLE_PLACES_API_KEY")) .WithLogger(_refitLogger) .WithType(PlaceTypes.GeoCode) .Build(); var service = new GooglePlacesApiService(settings); var predictions = await service.GetPredictionsAsync("new y") .ConfigureAwait(false); var details = await service.GetDetailsAsync(predictions.Items.FirstOrDefault().PlaceId, service.GetSessionToken()) .ConfigureAwait(false); details.Should() .NotBeNull(); details.Place .Should() .NotBeNull(); }