zillow4r 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/Gemfile +18 -0
  2. data/Gemfile.lock +23 -0
  3. data/README.md +69 -0
  4. data/Rakefile +53 -0
  5. data/VERSION +1 -0
  6. data/lib/zillow4r.rb +49 -0
  7. data/lib/zillow4r/api.rb +25 -0
  8. data/lib/zillow4r/api/base.rb +5 -0
  9. data/lib/zillow4r/api/chart.rb +12 -0
  10. data/lib/zillow4r/api/comps.rb +13 -0
  11. data/lib/zillow4r/api/deep_comps.rb +13 -0
  12. data/lib/zillow4r/api/deep_search_results.rb +12 -0
  13. data/lib/zillow4r/api/demographics.rb +38 -0
  14. data/lib/zillow4r/api/region_chart.rb +12 -0
  15. data/lib/zillow4r/api/region_children.rb +14 -0
  16. data/lib/zillow4r/api/search_results.rb +12 -0
  17. data/lib/zillow4r/api/updated_property_details.rb +52 -0
  18. data/lib/zillow4r/api/zestimate.rb +15 -0
  19. data/lib/zillow4r/models.rb +189 -0
  20. data/test/fixtures/chart.xml +19 -0
  21. data/test/fixtures/comps.xml +189 -0
  22. data/test/fixtures/deep_comps.xml +536 -0
  23. data/test/fixtures/deep_search_results.xml +102 -0
  24. data/test/fixtures/demographics.xml +849 -0
  25. data/test/fixtures/region_chart.xml +18 -0
  26. data/test/fixtures/region_children.xml +868 -0
  27. data/test/fixtures/search_results.xml +91 -0
  28. data/test/fixtures/updated_property_details.xml +75 -0
  29. data/test/fixtures/zestimate.xml +93 -0
  30. data/test/test_helper.rb +26 -0
  31. data/test/unit/chart_test.rb +18 -0
  32. data/test/unit/comps_test.rb +50 -0
  33. data/test/unit/deep_comps_test.rb +50 -0
  34. data/test/unit/deep_search_results_test.rb +28 -0
  35. data/test/unit/demographics_test.rb +39 -0
  36. data/test/unit/region_chart_test.rb +18 -0
  37. data/test/unit/region_children_test.rb +41 -0
  38. data/test/unit/search_results_test.rb +28 -0
  39. data/test/unit/updated_property_details_test.rb +65 -0
  40. data/test/unit/zestimate_test.rb +52 -0
  41. data/zillow4r.gemspec +105 -0
  42. metadata +183 -0
@@ -0,0 +1,91 @@
1
+ <SearchResults:searchresults xsi:schemaLocation="http://www.zillow.com/static/xsd/SearchResults.xsd /vstatic/ae1bf8a790b67ef2e902d2bc04046f02/static/xsd/SearchResults.xsd">
2
+ <request>
3
+ <address>2114 Bigelow Ave</address>
4
+ <citystatezip>Seattle, WA</citystatezip>
5
+ </request>
6
+ <message>
7
+ <text>Request successfully processed</text>
8
+ <code>0</code>
9
+ </message>
10
+ <response>
11
+ <results>
12
+ <result>
13
+ <zpid>48749425</zpid>
14
+ <links>
15
+ <homedetails>
16
+ http://www.zillow.com/homedetails/2114-Bigelow-Ave-N-Seattle-WA-98109/48749425_zpid/
17
+ </homedetails>
18
+ <graphsanddata>
19
+ http://www.zillow.com/homedetails/charts/48749425_zpid,1year_chartDuration/?cbt=7522682882544325802%7E9%7EY2EzX18jtvYTCel5PgJtPY1pmDDLxGDZXzsfRy49lJvCnZ4bh7Fi9w**
20
+ </graphsanddata>
21
+ <mapthishome>http://www.zillow.com/homes/map/48749425_zpid/</mapthishome>
22
+ <myestimator>
23
+ http://www.zillow.com/myestimator/Edit.htm?zprop=48749425
24
+ </myestimator>
25
+ <myzestimator deprecated="true">
26
+ http://www.zillow.com/myestimator/Edit.htm?zprop=48749425
27
+ </myzestimator>
28
+ <comparables>http://www.zillow.com/homes/comps/48749425_zpid/</comparables>
29
+ </links>
30
+ <address>
31
+ <street>2114 Bigelow Ave N</street>
32
+ <zipcode>98109</zipcode>
33
+ <city>Seattle</city>
34
+ <state>WA</state>
35
+ <latitude>47.63793</latitude>
36
+ <longitude>-122.347936</longitude>
37
+ </address>
38
+ <zestimate>
39
+ <amount currency="USD">1219500</amount>
40
+ <last-updated>11/03/2009</last-updated>
41
+ <oneWeekChange deprecated="true"/>
42
+ <valueChange duration="30" currency="USD">-41500</valueChange>
43
+ <valuationRange>
44
+ <low currency="USD">1024380</low>
45
+ <high currency="USD">1378035</high>
46
+ </valuationRange>
47
+ <percentile>0</percentile>
48
+ </zestimate>
49
+ <localRealEstate>
50
+ <region id="271856" type="neighborhood" name="East Queen Anne">
51
+ <zindexValue>525,397</zindexValue>
52
+ <zindexOneYearChange>-0.144</zindexOneYearChange>
53
+ <links>
54
+ <overview>
55
+ http://www.zillow.com/local-info/WA-Seattle/East-Queen-Anne/r_271856/
56
+ </overview>
57
+ <forSaleByOwner>
58
+ http://www.zillow.com/homes/fsbo/East-Queen-Anne-Seattle-WA/
59
+ </forSaleByOwner>
60
+ <forSale>
61
+ http://www.zillow.com/homes/for_sale/East-Queen-Anne-Seattle-WA/
62
+ </forSale>
63
+ </links>
64
+ </region>
65
+ <region id="16037" type="city" name="Seattle">
66
+ <zindexValue>381,764</zindexValue>
67
+ <zindexOneYearChange>-0.074</zindexOneYearChange>
68
+ <links>
69
+ <overview>
70
+ http://www.zillow.com/local-info/WA-Seattle/r_16037/
71
+ </overview>
72
+ <forSaleByOwner>http://www.zillow.com/homes/fsbo/Seattle-WA/</forSaleByOwner>
73
+ <forSale>http://www.zillow.com/homes/for_sale/Seattle-WA/</forSale>
74
+ </links>
75
+ </region>
76
+ <region id="59" type="state" name="Washington">
77
+ <zindexValue>263,278</zindexValue>
78
+ <zindexOneYearChange>-0.066</zindexOneYearChange>
79
+ <links>
80
+ <overview>
81
+ http://www.zillow.com/local-info/WA-home-value/r_59/
82
+ </overview>
83
+ <forSaleByOwner>http://www.zillow.com/homes/fsbo/WA/</forSaleByOwner>
84
+ <forSale>http://www.zillow.com/homes/for_sale/WA/</forSale>
85
+ </links>
86
+ </region>
87
+ </localRealEstate>
88
+ </result>
89
+ </results>
90
+ </response>
91
+ </SearchResults:searchresults>
@@ -0,0 +1,75 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <UpdatedPropertyDetails:updatedPropertyDetails xsi:schemaLocation="http://www.zillow.com/static/xsd/UpdatedPropertyDetails.xsd /vstatic/e6e5f302965f32ad16114f7a97ba3d89/static/xsd/UpdatedPropertyDetails.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:UpdatedPropertyDetails="http://www.zillow.com/static/xsd/UpdatedPropertyDetails.xsd">
3
+ <request>
4
+ <zpid>48749425</zpid>
5
+ </request>
6
+ <message>
7
+ <text>Request successfully processed</text>
8
+ <code>0</code>
9
+ </message>
10
+ <response>
11
+ <zpid>48749425</zpid>
12
+ <pageViewCount>
13
+ <currentMonth>172</currentMonth>
14
+ <total>4149</total>
15
+ </pageViewCount>
16
+ <address>
17
+ <street>2114 Bigelow Ave N</street>
18
+ <zipcode>98109</zipcode>
19
+ <city>Seattle</city>
20
+ <state>WA</state>
21
+ <latitude>47.637924</latitude>
22
+ <longitude>-122.347929</longitude>
23
+ </address>
24
+ <posting>
25
+ <status>Active</status>
26
+ <agentName>John Blacksmith</agentName>
27
+ <agentProfileUrl>/profile/John.Blacksmith</agentProfileUrl>
28
+ <brokerage>Lake and Company Real Estate</brokerage>
29
+ <type>For sale by agent</type>
30
+ <lastUpdatedDate>2008-06-05 10:28:00.0</lastUpdatedDate>
31
+ <externalUrl>http://mls.lakere.com/srch_mls/detail.php?mode=ag&LN=28097669&t=listings&l=</externalUrl>
32
+ <mls>28097669</mls>
33
+ </posting>
34
+ <price currency="USD">1290000</price>
35
+ <links>
36
+ <homeDetails>http://www.zillow.com/HomeDetails.htm?zprop=48749425</homeDetails>
37
+ <photoGallery>http://www.zillow.com/Gallery.htm?zpid=48749425</photoGallery>
38
+ <homeInfo>http://www.zillow.com/HomeInfo.htm?zprop=48749425</homeInfo>
39
+ </links>
40
+ <images>
41
+ <count>17</count>
42
+ <image>
43
+ <url>http://images3.zillow.com/is/image/i0/i0/i64/ISz23uixze1pr7.jpg?op_sharpen=1&qlt=90&size=400,400</url>
44
+ <url>http://images1.zillow.com/is/image/i0/i0/i64/ISz23uj5vihxnn.jpg?op_sharpen=1&qlt=90&size=400,400</url>
45
+ <url>http://images1.zillow.com/is/image/i0/i0/i64/ISz0l5yjj5pajn.jpg?op_sharpen=1&qlt=90&size=400,400</url>
46
+ <url>http://images2.zillow.com/is/image/i0/i0/i64/ISz23ukda6z543.jpg?op_sharpen=1&qlt=90&size=400,400</url>
47
+ <url>http://images1.zillow.com/is/image/i0/i0/i64/ISz0l5xk0loazn.jpg?op_sharpen=1&qlt=90&size=400,400</url>
48
+ </image>
49
+ </images>
50
+ <editedFacts>
51
+ <useCode>Single family</useCode>
52
+ <bedrooms>4</bedrooms>
53
+ <bathrooms>3.0</bathrooms>
54
+ <finishedSqFt>3470</finishedSqFt>
55
+ <lotSizeSqFt>4680</lotSizeSqFt>
56
+ <yearBuilt>1924</yearBuilt>
57
+ <yearUpdated>2003</yearUpdated>
58
+ <numFloors>2</numFloors>
59
+ <basement>Finished</basement>
60
+ <roof>Composition</roof>
61
+ <view>Water, City, Mountain</view>
62
+ <parkingType>Off-street</parkingType>
63
+ <heatingSources>Gas</heatingSources>
64
+ <heatingSystem>Forced air</heatingSystem>
65
+ <appliances>Dishwasher, Dryer, Freezer, Garbage disposal, Microwave, Range / Oven, Refrigerator, Washer</appliances>
66
+ <floorCovering>Hardwood, Carpet, Tile</floorCovering>
67
+ <rooms>Laundry room, Walk-in closet, Master bath, Office, Dining room, Family room, Breakfast nook</rooms>
68
+ </editedFacts>
69
+ <homeDescription>Bright, spacious, 4 bedroom/3 bath Craftsman, with stunning, expansive views, on one of Queen Anne's finest streets. Views of Lk Union, Lk Washington,the Cascades from Mt. Baker to Mt. Rainier, and the city-from two levels and 2 view decks. Craftsman charm intact: hardwood floors, cove moldings, crystal doorknobs, Batchelder tile fireplace. Huge gourmet eat-in kitchen with slab granite countertops, deluxe master suite, theater-like media room, level rear yard with garden space and covered patio.</homeDescription>
70
+ <neighborhood>Queen Anne</neighborhood>
71
+ <schoolDistrict>Seattle</schoolDistrict>
72
+ <elementarySchool>John Hay</elementarySchool>
73
+ <middleSchool>McClure</middleSchool>
74
+ </response>
75
+ </UpdatedPropertyDetails:updatedPropertyDetails>
@@ -0,0 +1,93 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <Zestimate:zestimate xsi:schemaLocation="http://www.zillow.com/static/xsd/Zestimate.xsd /vstatic/ae1bf8a790b67ef2e902d2bc04046f02/static/xsd/Zestimate.xsd">
3
+ <request>
4
+ <zpid>48749425</zpid>
5
+ </request>
6
+ <message>
7
+ <text>Request successfully processed</text>
8
+ <code>0</code>
9
+ </message>
10
+ <response>
11
+ <zpid>48749425</zpid>
12
+ <links>
13
+ <homedetails>
14
+ http://www.zillow.com/homedetails/2114-Bigelow-Ave-N-Seattle-WA-98109/48749425_zpid/
15
+ </homedetails>
16
+ <graphsanddata>
17
+ http://www.zillow.com/homedetails/charts/48749425_zpid,1year_chartDuration/?cbt=2950402095890968938%7E4%7ECh-lwa20e2Scegkf_Ev1dsQ2hJD7f74f1dovt2o0BMi2IuvfsZN-sg**
18
+ </graphsanddata>
19
+ <mapthishome>http://www.zillow.com/homes/map/48749425_zpid/</mapthishome>
20
+ <myestimator>
21
+ http://www.zillow.com/myestimator/Edit.htm?zprop=48749425
22
+ </myestimator>
23
+ <myzestimator deprecated="true">
24
+ http://www.zillow.com/myestimator/Edit.htm?zprop=48749425
25
+ </myzestimator>
26
+ <comparables>http://www.zillow.com/homes/comps/48749425_zpid/</comparables>
27
+ </links>
28
+ <address>
29
+ <street>2114 Bigelow Ave N</street>
30
+ <zipcode>98109</zipcode>
31
+ <city>Seattle</city>
32
+ <state>WA</state>
33
+ <latitude>47.63793</latitude>
34
+ <longitude>-122.347936</longitude>
35
+ </address>
36
+ <zestimate>
37
+ <amount currency="USD">1219500</amount>
38
+ <last-updated>11/03/2009</last-updated>
39
+ <oneWeekChange deprecated="true"/>
40
+ <valueChange duration="30" currency="USD">-41500</valueChange>
41
+ <valuationRange>
42
+ <low currency="USD">1024380</low>
43
+ <high currency="USD">1378035</high>
44
+ </valuationRange>
45
+ <percentile>95</percentile>
46
+ </zestimate>
47
+ <localRealEstate>
48
+ <region id="271856" type="neighborhood" name="East Queen Anne">
49
+ <zindexValue>525,397</zindexValue>
50
+ <zindexOneYearChange>-0.144</zindexOneYearChange>
51
+ <links>
52
+ <overview>
53
+ http://www.zillow.com/local-info/WA-Seattle/East-Queen-Anne/r_271856/
54
+ </overview>
55
+ <forSaleByOwner>
56
+ http://www.zillow.com/homes/fsbo/East-Queen-Anne-Seattle-WA/
57
+ </forSaleByOwner>
58
+ <forSale>
59
+ http://www.zillow.com/homes/for_sale/East-Queen-Anne-Seattle-WA/
60
+ </forSale>
61
+ </links>
62
+ </region>
63
+ <region id="16037" type="city" name="Seattle">
64
+ <zindexValue>381,764</zindexValue>
65
+ <zindexOneYearChange>-0.074</zindexOneYearChange>
66
+ <links>
67
+ <overview>
68
+ http://www.zillow.com/local-info/WA-Seattle/r_16037/
69
+ </overview>
70
+ <forSaleByOwner>http://www.zillow.com/homes/fsbo/Seattle-WA/</forSaleByOwner>
71
+ <forSale>http://www.zillow.com/homes/for_sale/Seattle-WA/</forSale>
72
+ </links>
73
+ </region>
74
+ <region id="59" type="state" name="Washington">
75
+ <zindexValue>263,278</zindexValue>
76
+ <zindexOneYearChange>-0.066</zindexOneYearChange>
77
+ <links>
78
+ <overview>
79
+ http://www.zillow.com/local-info/WA-home-value/r_59/
80
+ </overview>
81
+ <forSaleByOwner>http://www.zillow.com/homes/fsbo/WA/</forSaleByOwner>
82
+ <forSale>http://www.zillow.com/homes/for_sale/WA/</forSale>
83
+ </links>
84
+ </region>
85
+ </localRealEstate>
86
+ <regions>
87
+ <zipcode-id>99569</zipcode-id>
88
+ <city-id>16037</city-id>
89
+ <county-id>207</county-id>
90
+ <state-id>59</state-id>
91
+ </regions>
92
+ </response>
93
+ </Zestimate:zestimate>
@@ -0,0 +1,26 @@
1
+ # add to the load path (done by loading gems for you, just not in test)
2
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
3
+
4
+ # require dependencies
5
+ require 'bundler'
6
+ require 'test/unit'
7
+ Bundler.setup
8
+ Bundler.require(:default)
9
+ Bundler.require(:development)
10
+
11
+ # require the files
12
+ require 'zillow4r'
13
+
14
+ # set a dummy ZWS_ID
15
+ Zillow4r.zws_id = "TEST_ZWS_ID"
16
+
17
+ FIXTURE_PATH = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
18
+
19
+ class ZillowTest < Test::Unit::TestCase
20
+
21
+ protected
22
+
23
+ def mock_http_response(filename)
24
+ OpenURI.stubs(:open_uri).returns(File.open(FIXTURE_PATH + "/#{filename}"))
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))
2
+
3
+ class ChartTest < ZillowTest
4
+
5
+ def test_webservice_url
6
+ path = Zillow4r.build_path(Zillow4r::Api::Chart, "unit-type" => "percent", "zpid" => 48749425, "width" => 300, "height" => 150)
7
+ assert_equal("/webservice/GetChart.htm?zws-id=TEST_ZWS_ID&unit-type=percent&zpid=48749425&width=300&height=150", path)
8
+ end
9
+
10
+ def test_parsing
11
+ # mock response
12
+ mock_http_response("chart.xml")
13
+
14
+ response = Zillow4r.fetch_chart("unit-type" => "percent", "zpid" => 48749425, "width" => 300, "height" => 150)
15
+ assert_equal("http://www.zillow.com/app?chartDuration=1year&chartType=partner&height=150&page=webservice%2FGetChart&service=chart&showPercent=true&width=300&zpid=48749425", response.chart_url)
16
+ end
17
+
18
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))
2
+
3
+ class CompsTest < ZillowTest
4
+
5
+ def test_webservice_url
6
+ path = Zillow4r.build_path(Zillow4r::Api::Comps, :zpid => 48749425, :count => 5)
7
+ assert_equal("/webservice/GetComps.htm?zws-id=TEST_ZWS_ID&zpid=48749425&count=5", path)
8
+ end
9
+
10
+ def test_parsing
11
+ # mock response
12
+ mock_http_response("comps.xml")
13
+
14
+ response = Zillow4r.fetch_comps(:zpid => 48749425, :count => 5)
15
+
16
+ # test principal property
17
+ principal = response.principal
18
+ assert(principal)
19
+ assert_equal(Zillow4r::Property, principal.class)
20
+ assert_equal(48749425, principal.zpid)
21
+
22
+ principal_address = principal.address
23
+ assert(principal_address)
24
+ assert_equal(Zillow4r::Address, principal_address.class)
25
+ assert_equal("2114 Bigelow Ave N", principal_address.street)
26
+
27
+ principal_zestimate = principal.zestimate
28
+ assert(principal_zestimate)
29
+ assert_equal(Zillow4r::Zestimate, principal_zestimate.class)
30
+ assert_equal(1124072, principal_zestimate.amount)
31
+
32
+ # test comparables
33
+ comparables = response.comparables
34
+ assert_equal(5, comparables.length)
35
+ comparables.each do |comparable|
36
+ assert_equal(Zillow4r::ComparableProperty, comparable.class)
37
+ # just make sure we're parsing something instead of testing every value
38
+ assert(comparable.zestimate.amount)
39
+ assert(comparable.address.street)
40
+ assert(comparable.links.links.length > 0)
41
+ end
42
+
43
+ assert_equal(0.257106811263241, comparables[0].score)
44
+ assert_equal(0.31179534464349695, comparables[1].score)
45
+ assert_equal(0.35103815285082135, comparables[2].score)
46
+ assert_equal(0.3738944725221039, comparables[3].score)
47
+ assert_equal(0.40222697483306563, comparables[4].score)
48
+ end
49
+
50
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))
2
+
3
+ class DeepCompsTest < ZillowTest
4
+
5
+ def test_webservice_url
6
+ path = Zillow4r.build_path(Zillow4r::Api::DeepComps, :zpid => 48749425, :count => 5)
7
+ assert_equal("/webservice/GetDeepComps.htm?zws-id=TEST_ZWS_ID&zpid=48749425&count=5", path)
8
+ end
9
+
10
+ def test_parsing
11
+ # mock response
12
+ mock_http_response("deep_comps.xml")
13
+
14
+ response = Zillow4r.fetch_deep_comps(:zpid => 48749425, :count => 5)
15
+
16
+ # test principal property
17
+ principal = response.principal
18
+ assert(principal)
19
+ assert_equal(Zillow4r::Property, principal.class)
20
+ assert_equal(48749425, principal.zpid)
21
+
22
+ principal_address = principal.address
23
+ assert(principal_address)
24
+ assert_equal(Zillow4r::Address, principal_address.class)
25
+ assert_equal("2114 Bigelow Ave N", principal_address.street)
26
+
27
+ principal_zestimate = principal.zestimate
28
+ assert(principal_zestimate)
29
+ assert_equal(Zillow4r::Zestimate, principal_zestimate.class)
30
+ assert_equal(1219500, principal_zestimate.amount)
31
+
32
+ # test comparables
33
+ comparables = response.comparables
34
+ assert_equal(5, comparables.length)
35
+ comparables.each do |comparable|
36
+ assert_equal(Zillow4r::ComparableProperty, comparable.class)
37
+ # just make sure we're parsing something instead of testing every value
38
+ assert(comparable.zestimate.amount)
39
+ assert(comparable.address.street)
40
+ assert(comparable.links.links.length > 0)
41
+ end
42
+
43
+ assert_equal(0.156502, comparables[0].score)
44
+ assert_equal(0.156114, comparables[1].score)
45
+ assert_equal(0.153359, comparables[2].score)
46
+ assert_equal(0.15329, comparables[3].score)
47
+ assert_equal(0.153177, comparables[4].score)
48
+ end
49
+
50
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))
2
+
3
+ class DeepSearchResultsTest < ZillowTest
4
+
5
+ def test_webservice_url
6
+ path = Zillow4r.build_path(Zillow4r::Api::DeepSearchResults, :address => "2114 Bigelow Ave", :citystatezip => "Seattle, WA")
7
+ assert_equal("/webservice/GetDeepSearchResults.htm?zws-id=TEST_ZWS_ID&address=2114+Bigelow+Ave&citystatezip=Seattle%2C+WA", path)
8
+ end
9
+
10
+ def test_parsing
11
+ # mock response
12
+ mock_http_response("deep_search_results.xml")
13
+
14
+ response = Zillow4r.fetch_deep_search_results(:address => "2114 Bigelow Ave", :citystatezip => "Seattle, WA")
15
+
16
+ # test results
17
+ results = response.results
18
+ assert_equal(1, results.length)
19
+
20
+ result = results.first
21
+ assert_equal(Zillow4r::Property, result.class)
22
+ assert_equal(48749425, result.zpid)
23
+ assert(result.links.links.length > 0)
24
+ assert(result.address.street)
25
+ assert(result.zestimate.amount)
26
+ end
27
+
28
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'test_helper.rb'))
2
+
3
+ class DemographicsTest < ZillowTest
4
+
5
+ def test_webservice_url
6
+ path = Zillow4r.build_path(Zillow4r::Api::Demographics, :city => "Seattle", :state => "WA")
7
+ assert_equal("/webservice/GetDemographics.htm?zws-id=TEST_ZWS_ID&city=Seattle&state=WA", path)
8
+ end
9
+
10
+ def test_parsing
11
+ # mock response
12
+ mock_http_response("demographics.xml")
13
+
14
+ response = Zillow4r.fetch_demographics(:city => "Seattle", :state => "WA")
15
+ assert_equal("http://www.zillow.com/homes/for_sale/Ballard-Seattle-WA/", response.links["forsale"])
16
+
17
+ # test city demographics
18
+ assert_equal(37, response.city_median_age)
19
+ assert_equal(45736, response.city_median_household_income)
20
+ assert_equal(2.08, response.city_average_household_size)
21
+ assert_equal(0.181808339938523, response.city_percent_of_homes_with_kids)
22
+
23
+ # test neighborhood demographics
24
+ assert_equal(39, response.neighborhood_median_age)
25
+ assert_equal(41202.9453206937, response.neighborhood_median_household_income)
26
+ assert_equal(1.82278897942217, response.neighborhood_average_household_size)
27
+ assert_equal(0.149933859172205, response.neighborhood_percent_of_homes_with_kids)
28
+
29
+ # test nation demographics
30
+ assert_equal(36, response.nation_median_age)
31
+ assert_equal(44512.0130806292, response.nation_median_household_income)
32
+ assert_equal(2.58883240001203, response.nation_average_household_size)
33
+ assert_equal(0.313623902816284, response.nation_percent_of_homes_with_kids)
34
+
35
+ assert_equal(0.35028618, response.percent_owners)
36
+ assert_equal(0.64971382, response.percent_renters)
37
+ end
38
+
39
+ end