trulia_api 1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/trulia_api.rb +111 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1fe899c03f5ede8c974386bcf6a7715e2e4196c1
|
4
|
+
data.tar.gz: b9a52a21f2a85b43fa4ff8a1a2d60edf214782e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed8cc29fa05a8af85848a80a819ecae70ab28c3daa631dfc659a5e9deefaef0e1613cbf2a9c1a0a022a8f5f0118f88df9895e0158559ae22db5323efc1240fcd
|
7
|
+
data.tar.gz: 2fa66de5a790a8e6671614155de9fef98297f36cb3e3c996c4c6faecc14098204ac572e55ec04f6b3b399aa01c88252e165471ef773d0a6f470b16cf2b4d24fa
|
data/lib/trulia_api.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
class TruliaAPI
|
2
|
+
require 'open-uri'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
def initialize(api_key)
|
6
|
+
@api_key = api_key
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_states
|
10
|
+
states = {}
|
11
|
+
states_xml = Nokogiri::HTML(open("http://api.trulia.com/webservices.php?library=LocationInfo&function=getStates&apikey=#{@api_key}"))
|
12
|
+
states_xml.css("state").each do |state|
|
13
|
+
states[state.css("name").text.downcase] = {
|
14
|
+
abbreviation: state.css("statecode").text.downcase,
|
15
|
+
longitude: state.css("longitude").text.to_d,
|
16
|
+
latitude: state.css("latitude").text.to_d
|
17
|
+
}
|
18
|
+
end
|
19
|
+
states
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_cities(state)
|
23
|
+
cities = {}
|
24
|
+
cities_in_state_xml = Nokogiri::HTML(open("http://api.trulia.com/webservices.php?library=LocationInfo&function=getCitiesInState&state=#{state}&apikey=#{@api_key}"))
|
25
|
+
cities_in_state_xml.css("city").each do |city|
|
26
|
+
cities[city.css("name").text.downcase] = {
|
27
|
+
state: state,
|
28
|
+
zillow_id: city.css("cityid").text.to_i,
|
29
|
+
longitude: city.css("longitude").text.to_d,
|
30
|
+
latitude: city.css("latitude").text.to_d
|
31
|
+
}
|
32
|
+
end
|
33
|
+
return cities
|
34
|
+
end
|
35
|
+
|
36
|
+
def get_zip_codes(state)
|
37
|
+
zips = {}
|
38
|
+
zip_codes_in_state_xml = Nokogiri::HTML(open("http://api.trulia.com/webservices.php?library=LocationInfo&function=getZipCodesInState&state=#{state}&apikey=#{@api_key}"))
|
39
|
+
zip_codes_in_state_xml.css("zipcode").each do |zip|
|
40
|
+
zips[zip.css("name").text.downcase] = {
|
41
|
+
state: state,
|
42
|
+
longitude: zip.css("longitude").text.to_d,
|
43
|
+
latitude: zip.css("latitude").text.to_d
|
44
|
+
}
|
45
|
+
end
|
46
|
+
return zips
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_counties(state)
|
50
|
+
counties = {}
|
51
|
+
counties_in_state_xml = Nokogiri::HTML(open("http://api.trulia.com/webservices.php?library=LocationInfo&function=getCountiesInState&state=#{state}&apikey=#{@api_key}"))
|
52
|
+
counties_in_state_xml.css("county").each do |county|
|
53
|
+
counties[county.css("name").text.downcase] = {
|
54
|
+
zillow_id: county.css("countyid").text.to_i,
|
55
|
+
longitude: county.css("longitude").text.to_d,
|
56
|
+
latitude: county.css("latitude").text.to_d
|
57
|
+
}
|
58
|
+
end
|
59
|
+
return counties
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_neighborhoods(city, state)
|
63
|
+
neighborhoods = {}
|
64
|
+
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
|
+
neighborhoods_in_city_xml.css("neighborhood").each do |neighborhood|
|
66
|
+
neighborhoods[neighborhood.css("name").text.downcase] = {
|
67
|
+
zillow_id: neighborhood.css("id").text.to_i,
|
68
|
+
}
|
69
|
+
end
|
70
|
+
return neighborhoods
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_city_stats(city, state, startdate, enddate)
|
74
|
+
city_stats = {}
|
75
|
+
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
|
+
|
77
|
+
city_stats_xml.css("listingstat").each do |listingstat|
|
78
|
+
weekend_date = listingstat.css("weekendingdate").text.downcase
|
79
|
+
listingstat.css("subcategory").each do |subcategory|
|
80
|
+
city_stats = {weekend_date => {
|
81
|
+
subcategory.css("type").text.downcase => {
|
82
|
+
properties: subcategory.css("numberofproperties").text,
|
83
|
+
medianlistingprice: subcategory.css("medianlistingprice").text,
|
84
|
+
averagelistingprice: subcategory.css("averagelistingprice").text
|
85
|
+
}}}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
return "THIS IS NOT READY YET"
|
89
|
+
#return city_stats
|
90
|
+
end
|
91
|
+
|
92
|
+
def get_state_stats(city, state, startdate, enddate)
|
93
|
+
city_stats = {}
|
94
|
+
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}"))
|
95
|
+
|
96
|
+
city_stats_xml.css("listingstat").each do |listingstat|
|
97
|
+
weekend_date = listingstat.css("weekendingdate").text.downcase
|
98
|
+
listingstat.css("subcategory").each do |subcategory|
|
99
|
+
city_stats = {weekend_date => {
|
100
|
+
subcategory.css("type").text.downcase => {
|
101
|
+
properties: subcategory.css("numberofproperties").text,
|
102
|
+
medianlistingprice: subcategory.css("medianlistingprice").text,
|
103
|
+
averagelistingprice: subcategory.css("averagelistingprice").text
|
104
|
+
}}}
|
105
|
+
end
|
106
|
+
end
|
107
|
+
return puts "THIS IS NOT READY YET"
|
108
|
+
#return city_stats
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trulia_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.3'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Freeman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Gem for interfacing with Trulias API
|
14
|
+
email: benfreeman@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/trulia_api.rb
|
20
|
+
homepage: http://rubygems.org/gems/trulia_api
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata:
|
24
|
+
github: https://github.com/benfreeman/trulia_api
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.4.5
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: TruliaAPI
|
45
|
+
test_files: []
|