zillow_api 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/zillow_api.rb +110 -0
  3. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c31e09dc3c05dcfaee56121455c41e247ed634eb
4
+ data.tar.gz: 52759e4da08b42f73609be5cc47c06b6af4eaf96
5
+ SHA512:
6
+ metadata.gz: b201b6ee09e71b800833e90085da582c4678782593c997f5c20422986b037867d785bcc76b0e4d85373faccd30c47ba95b0d978c8fb12c1f27ff994ab7324835
7
+ data.tar.gz: 6010146b29d63414ce7cb208020776c6a7bf0021c766c379d26ad7aadc369913d1e2d65518167f31412b99a293d1ed1a966aac345bb1a5dcd3a8c0d49262ef44
data/lib/zillow_api.rb ADDED
@@ -0,0 +1,110 @@
1
+ class ZillowAPI
2
+ require 'open-uri'
3
+ require 'nokogiri'
4
+
5
+ ZILLOW_API_URL = "http://www.zillow.com/webservice/GetSearchResults.htm?rentzestimate=true"
6
+ ZILLOW_DEMO_URL = "http://www.zillow.com/webservice/GetDemographics.htm?"
7
+ ZILLOW_API_ZPID_URL = "http://www.zillow.com/webservice/GetZestimate.htm?rentzestimate=true"
8
+
9
+ def initialize(api_key)
10
+ @api_key = api_key
11
+ end
12
+
13
+ def get_zpid(address_num:, address_street:, address_street_type:nil, address_city:nil, address_state:nil, address_zip:nil)
14
+ if address_zip && address_street_type
15
+ property = Nokogiri::HTML(open("#{ZILLOW_API_URL}&zws-id=#{@api_key}&address=#{CGI::escape(address_num)}%20#{CGI::escape(address_street)}%20#{CGI::escape(address_street_type)}&citystatezip=#{CGI::escape(address_zip)}"))
16
+ elsif address_zip && address_street_type.nil?
17
+ property = Nokogiri::HTML(open("#{ZILLOW_API_URL}&zws-id=#{@api_key}&address=#{CGI::escape(address_num)}%20#{CGI::escape(address_street)}&citystatezip=#{CGI::escape(address_zip)}"))
18
+ elsif address_zip.nil? && (address_city && address_state && address_street_type)
19
+ property = Nokogiri::HTML(open("#{ZILLOW_API_URL}&zws-id=#{@api_key}&address=#{CGI::escape(address_num)}%20#{CGI::escape(address_street)}%20#{CGI::escape(address_street_type)}&citystatezip=#{CGI::escape(address_city)}%20#{CGI::escape(address_state)}"))
20
+ elsif address_zip.nil? && (address_city && address_state && address_street_type.nil?)
21
+ property = Nokogiri::HTML(open("#{ZILLOW_API_URL}&zws-id=#{@api_key}&address=#{CGI::escape(address_num)}%20#{CGI::escape(address_street)}&citystatezip=#{CGI::escape(address_city)}%20#{CGI::escape(address_state)}"))
22
+ else
23
+ return "SOMETHING WITH THE ADDRESS ISNT RIGHT"
24
+ end
25
+
26
+ if property.css("zpid")[0] && (property.css("zpid")[0].text.to_i.to_s == property.css("zpid")[0].text)
27
+ return { zpid: property.css("zpid")[0].text }
28
+ else
29
+ return {zillow_error_code: property.css('message').children[1].text, zillow_error_code_text: property.css('message').children[0].text}
30
+ end
31
+ end
32
+
33
+ def get_property_by_address(address_num:, address_street:, address_street_type:nil,address_city:nil,address_state:nil,address_zip:nil)
34
+ if address_zip && address_street_type
35
+ property = Nokogiri::HTML(open("#{ZILLOW_API_URL}&zws-id=#{@api_key}&address=#{CGI::escape(address_num)}%20#{CGI::escape(address_street)}%20#{CGI::escape(address_street_type)}&citystatezip=#{CGI::escape(address_zip)}"))
36
+ elsif address_zip && address_street_type.nil?
37
+ property = Nokogiri::HTML(open("#{ZILLOW_API_URL}&zws-id=#{@api_key}&address=#{CGI::escape(address_num)}%20#{CGI::escape(address_street)}&citystatezip=#{CGI::escape(address_zip)}"))
38
+ elsif address_zip.nil? && (address_city && address_state && address_street_type)
39
+ property = Nokogiri::HTML(open("#{ZILLOW_API_URL}&zws-id=#{@api_key}&address=#{CGI::escape(address_num)}%20#{CGI::escape(address_street)}%20#{CGI::escape(address_street_type)}&citystatezip=#{CGI::escape(address_city)}%20#{CGI::escape(address_state)}"))
40
+ elsif address_zip.nil? && (address_city && address_state && address_street_type.nil?)
41
+ property = Nokogiri::HTML(open("#{ZILLOW_API_URL}&zws-id=#{@api_key}&address=#{CGI::escape(address_num)}%20#{CGI::escape(address_street)}&citystatezip=#{CGI::escape(address_city)}%20#{CGI::escape(address_state)}"))
42
+ else
43
+ return "SOMETHING WITH THE ADDRESS ISNT RIGHT"
44
+ end
45
+
46
+ if property.css("zpid")[0].text.to_i.to_s == property.css("zpid")[0].text
47
+ property_data = {}
48
+ property_data = { zpid: property.css("zpid")[0].text,
49
+ street: property.css("address")[1].children[0].text,
50
+ zip_code: property.css("address")[1].children[1].text,
51
+ city: property.css("address")[1].children[2].text.downcase,
52
+ state: property.css("address")[1].children[3].text.downcase,
53
+ latitude: property.css("address")[1].children[4].text,
54
+ longitude: property.css("address")[1].children[5].text,
55
+ zestimate: property.css("zestimate")[0].children[0].text,
56
+ rent_zestimate: property.css("rentzestimate")[0].children[0].text,
57
+ neighborhood_id: property.css("localrealestate")[0].children.css("region").first["id"],
58
+ neighborhood_name: property.css("localrealestate")[0].children.css("region").first["name"],
59
+ neighborhood_type: property.css("localrealestate")[0].children.css("region").first["type"]
60
+ }
61
+ return property_data
62
+ else
63
+ return {zillow_error_code: property.css('message').children[1].text, zillow_error_code_text: property.css('message').children[0].text}
64
+ end
65
+ end
66
+
67
+ def get_property_by_zpid(zpid:)
68
+ property = Nokogiri::HTML(open("#{ZILLOW_API_ZPID_URL}&zws-id=#{@api_key}&zpid=#{zpid}"))
69
+
70
+ if property.css("zpid")[0].text.to_i.to_s == property.css("zpid")[0].text
71
+ property_data = {}
72
+ property_data = { zpid: property.css("zpid")[0].text,
73
+ street: property.css("address").children[0].text,
74
+ zip_code: property.css("address").children[1].text,
75
+ city: property.css("address").children[2].text.downcase,
76
+ state: property.css("address").children[3].text.downcase,
77
+ latitude: property.css("address").children[4].text,
78
+ longitude: property.css("address").children[5].text,
79
+ zestimate: property.css("amount").children[0].text,
80
+ rent_zestimate: property.css("rentzestimate")[0].children[0].text
81
+ }
82
+ return property_data
83
+ else
84
+ return { zillow_error_code: property.css('message').children[1].text, zillow_error_code_text: property.css('message').children[0].text }
85
+ end
86
+ end
87
+
88
+ # THIS METHOD IS UNDER CONSTRUCTION
89
+ def get_demographics_by_id(regionid:)
90
+ demo_stats = Nokogiri::HTML(open("#{ZILLOW_DEMO_URL}&zws-id=#{@api_key}&regionid=#{CGI::escape(regionid)}"))
91
+ if demo_stats.css("regionid").text.to_i.to_s == demo_stats.css("regionid").text
92
+ demo_data = {}
93
+ demo_data = { id: demo_stats.css("region").children[0].text,
94
+ state: demo_stats.css("region").children[1].text.downcase,
95
+ city: demo_stats.css("region").children[2].text.downcase,
96
+ neighborhood: demo_stats.css("region").children[3].text.downcase,
97
+ latitude: demo_stats.css("region").children[4].text,
98
+ longitude: demo_stats.css("region").children[0].text,
99
+ median_zestimate: demo_stats.css("zestimate")[0].children[0].text,
100
+ rent_zestimate: property.css("rentzestimate")[0].children[0].text,
101
+ neighborhood_id: property.css("localrealestate")[0].children.css("region").first["id"],
102
+ neighborhood_name: property.css("localrealestate")[0].children.css("region").first["name"],
103
+ neighborhood_type: property.css("localrealestate")[0].children.css("region").first["type"]
104
+ }
105
+ return demo_stats
106
+ else
107
+ return {zillow_error_code: demo_stats.css('message').children[1].text, zillow_error_code_text: demo_stats.css('message').children[0].text}
108
+ end
109
+ end
110
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zillow_api
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Ben Freeman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Gem for interfacing with Zillow API
14
+ email: benfreeman@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/zillow_api.rb
20
+ homepage: http://rubygems.org/gems/zillow_api
21
+ licenses:
22
+ - MIT
23
+ metadata:
24
+ github: https://github.com/benfreeman/zillow_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: ZillowAPI
45
+ test_files: []