Beispiel #1
0
        public GooglePlacesApiService(GoogleApiSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (string.IsNullOrEmpty(settings.ApiKey))
            {
                throw new InvalidOperationException("ApiKey must be set");
            }

            if (string.IsNullOrEmpty(settings.SessionToken))
            {
                settings.SessionToken = Guid.NewGuid().ToString();
            }

            _settings = settings;

            JsonConvert.DefaultSettings =
                () => new JsonSerializerSettings()
            {
                MissingMemberHandling = MissingMemberHandling.Ignore
            };

            var refitSettings = new RefitSettings();

            if (_settings.Logger != null)
            {
                refitSettings.HttpMessageHandlerFactory = () => new LoggingHandler(new HttpClientHandler(), _settings.Logger);
            }

            _api = RestService.For <IGooglePlacesApi>(Constants.BASE_API_URL, refitSettings);
        }
Beispiel #2
0
 public DomainFinder()
 {
     _google_api_key = ConfigurationManager.AppSettings.Get("google_api");
     _settings       = GoogleApiSettings.Builder
                       .WithApiKey(_google_api_key)
                       .WithType(PlaceTypes.Establishment)
                       .WithDetailLevel(DetailLevel.Contact)
                       .Build();
     _service = new GooglePlacesApiService(_settings);
 }
        public static GoogleApiQueryStringParameters CreateQueryStringParameters(this GoogleApiSettings settings)
        {
            var queryParams = new GoogleApiQueryStringParameters();

            queryParams.ApiKey   = settings.ApiKey;
            queryParams.Language = !string.IsNullOrEmpty(settings.Language) ? $"{settings.Language}" : string.Empty;

            if (settings.Countries != null && settings.Countries.Any())
            {
                queryParams.Country = string.Join("|", settings.Countries.Select(x => $"country:{x}"));
            }

            switch (settings.PlaceType)
            {
            case PlaceTypes.Address:
                queryParams.PlaceType = "address";
                break;

            case PlaceTypes.Cities:
                queryParams.PlaceType = "(cities)";
                break;

            case PlaceTypes.Establishment:
                queryParams.PlaceType = "establishment";
                break;

            case PlaceTypes.GeoCode:
                queryParams.PlaceType = "geocode";
                break;

            case  PlaceTypes.Regions:
                queryParams.PlaceType = "(regions)";
                break;
            }

            return(queryParams);
        }
 public GoogleBooksAPIService(IOptions <GoogleApiSettings> settings, IHttpClientFactory clientFactory)
 {
     _googleApiSettings = settings.Value;
     _clientFactory     = clientFactory;
 }
 public GoogleApiClient(IOptions <GoogleApiSettings> googleApiSettings)
 {
     _googleApiSettings = googleApiSettings.Value;
 }
 public GoogleCivicInfoProvider(IOptions <GoogleApiSettings> settings)
 {
     _apiSettings = settings.Value;
 }
 public DetailsController(Event_AggregatorContext context, IOptions <GoogleApiSettings> options)
 {
     _googleApiSettings = options.Value;
     _context           = context;
 }