zillow_api 0.1 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/zillow_api.rb +53 -35
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c31e09dc3c05dcfaee56121455c41e247ed634eb
4
- data.tar.gz: 52759e4da08b42f73609be5cc47c06b6af4eaf96
3
+ metadata.gz: 983064ad60143a3331d18d29b430e514bbb4ed63
4
+ data.tar.gz: e99b2335b22f55c229dc8d9cc401c3f3319a223f
5
5
  SHA512:
6
- metadata.gz: b201b6ee09e71b800833e90085da582c4678782593c997f5c20422986b037867d785bcc76b0e4d85373faccd30c47ba95b0d978c8fb12c1f27ff994ab7324835
7
- data.tar.gz: 6010146b29d63414ce7cb208020776c6a7bf0021c766c379d26ad7aadc369913d1e2d65518167f31412b99a293d1ed1a966aac345bb1a5dcd3a8c0d49262ef44
6
+ metadata.gz: 0eb5b499a26d3719a5e52c78d7ba1f04a6ff61f704c809541b0c84a33d6037c85541d58701a4bf6c6c697e854a32eebffbc2028c172b81b7a977a394b16d6406
7
+ data.tar.gz: c33aa0d8beb0a3fdb9298cd2670411649f09a977329347aa8ba22613d152180ccba796dfd75af95bf0ee460c59014fb81a9bbdba7d23c94c74666633cf648f24
data/lib/zillow_api.rb CHANGED
@@ -30,8 +30,10 @@ class ZillowAPI
30
30
  end
31
31
  end
32
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
33
+ def get_property_by_address(address_num:nil, address_street:, address_street_type:nil,address_city:nil,address_state:nil,address_zip:nil)
34
+ if address_num.nil? && (address_street && address_zip)
35
+ property = Nokogiri::HTML(open("#{ZILLOW_API_URL}&zws-id=#{@api_key}&address=#{CGI::escape(address_street)}&citystatezip=#{CGI::escape(address_zip)}"))
36
+ elsif address_zip && address_street_type
35
37
  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
38
  elsif address_zip && address_street_type.nil?
37
39
  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)}"))
@@ -46,17 +48,17 @@ class ZillowAPI
46
48
  if property.css("zpid")[0].text.to_i.to_s == property.css("zpid")[0].text
47
49
  property_data = {}
48
50
  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"]
51
+ street: property.css("address")[1].children[0].text,
52
+ zip_code: property.css("address")[1].children[1].text,
53
+ city: property.css("address")[1].children[2].text.downcase,
54
+ state: property.css("address")[1].children[3].text.downcase,
55
+ latitude: property.css("address")[1].children[4].text,
56
+ longitude: property.css("address")[1].children[5].text,
57
+ zestimate: property.css("zestimate")[0].children[0].text,
58
+ rent_zestimate: property.css("rentzestimate")[0].children[0].text,
59
+ neighborhood_id: property.css("localrealestate")[0].children.css("region").first["id"],
60
+ neighborhood_name: property.css("localrealestate")[0].children.css("region").first["name"],
61
+ neighborhood_type: property.css("localrealestate")[0].children.css("region").first["type"]
60
62
  }
61
63
  return property_data
62
64
  else
@@ -70,14 +72,14 @@ class ZillowAPI
70
72
  if property.css("zpid")[0].text.to_i.to_s == property.css("zpid")[0].text
71
73
  property_data = {}
72
74
  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
75
+ street: property.css("address").children[0].text,
76
+ zip_code: property.css("address").children[1].text,
77
+ city: property.css("address").children[2].text.downcase,
78
+ state: property.css("address").children[3].text.downcase,
79
+ latitude: property.css("address").children[4].text,
80
+ longitude: property.css("address").children[5].text,
81
+ zestimate: property.css("amount").children[0].text,
82
+ rent_zestimate: property.css("rentzestimate")[0].children[0].text
81
83
  }
82
84
  return property_data
83
85
  else
@@ -85,24 +87,40 @@ class ZillowAPI
85
87
  end
86
88
  end
87
89
 
88
- # THIS METHOD IS UNDER CONSTRUCTION
89
- def get_demographics_by_id(regionid:)
90
+ def get_demographics_by_id(regionid)
90
91
  demo_stats = Nokogiri::HTML(open("#{ZILLOW_DEMO_URL}&zws-id=#{@api_key}&regionid=#{CGI::escape(regionid)}"))
91
92
  if demo_stats.css("regionid").text.to_i.to_s == demo_stats.css("regionid").text
92
93
  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"]
94
+ neighborhood_data = {}
95
+ nation_data = {}
96
+ city_data = {}
97
+
98
+ #get city data
99
+ demo_stats.css("attribute").each do |att|
100
+ city_data[att.css("name").text.downcase] = att.css("city").text.downcase
101
+ end
102
+
103
+ #get neighborhood data
104
+ demo_stats.css("attribute").each do |att|
105
+ neighborhood_data[att.css("name").text.downcase] = att.css("neighborhood").text.downcase
106
+ end
107
+
108
+ #get nation data
109
+ demo_stats.css("attribute").each do |att|
110
+ nation_data[att.css("name").text.downcase] = att.css("nation").text.downcase
111
+ end
112
+
113
+ demo_data = { id: demo_stats.css("region").children[0].text,
114
+ state: demo_stats.css("region").children[1].text.downcase,
115
+ city: demo_stats.css("region").children[2].text.downcase,
116
+ neighborhood: demo_stats.css("region").children[3].text.downcase,
117
+ latitude: demo_stats.css("region").children[4].text,
118
+ longitude: demo_stats.css("region").children[5].text,
119
+ neighborhood_data: neighborhood_data,
120
+ city_data: city_data,
121
+ nation_data: nation_data
104
122
  }
105
- return demo_stats
123
+ return demo_data
106
124
  else
107
125
  return {zillow_error_code: demo_stats.css('message').children[1].text, zillow_error_code_text: demo_stats.css('message').children[0].text}
108
126
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zillow_api
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Freeman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-04 00:00:00.000000000 Z
11
+ date: 2015-08-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Gem for interfacing with Zillow API
14
14
  email: benfreeman@gmail.com