-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathZillowClient`1.cs
306 lines (272 loc) · 8.96 KB
/
ZillowClient`1.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
using System.Xml.Serialization;
using Zillow.Services.Schema;
namespace Zillow.Services
{
public partial class ZillowClient : IZillowClient
{
private async Task<T> CallAPIAsync<T>(string uri, Hashtable parameters)
{
try
{
// Build HttpClient request
using (var httpClient = new HttpClient())
{
// Read XML and Deserialize Object
var u = new UriBuilder(uri)
{
Query = PrepareQuery(parameters)
};
var xml = await httpClient.GetStringAsync(u.Uri);
XmlSerializer ser = new XmlSerializer(typeof(T));
return (T)ser.Deserialize(new StringReader(xml));
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message, ex);
throw ex;
}
}
#region Public Async Methods
public async Task<searchresults> GetSearchResultsAsync(string address, string citystatezip)
{
try
{
Hashtable p = new Hashtable
{
{"zws-id", Zwsid},
{"address", address},
{"citystatezip", citystatezip}
};
return await CallAPIAsync<searchresults>(ZillowURI.SearchResults, p);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
throw ex;
}
}
public async Task<zestimateResultType> GetZestimateAsync(string zpid)
{
try
{
Hashtable p = new Hashtable
{
{"zws-id", Zwsid},
{"zpid", zpid}
};
return await CallAPIAsync<zestimateResultType>(ZillowURI.ZEstimate, p);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
throw ex;
}
}
public async Task<chart> GetChartAsync(string zpid, string unittype, string width, string height)
{
try
{
Hashtable p = new Hashtable
{
{"zws-id", Zwsid},
{"zpid", zpid},
{"unit-type", unittype},
{"width", width},
{"height", height}
};
return await CallAPIAsync<chart>(ZillowURI.Chart, p);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
throw ex;
}
}
public async Task<comps> GetCompsAsync(string zpid, string count)
{
try
{
Hashtable p = new Hashtable
{
{"zws-id", Zwsid},
{"zpid", zpid},
{"count", count}
};
return await CallAPIAsync<comps>(ZillowURI.Comps, p);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
throw ex;
}
}
public async Task<regionchart> GetRegionChartAsync(string city, string state, string neighborhood, string zip, string unittype, string width, string height, SimpleChartDuration chartDuration, ChartVariant chartVariant)
{
try
{
Hashtable p = new Hashtable
{
{"zws-id", Zwsid},
{"city", city},
{"state", state},
{"neighborhood", neighborhood},
{"zip", zip},
{"unit-type", unittype},
{"width", width},
{"height", height},
{"chartDuration", ZillowExtensions.GetXmlName(chartDuration)},
{"chartVariant", chartVariant}
};
return await CallAPIAsync<regionchart>(ZillowURI.RegionChart, p);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
throw ex;
}
}
public async Task<demographicsResultType> GetDemographicsAsync(string rid, string state, string city, string neighborhood)
{
try
{
Hashtable p = new Hashtable
{
{"zws-id", Zwsid},
{"rid", rid},
{"state", state},
{"city", city},
{"neighborhood", neighborhood}
};
return await CallAPIAsync<demographicsResultType>(ZillowURI.DemoGraphics, p);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
throw ex;
}
}
public async Task<regionchildrenResultType> GetRegionChildrenAsync(string regionid, string country, string state, string county, string city, string childtype)
{
try
{
Hashtable p = new Hashtable
{
{"zws-id", Zwsid},
{"regionid", regionid},
{"country", country},
{"state", state},
{"childtype", childtype}
};
return await CallAPIAsync<regionchildrenResultType>(ZillowURI.RegionChildren, p);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
throw ex;
}
}
public async Task<rateSummaryResultType> GetRateSummaryAsync(string state, string output, string callback)
{
try
{
Hashtable p = new Hashtable
{
{"zws-id", Zwsid},
{"state", state},
{"output", output},
{"callback", callback}
};
return await CallAPIAsync<rateSummaryResultType>(ZillowURI.RateSummary, p);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
throw ex;
}
}
public async Task<paymentsSummaryResultType> GetMonthlyPaymentsAsync(int price, int down, int dollarsdown, int zip, string output, string callback)
{
try
{
Hashtable p = new Hashtable
{
{"zws-id", Zwsid},
{"price", price},
{"down", down},
{"dollarsdown", dollarsdown},
{"zip", zip},
{"output", output},
{"callback", callback}
};
return await CallAPIAsync<paymentsSummaryResultType>(ZillowURI.RegionChildren, p);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
throw ex;
}
}
public async Task<searchresults> GetDeepSearchResultsAsync(string address, string citystatezip)
{
try
{
Hashtable p = new Hashtable
{
{"zws-id", Zwsid},
{"address", address},
{"citystatezip", citystatezip}
};
return await CallAPIAsync<searchresults>(ZillowURI.DeepSearchResults, p);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
throw ex;
}
}
public async Task<comps> GetDeepCompsAsync(string zpid, string count)
{
try
{
Hashtable p = new Hashtable
{
{"zws-id", Zwsid},
{"zpid", zpid},
{"count", count}
};
return await CallAPIAsync<comps>(ZillowURI.DeepComps, p);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
throw ex;
}
}
public async Task<updatedPropertyDetails> GetUpdatedPropertyDetailsAsync(uint zpid)
{
try
{
Hashtable p = new Hashtable
{
{"zws-id", Zwsid},
{"zpid", zpid}
};
return await CallAPIAsync<updatedPropertyDetails>(ZillowURI.UpdatedPropertyDetails, p);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
throw ex;
}
}
#endregion
}
}