Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions CreativeGurus.Weather.Wunderground/Models/DailySummary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
using Newtonsoft.Json;

namespace CreativeGurus.Weather.Wunderground.Models
{
public class DailySummary
{
[JsonProperty("date")]
public Date Date { get; set; }
[JsonProperty("fog")]
public bool Fog { get; set; }
[JsonProperty("rain")]
public bool Rain { get; set; }
[JsonProperty("snow")]
public bool Snow { get; set; }
[JsonProperty("snowfallm")]
public float? SnowFallMetric { get; set; }
[JsonProperty("snowfalli")]
public float? SnowFallImperial { get; set; }
[JsonProperty("monthtodatesnowfallm")]
public float? MonthToDateSnowFallMetric { get; set; }
[JsonProperty("monthtodatesnowfalli")]
public float? MonthToDateSnowFallImperial { get; set; }
[JsonProperty("since1julsnowfallm")]
public float? Since1JulSnowFallMetric { get; set; }
[JsonProperty("since1julsnowfalli")]
public float? Since1JulSnowFallImperial { get; set; }
[JsonProperty("snowdepthm")]
public float? SnowDepthMetric { get; set; }
[JsonProperty("snowdepthi")]
public float? SnowDepthImperial { get; set; }
[JsonProperty("hail")]
public bool Hail { get; set; }
[JsonProperty("thunder")]
public bool Thunder { get; set; }
[JsonProperty("tornado")]
public bool Tornado { get; set; }
[JsonProperty("meantempm")]
public float? MeanTempMetric { get; set; }
[JsonProperty("meantempi")]
public float? MeanTempImperial { get; set; }
[JsonProperty("meandewptm")]
public float? MeanDewPointMetric { get; set; }
[JsonProperty("meandewpti")]
public float? MeanDewPopintImperial { get; set; }
[JsonProperty("meanpressurem")]
public float? MeanPressureMetric { get; set; }
[JsonProperty("meanpressurei")]
public float? MeanPressureImperial { get; set; }
[JsonProperty("meanwindspdm")]
public float? MeanWindSpeedMetric { get; set; }
[JsonProperty("meanwindspdi")]
public float? MeanWindSpeedImperial { get; set; }
[JsonProperty("meanwdire")]
public string MeanWindDirection { get; set; }
[JsonProperty("meanwdird")]
public int? MeanWindDirectionDegree { get; set; }
[JsonProperty("meanvism")]
public float? MeanVisibilityMetric { get; set; }
[JsonProperty("meanvisi")]
public float? MeanVisibilityImperial { get; set; }
[JsonProperty("humidity")]
public int? Humidity { get; set; }
[JsonProperty("maxtempm")]
public float? MaxTempMetric { get; set; }
[JsonProperty("maxtempi")]
public float? MaxTempImperial { get; set; }
[JsonProperty("mintempm")]
public float? MinTempMetric { get; set; }
[JsonProperty("mintempi")]
public float? MinTempImperial { get; set; }
[JsonProperty("maxhumidity")]
public int? MaxHumidity { get; set; }
[JsonProperty("minhumidity")]
public int? MinHumidity { get; set; }
[JsonProperty("maxdewptm")]
public float? MaxDewPointMetric { get; set; }
[JsonProperty("maxdewpti")]
public float? MaxDewPointImperial { get; set; }
[JsonProperty("mindewptm")]
public float? MinDewPointMetric { get; set; }
[JsonProperty("mindewpti")]
public float? MinDewPointImperial { get; set; }
[JsonProperty("maxpressurem")]
public float? MaxPressureMetric { get; set; }
[JsonProperty("maxpressurei")]
public float? MaxPressureImperial { get; set; }
[JsonProperty("minpressurem")]
public float? MinPressureMetric { get; set; }
[JsonProperty("minpressurei")]
public float? MinPressureImperial { get; set; }
[JsonProperty("maxwspdm")]
public float? MaxWindSpeedMetric { get; set; }
[JsonProperty("maxwspdi")]
public float? MaxWindSpeedImperial { get; set; }
[JsonProperty("minwspdm")]
public float? MinWindSpeedMetric { get; set; }
[JsonProperty("minwspdi")]
public float? MinWindSpeedImperial { get; set; }
[JsonProperty("maxvism")]
public float? MaxVisibilityMetric { get; set; }
[JsonProperty("maxvisi")]
public float? MaxVisibilityImperial { get; set; }
[JsonProperty("minvism")]
public float? MinVisibilityMetric { get; set; }
[JsonProperty("minvisi")]
public float? MinVisibilityImperial { get; set; }
[JsonProperty("gdegreedays")]
public int? GrowingDegreeDays { get; set; }
[JsonProperty("heatingdegreedays")]
public int? HeatingDegreeDays { get; set; }
[JsonProperty("coolingdegreedays")]
public int? CoolingDegreeDays { get; set; }
[JsonProperty("precipm")]
public float? PrecipitationMetric { get; set; }
[JsonProperty("precipi")]
public float? PrecipitationImperial { get; set; }
[JsonProperty("precipsource")]
public string PrecipitationSource { get; set; }
[JsonProperty("heatingdegreedaysnormal")]
public int? HeatingDegreeDaysNormal { get; set; }
[JsonProperty("monthtodateheatingdegreedays")]
public int? MonthToDateHeatingDegreeDays { get; set; }
[JsonProperty("monthtodateheatingdegreedaysnormal")]
public int? MonthToDateHeatingDegreeDaysNormal { get; set; }
[JsonProperty("since1sepheatingdegreedays")]
public int? Since1SepHeatingDegreeDays { get; set; }
[JsonProperty("since1sepheatingdegreedaysnormal")]
public int? Since1SepHeatingDegreeDaysNormal { get; set; }
[JsonProperty("since1julheatingdegreedays")]
public int? Since1JulHeatingDegreeDays { get; set; }
[JsonProperty("since1julheatingdegreedaysnormal")]
public int? Since1JulHeatingDegreeDaysNormal { get; set; }
[JsonProperty("coolingdegreedaysnormal")]
public int? CoolingDegreeDaysNormal { get; set; }
[JsonProperty("monthtodatecoolingdegreedays")]
public int? MonthToDateCoolingDegreeDays { get; set; }
[JsonProperty("monthtodatecoolingdegreedaysnormal")]
public int? MonthToDateCoolingDegreeDaysNormal { get; set; }
[JsonProperty("since1sepcoolingdegreedays")]
public int? Since1SepCoolingDegreeDays { get; set; }
[JsonProperty("since1sepcoolingdegreedaysnormal")]
public int? Since1SepCoolingDegreeDaysNormal { get; set; }
[JsonProperty("since1jancoolingdegreedays")]
public int? Since1JanCoolingDegreeDays { get; set; }
[JsonProperty("since1jancoolingdegreedaysnormal")]
public int? Since1JanCoolingDegreeDaysNormal { get; set; }

}
}
16 changes: 16 additions & 0 deletions CreativeGurus.Weather.Wunderground/Models/History.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Newtonsoft.Json;

namespace CreativeGurus.Weather.Wunderground.Models
{
public class History
{
[JsonProperty("date")]
public Date Date { get; set; }
[JsonProperty("utcdate")]
public Date UTCDATE { get; set; }
[JsonProperty("observations")]
public Observation[] Observations { get; set; }
[JsonProperty("dailysummary")]
public DailySummary[] DailySummaries { get; set; }
}
}
19 changes: 19 additions & 0 deletions CreativeGurus.Weather.Wunderground/Models/HistoryDate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace CreativeGurus.Weather.Wunderground.Models
{
public class HistoryDate
{
public HistoryDate(int Year, int Month, int Day)
{
this.Year = Year;
this.Month = Month;
this.Day = Day;
}
public int Day { get; set; }
public int Year { get; set; }
public int Month { get; set; }
}
}
73 changes: 73 additions & 0 deletions CreativeGurus.Weather.Wunderground/Models/Observation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Newtonsoft.Json;

namespace CreativeGurus.Weather.Wunderground.Models
{
public class Observation
{
[JsonProperty("date")]
public Date Date { get; set; }
[JsonProperty("utcdate")]
public Date UTCDATE { get; set; }
[JsonProperty("tempm")]
public float? TempCelcius { get; set; }
[JsonProperty("tempi")]
public float? TempFahrenheit { get; set; }
[JsonProperty("dewptm")]
public float? DewPointMetric { get; set; }
[JsonProperty("dewpti")]
public float? DewPointImparial { get; set; }
[JsonProperty("hum")]
public int? Humidity { get; set; }
[JsonProperty("wspdm")]
public float? WindSpeedMetric { get; set; }
[JsonProperty("wspdi")]
public float? WindSpeedImperial { get; set; }
[JsonProperty("wgustm")]
public float? WindGustMetric { get; set; }
[JsonProperty("wgusti")]
public float? WindGurstImperial { get; set; }
[JsonProperty("wdird")]
public int? WindDirectionDegree { get; set; }
[JsonProperty("wdire")]
public string WindDirection { get; set; }
[JsonProperty("vism")]
public float? VisibilityMetric { get; set; }
[JsonProperty("visi")]
public float? VisibilityImperial { get; set; }
[JsonProperty("pressurem")]
public float? PressureMetric { get; set; }
[JsonProperty("pressurei")]
public float? PressureImperial { get; set; }
[JsonProperty("windchillm")]
public float? WindChillMetric { get; set; }
[JsonProperty("windchilli")]
public float? WindChillImperial { get; set; }
[JsonProperty("heatindexm")]
public float? HeatIndexMetric { get; set; }
[JsonProperty("heatindexi")]
public float? HeatIndexImperial { get; set; }
[JsonProperty("precipm")]
public float? PrecipitationMetric { get; set; }
[JsonProperty("precipi")]
public float? PrecipitationImperial { get; set; }
[JsonProperty("conds")]
public string Conditions { get; set; }
[JsonProperty("icon")]
public string Icon { get; set; }
[JsonProperty("fog")]
public bool Fog { get; set; }
[JsonProperty("rain")]
public bool Rain { get; set; }
[JsonProperty("snow")]
public bool Snow { get; set; }
[JsonProperty("hail")]
public bool Hail { get; set; }
[JsonProperty("thunder")]
public bool Thunder { get; set; }
[JsonProperty("tornado")]
public bool Tornado { get; set; }
[JsonProperty("metar")]
public string Metar { get; set; }

}
}
11 changes: 9 additions & 2 deletions CreativeGurus.Weather.Wunderground/Models/QueryOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using CreativeGurus.Weather.Wunderground.Models;
using System;
namespace CreativeGurus.Weather.Wunderground
{
public class QueryOptions
Expand Down Expand Up @@ -87,5 +88,11 @@ public QueryOptions()
/// </summary>
/// <value>The PWSI.</value>
public string PWSId { get; set; }
}

/// <summary>
/// Date for the history request
/// </summary>
/// <value>The date</value>
public HistoryDate HistoryDate { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace CreativeGurus.Weather.Wunderground.Models
{
public class HistoryResponse
{
public Models.History History { get; set; }
public Models.Response Response { get; set; }
}
}
6 changes: 4 additions & 2 deletions CreativeGurus.Weather.Wunderground/Utilities/UrlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ internal static class UrlBuilder
internal static string BuildUrl(string baseUrl, string apiKey, Feature feature, QueryType queryType, QueryOptions options)
{
StringBuilder sb = new StringBuilder();

sb.AppendFormat("{0}/{1}/{2}", baseUrl, apiKey, feature.ToString().ToLower());
if (feature != Feature.History)
sb.AppendFormat("{0}/{1}/{2}", baseUrl, apiKey, feature.ToString().ToLower());
else
sb.AppendFormat("{0}/{1}/{2}", baseUrl, apiKey, feature.ToString().ToLower() + "_" + options.HistoryDate.Year.ToString() + options.HistoryDate.Month.ToString() + options.HistoryDate.Day.ToString());

if (!string.IsNullOrWhiteSpace(options?.Language)) { sb.AppendFormat("/lang:{0}", options?.Language); } //Language
if (options?.UsePWS == true) { sb.AppendFormat("/pws:{0}", options?.UsePWS); } // Use Personal weather station
Expand Down
12 changes: 12 additions & 0 deletions CreativeGurus.Weather.Wunderground/WeatherClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ public async Task<ForecastResponse> GetForecastAsync(QueryType queryType, QueryO
return await forecast.GetDataAsync(Feature.Forecast, queryType, options).ConfigureAwait(false);
}

public HistoryResponse GetHistory(QueryType queryType, QueryOptions options = null)
{
Service<HistoryResponse> history = new Service<HistoryResponse>(_apiKey, _baseUrl);
return history.GetData(Feature.History, queryType, options);
}

public async Task<HistoryResponse> GetHistoryAsync(QueryType queryType, QueryOptions options = null)
{
Service<HistoryResponse> history = new Service<HistoryResponse>(_apiKey, _baseUrl);
return await history.GetDataAsync(Feature.Forecast, queryType, options).ConfigureAwait(false);
}

public GeoLookupResponse GetGeoLookup(QueryType queryType, QueryOptions options = null)
{
Service<GeoLookupResponse> forecast = new Service<GeoLookupResponse>(_apiKey, _baseUrl);
Expand Down
13 changes: 12 additions & 1 deletion Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private static async Task<bool> Examples()
//List of supported languages
//https://www.wunderground.com/weather/api/d/docs?d=language-support&MR=1

string key = "{Your API Key Here}";
string key = "{Insert your key here}";

WeatherClient client = new WeatherClient(key);

Expand Down Expand Up @@ -49,6 +49,17 @@ private static async Task<bool> Examples()
//var f7 = client.GetForecast(QueryType.USCity, new QueryOptions() { City = "Dallas", State = "TX" }); //Gets data for a US City
//var f8 = client.GetForecast(QueryType.ZipCode, new QueryOptions() { ZipCode = "94107" }); //Gets data by US Zip Code

//Sample History
//var h1 = client.GetHistory(QueryType.AirportCode, new QueryOptions() { AirportCode = "DFW", HistoryDate = new HistoryDate(2017, 06, 25) }); //Gets data by Airport Code
//var h2 = client.GetHistory(QueryType.AutoIp, new QueryOptions() { HistoryDate = new HistoryDate(2017, 06, 25) }); //Gets data by the detected IP address of the calling client
//var h3 = client.GetHistory(QueryType.GlobalCity, new QueryOptions() { Country = "France", City = "Paris", HistoryDate = new HistoryDate(2017, 06, 25) }); //Gets data by country and city
//var h4 = client.GetHistory(QueryType.GPS, new QueryOptions() { Latitude = "37.776289", Longitude = "-122.395234", HistoryDate = new HistoryDate(2017, 06, 25) }); //Gets data by GPS coordinates
//var h5 = client.GetHistory(QueryType.LinkId, new QueryOptions() { LinkId = "00000.1.16172", HistoryDate = new HistoryDate(2017, 06, 25) }); //Gets data by Weather Underground Link ID
//var h6 = client.GetHistory(QueryType.PWSId, new QueryOptions() { PWSId = "KMNCHASK10", HistoryDate = new HistoryDate(2017, 06, 25) }); //Gets data from a personal weather station by ID
//var h7 = client.GetHistory(QueryType.USCity, new QueryOptions() { City = "Dallas", State = "TX", HistoryDate = new HistoryDate(2017, 06, 25) }); //Gets data for a US City
//var h8 = client.GetHistory(QueryType.ZipCode, new QueryOptions() { ZipCode = "94107", HistoryDate = new HistoryDate(2017, 06, 25) }); //Gets data by US Zip Code


//Sample GeoLookups
//var g1 = client.GetGeoLookup(QueryType.AirportCode, new QueryOptions() { AirportCode = "DFW" }); //Gets data by Airport Code
//var g2 = client.GetGeoLookup(QueryType.AutoIp); //Gets data by the detected IP address of the calling client
Expand Down