trulia_api 1.3 → 1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trulia_api.rb +90 -25
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 322eff8e37d4baa87635afbf379f7ef5bdcf73a1
|
4
|
+
data.tar.gz: ab8597613972830b7d48f94ebc8607869395d0ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1876070612d57e27107812e5bdd63194e54e63f6e6718a17da76e181cb3ec1d9ddbd8635873d1ad6de0037d73cb4a3a3380a5b4710cd8636d9748b30f6daa0bd
|
7
|
+
data.tar.gz: ab7aa8162a8199764323d5959ae51eb50139e8153826bcf6391bb4b4c936038e7b543c49faafa262312a9d7b36b0cb4f5510c98532286e7c731fd554107f6482
|
data/lib/trulia_api.rb
CHANGED
@@ -24,7 +24,6 @@ class TruliaAPI
|
|
24
24
|
cities_in_state_xml = Nokogiri::HTML(open("http://api.trulia.com/webservices.php?library=LocationInfo&function=getCitiesInState&state=#{state}&apikey=#{@api_key}"))
|
25
25
|
cities_in_state_xml.css("city").each do |city|
|
26
26
|
cities[city.css("name").text.downcase] = {
|
27
|
-
state: state,
|
28
27
|
zillow_id: city.css("cityid").text.to_i,
|
29
28
|
longitude: city.css("longitude").text.to_d,
|
30
29
|
latitude: city.css("latitude").text.to_d
|
@@ -38,7 +37,6 @@ class TruliaAPI
|
|
38
37
|
zip_codes_in_state_xml = Nokogiri::HTML(open("http://api.trulia.com/webservices.php?library=LocationInfo&function=getZipCodesInState&state=#{state}&apikey=#{@api_key}"))
|
39
38
|
zip_codes_in_state_xml.css("zipcode").each do |zip|
|
40
39
|
zips[zip.css("name").text.downcase] = {
|
41
|
-
state: state,
|
42
40
|
longitude: zip.css("longitude").text.to_d,
|
43
41
|
latitude: zip.css("latitude").text.to_d
|
44
42
|
}
|
@@ -63,7 +61,7 @@ class TruliaAPI
|
|
63
61
|
neighborhoods = {}
|
64
62
|
neighborhoods_in_city_xml = Nokogiri::HTML(open("http://api.trulia.com/webservices.php?library=LocationInfo&function=getNeighborhoodsInCity&city=#{CGI::escape(city)}&state=#{state}&apikey=#{@api_key}"))
|
65
63
|
neighborhoods_in_city_xml.css("neighborhood").each do |neighborhood|
|
66
|
-
|
64
|
+
neeghborhoods[neighborhood.css("name").text.downcase] = {
|
67
65
|
zillow_id: neighborhood.css("id").text.to_i,
|
68
66
|
}
|
69
67
|
end
|
@@ -72,40 +70,107 @@ class TruliaAPI
|
|
72
70
|
|
73
71
|
def get_city_stats(city, state, startdate, enddate)
|
74
72
|
city_stats = {}
|
73
|
+
bedrooms = {}
|
75
74
|
city_stats_xml = Nokogiri::HTML(open("http://api.trulia.com/webservices.php?library=TruliaStats&function=getCityStats&city=#{CGI::escape(city)}&state=#{state}&startDate=#{startdate}&endDate=#{enddate}&apikey=#{@api_key}"))
|
76
75
|
|
77
76
|
city_stats_xml.css("listingstat").each do |listingstat|
|
78
|
-
weekend_date
|
77
|
+
weekend_date = listingstat.css("weekendingdate").text.downcase
|
79
78
|
listingstat.css("subcategory").each do |subcategory|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
79
|
+
type = subcategory.css("type").text.downcase
|
80
|
+
|
81
|
+
bedrooms[type] = {
|
82
|
+
properties: subcategory.css("numberofproperties").text,
|
83
|
+
medianlistingprice: subcategory.css("medianlistingprice").text,
|
84
|
+
averagelistingprice: subcategory.css("averagelistingprice").text
|
85
|
+
}
|
86
|
+
city_stats[weekend_date] = bedrooms
|
86
87
|
end
|
87
88
|
end
|
88
|
-
return
|
89
|
-
#return city_stats
|
89
|
+
return city_stats
|
90
90
|
end
|
91
91
|
|
92
|
-
def get_state_stats(
|
93
|
-
|
94
|
-
|
92
|
+
def get_state_stats(state, startdate, enddate)
|
93
|
+
state_stats = {}
|
94
|
+
bedrooms = {}
|
95
|
+
state_stats_xml = Nokogiri::HTML(open("http://api.trulia.com/webservices.php?library=TruliaStats&function=getStateStats&state=#{state}&startDate=#{startdate}&endDate=#{enddate}&apikey=#{@api_key}"))
|
95
96
|
|
96
|
-
|
97
|
-
weekend_date
|
97
|
+
state_stats_xml.css("listingstat").each do |listingstat|
|
98
|
+
weekend_date = listingstat.css("weekendingdate").text.downcase
|
99
|
+
listingstat.css("subcategory").each do |subcategory|
|
100
|
+
type = subcategory.css("type").text.downcase
|
101
|
+
|
102
|
+
bedrooms[type] = {
|
103
|
+
properties: subcategory.css("numberofproperties").text,
|
104
|
+
medianlistingprice: subcategory.css("medianlistingprice").text,
|
105
|
+
averagelistingprice: subcategory.css("averagelistingprice").text
|
106
|
+
}
|
107
|
+
state_stats[weekend_date] = bedrooms
|
108
|
+
end
|
109
|
+
end
|
110
|
+
return state_stats
|
111
|
+
end
|
112
|
+
|
113
|
+
def get_zip_stats(zip, startdate, enddate)
|
114
|
+
zip_stats = {}
|
115
|
+
bedrooms = {}
|
116
|
+
zip_stats_xml = Nokogiri::HTML(open("http://api.trulia.com/webservices.php?library=TruliaStats&function=getZipCodeStats&zipCode=#{zip}&startDate=#{startdate}&endDate=#{enddate}&apikey=#{@api_key}"))
|
117
|
+
|
118
|
+
zip_stats_xml.css("listingstat").each do |listingstat|
|
119
|
+
weekend_date = listingstat.css("weekendingdate").text.downcase
|
120
|
+
listingstat.css("subcategory").each do |subcategory|
|
121
|
+
type = subcategory.css("type").text.downcase
|
122
|
+
|
123
|
+
bedrooms[type] = {
|
124
|
+
properties: subcategory.css("numberofproperties").text,
|
125
|
+
medianlistingprice: subcategory.css("medianlistingprice").text,
|
126
|
+
averagelistingprice: subcategory.css("averagelistingprice").text
|
127
|
+
}
|
128
|
+
zip_stats[weekend_date] = bedrooms
|
129
|
+
end
|
130
|
+
end
|
131
|
+
return zip_stats
|
132
|
+
end
|
133
|
+
|
134
|
+
def get_neighborhood_stats(nid, startdate, enddate)
|
135
|
+
neighborhood_stats = {}
|
136
|
+
bedrooms = {}
|
137
|
+
neighborhood_stats_xml = Nokogiri::HTML(open("http://api.trulia.com/webservices.php?library=TruliaStats&function=getNeighborhoodStats&neighborhoodId=#{nid}&startDate=#{startdate}&endDate=#{enddate}&apikey=#{@api_key}"))
|
138
|
+
|
139
|
+
neighborhood_stats_xml.css("listingstat").each do |listingstat|
|
140
|
+
weekend_date = listingstat.css("weekendingdate").text.downcase
|
98
141
|
listingstat.css("subcategory").each do |subcategory|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
142
|
+
type = subcategory.css("type").text.downcase
|
143
|
+
|
144
|
+
bedrooms[type] = {
|
145
|
+
properties: subcategory.css("numberofproperties").text,
|
146
|
+
medianlistingprice: subcategory.css("medianlistingprice").text,
|
147
|
+
averagelistingprice: subcategory.css("averagelistingprice").text
|
148
|
+
}
|
149
|
+
neighborhood_stats[weekend_date] = bedrooms
|
150
|
+
end
|
151
|
+
end
|
152
|
+
return neighborhood_stats
|
153
|
+
end
|
154
|
+
|
155
|
+
def get_county_stats(county, state, startdate, enddate)
|
156
|
+
county_stats = {}
|
157
|
+
bedrooms = {}
|
158
|
+
county_stats_xml = Nokogiri::HTML(open("http://api.trulia.com/webservices.php?library=TruliaStats&function=getCountyStats&county=#{CGI::escape(county)}&state=#{state}&startDate=#{startdate}&endDate=#{enddate}&apikey=#{@api_key}"))
|
159
|
+
|
160
|
+
county_stats_xml.css("listingstat").each do |listingstat|
|
161
|
+
weekend_date = listingstat.css("weekendingdate").text.downcase
|
162
|
+
listingstat.css("subcategory").each do |subcategory|
|
163
|
+
type = subcategory.css("type").text.downcase
|
164
|
+
|
165
|
+
bedrooms[type] = {
|
166
|
+
properties: subcategory.css("numberofproperties").text,
|
167
|
+
medianlistingprice: subcategory.css("medianlistingprice").text,
|
168
|
+
averagelistingprice: subcategory.css("averagelistingprice").text
|
169
|
+
}
|
170
|
+
county_stats[weekend_date] = bedrooms
|
105
171
|
end
|
106
172
|
end
|
107
|
-
return
|
108
|
-
#return city_stats
|
173
|
+
return county_stats
|
109
174
|
end
|
110
175
|
|
111
176
|
end
|