-
Notifications
You must be signed in to change notification settings - Fork 598
/
Copy pathWeather.OpenWeather.cs
92 lines (81 loc) · 3.39 KB
/
Weather.OpenWeather.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using Iot.Device.LEDMatrix;
using Iot.Device.Graphics;
namespace LedMatrixWeather
{
internal struct OpenWeatherCoord
{
public float Lon { get; set; }
public float Lat { get; set; }
}
internal struct OpenWeather
{
public int Id { get; set; }
public string Main { get; set; }
public string Description { get; set; }
public string Icon { get; set; }
}
internal struct OpenWeatherWind
{
public float Speed { get; set; }
public float Deg { get; set; }
}
internal struct OpenWeatherClouds
{
public int All { get; set; }
}
internal struct OpenWeatherSys
{
public int Type { get; set; }
public int Id { get; set; }
public float Message { get; set; }
public string Country { get; set; }
public int Sunrise { get; set; }
public int Sunset { get; set; }
}
internal struct OpenWeatherReadings
{
public float Temp { get; set; }
public float Pressure { get; set; }
public float Humidity { get; set; }
public float TempMin { get; set; }
public float TempMax { get; set; }
}
internal struct OpenWeatherResponse
{
// This is also self-test since this is an actual response from day of first testing.
private const string ExampleJsonResponse = "{\"coord\":{\"lon\":-122.12,\"lat\":47.67},\"weather\":[{\"id\":500,\"main\":\"Rain\",\"description\":\"light rain\",\"icon\":\"10d\"},{\"id\":701,\"main\":\"Mist\",\"description\":\"mist\",\"icon\":\"50d\"}],\"base\":\"stations\",\"main\":{\"temp\":59.52,\"pressure\":1011,\"humidity\":87,\"temp_min\":57.99,\"temp_max\":61},\"visibility\":16093,\"wind\":{\"speed\":8.05,\"deg\":140},\"rain\":{\"1h\":0.63},\"clouds\":{\"all\":90},\"dt\":1569171772,\"sys\":{\"type\":1,\"id\":3417,\"message\":0.0124,\"country\":\"US\",\"sunrise\":1569160502,\"sunset\":1569204450},\"timezone\":-25200,\"id\":5808079,\"name\":\"Redmond\",\"cod\":200}";
public OpenWeatherCoord Coord { get; set; }
public OpenWeather[] Weather { get; set; }
public string Base { get; set; }
public OpenWeatherReadings Main { get; set; }
public int Visibility { get; set; }
public OpenWeatherWind Wind { get; set; }
public OpenWeatherClouds Clouds { get; set; }
public int Dt { get; set; }
public OpenWeatherSys Sys { get; set; }
public int Timezone { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public int Cod { get; set; }
public static OpenWeatherResponse FromJson(string json)
{
return JsonSerializer.Deserialize<OpenWeatherResponse>(json,
new JsonSerializerOptions()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
});
}
public static OpenWeatherResponse GetExampleResponse()
{
return FromJson(ExampleJsonResponse);
}
}
}