Exemple #1
0
        private void Initialize()
        {
            this.ForecastOperations    = new ForecastOperations(this);
            this.BaseUri               = new Uri("https://api.darksky.net/forecast/");
            this.SerializationSettings = new JsonSerializerSettings
            {
                Formatting            = Formatting.Indented,
                DateFormatHandling    = DateFormatHandling.IsoDateFormat,
                DateTimeZoneHandling  = DateTimeZoneHandling.Utc,
                NullValueHandling     = NullValueHandling.Ignore,
                ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
                ContractResolver      = new ReadOnlyJsonContractResolver(),
                Converters            = new List <JsonConverter>
                {
                    new UnixDateTimeConverter()
                }
            };

            this.SerializationSettings.Converters.Add(new TransformationJsonConverter());
            this.DeserializationSettings = new JsonSerializerSettings
            {
                DateFormatHandling    = DateFormatHandling.IsoDateFormat,
                DateTimeZoneHandling  = DateTimeZoneHandling.Utc,
                NullValueHandling     = NullValueHandling.Ignore,
                ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
                ContractResolver      = new ReadOnlyJsonContractResolver(),
                Converters            = new List <JsonConverter>
                {
                    new UnixDateTimeConverter()
                }
            };

            this.CustomInitialize();
            this.DeserializationSettings.Converters.Add(new TransformationJsonConverter());
        }
 /// <summary>
 /// Gets the forecast asynchronous.
 /// </summary>
 /// <param name="operations">The operations.</param>
 /// <param name="latitude">The latitude.</param>
 /// <param name="longitude">The longitude.</param>
 /// <param name="lang">The language.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns>The forecast</returns>
 public static async Task <Forecast> GetForecastAsync(this IForecastOperations operations, double latitude, double longitude, string lang = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var result = await operations.GetForecastWithHttpMessagesAsync(latitude, longitude, lang, null, cancellationToken).ConfigureAwait(false))
     {
         return(result.Body);
     }
 }
Exemple #3
0
 /// <summary>
 /// Creates a new WeatherAPI.NET API client with an optional custom base URI.
 /// </summary>
 /// <param name="apiKey">Your WeatherAPI.NET API key.</param>
 /// <param name="baseApiUri">The base URI to use for the API, or null for default.</param>
 public WeatherAPIClient(string apiKey, Uri baseApiUri = null)
     : base(apiKey, baseApiUri)
 {
     _astronomyOperations = ConstructAstronomyOperations();
     _forecastOperations = ConstructForecastOperations();
     _historyOperations = ConstructHistoryOperations();
     _ipLookupOperations = ConstructIPLookupOperations();
     _realtimeOperations = ConstructRealtimeOperations();
     _searchOperations = ConstructSearchOperations();
     _sportsOperations = ConstructSportsOperations();
     _timeZoneOperations = ConstructTimeZoneOperations();
 }