-
Notifications
You must be signed in to change notification settings - Fork 27
/
examples.js
55 lines (50 loc) · 1.73 KB
/
examples.js
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
// Call with ZWSID=<ZWSID> node examples.js GetZestimate
var Zillow = require("../lib/node-zillow");
var _ = require("lodash");
var params = require("./parameters");
var apiNames = _.keys(require("../lib/api-list"));
var inspect = require("eyes").inspector({ maxLength: 50000 });
// Make sure we have specified the correct API name in the arguments
var apiName = process.argv[2];
if (!_.includes(apiNames, apiName))
throw new Error("requires apiName: \n" + apiNames.join(", "));
// Instantiate a zillow object by passing in our own custom Zillow id (zswid):
var zwsid = process.env.ZWSID;
var zillow = new Zillow(zwsid);
// Call parameters based on which API we are calling
var parameters = (function() {
switch (apiName) {
case "GetDeepSearchResults":
return params.addressWithupdates;
case "GetUpdatedPropertyDetails":
return params.zpidWithUpdates;
case "GetDeepComps":
return _.extend(params.zpidWithComps, { count: 5 });
case "GetRateSummary":
return { state: "CO" };
case "GetMonthlyPayments":
return { price: 200000 };
case "GetDemographics":
return params.zip;
case "GetRegionChildren":
return { state: "CO" };
case "GetRegionChart":
return params.chart;
case "GetSearchResults":
return params.addressWithupdates;
case "GetZestimate":
return params.zpidWithZestimate;
case "GetChart":
return _.extend(params.chart, params.zpidWithZestimate);
case "GetComps":
return _.extend(params.zpidWithComps, { count: 5 });
default:
throw new Error();
}
})();
// Call the primary API function based on the arguments passed in
var example = zillow.get(apiName, parameters);
example.then(function(data) {
inspect(data);
return data;
});