forked from shantimarthaller/weather
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SIMPL#
115 lines (98 loc) · 3.27 KB
/
SIMPL#
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronIO;
using Crestron.SimplSharp.Net.Http;
using Newtonsoft.Json;
namespace WeatherClient
{
public static class WeatherClientMain
{
public static string sJsonData;
//public delegate void TempDelegate(double Value);
public delegate void StringTemp(SimplSharpString Value);
//public static TempDelegate TempToSimpl { get; set; }
public static StringTemp TempStringToSimpl { get; set; }
public static Main weatherData;
public static string GetData(string _url)
{
sJsonData = "";
try
{
Console.WriteLine(_url);
HttpClient myHttpClient = new HttpClient();
HttpClientRequest myHttpRequest = new HttpClientRequest();
HttpClientResponse myHttpResponse;
myHttpClient.KeepAlive = false;
myHttpRequest.RequestType = Crestron.SimplSharp.Net.Http.RequestType.Get;
myHttpRequest.Url.Parse(String.Format("{0}", _url));
myHttpResponse = myHttpClient.Dispatch(myHttpRequest);
sJsonData = myHttpResponse.ContentString;
weatherData = JsonConvert.DeserializeObject<Main>(sJsonData);
Console.WriteLine(weatherData.temp);
//TempToSimpl(weatherData.temp);
TempStringToSimpl(weatherData.temp.ToString("N0"));
}
catch (Exception e)
{
ErrorLog.Notice("Error in Http Request: {0}", e);
}
return sJsonData;
}
}
public class Coord
{
public double lon { get; set; }
public double lat { get; set; }
}
public class Weather
{
public int id { get; set; }
public string main { get; set; }
public string description { get; set; }
public string icon { get; set; }
}
public class Main
{
public double temp { get; set; }
public int pressure { get; set; }
public int humidity { get; set; }
public int temp_min { get; set; }
public int temp_max { get; set; }
}
public class Wind
{
public int speed { get; set; }
public int deg { get; set; }
}
public class Clouds
{
public int all { get; set; }
}
public class Sys
{
public int type { get; set; }
public int id { get; set; }
public double message { get; set; }
public string country { get; set; }
public int sunrise { get; set; }
public int sunset { get; set; }
}
public class RootObject
{
public Coord coord { get; set; }
public List<Weather> weather { get; set; }
public string @base { get; set; }
public Main main { get; set; }
public int visibility { get; set; }
public Wind wind { get; set; }
public Clouds clouds { get; set; }
public int dt { get; set; }
public Sys sys { get; set; }
public int id { get; set; }
public string name { get; set; }
public int cod { get; set; }
}
}