zillow_demographics 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -3,17 +3,16 @@ require 'faraday'
|
|
3
3
|
module ZillowApi
|
4
4
|
class Client
|
5
5
|
BASE_URL = 'http://www.zillow.com'
|
6
|
-
ZWSID = 'X1-ZWz1bn1je20hzf_1wtus'
|
7
6
|
|
8
7
|
def initialize
|
9
8
|
@connection = Faraday.new(url: BASE_URL)
|
10
9
|
end
|
11
10
|
|
12
|
-
def get_city_data(location)
|
11
|
+
def get_city_data(location, api_key)
|
13
12
|
response = @connection.get do |req|
|
14
13
|
req.url "/webservice/GetDemographics.htm"
|
15
14
|
req.headers['Accepts'] = 'application/xml'
|
16
|
-
req.params['zws-id'] =
|
15
|
+
req.params['zws-id'] = api_key
|
17
16
|
req.params['state'] = location[:state]
|
18
17
|
req.params['city'] = location[:city]
|
19
18
|
end
|
@@ -18,25 +18,25 @@ module ZillowApi
|
|
18
18
|
ZillowApi::Client.new
|
19
19
|
end
|
20
20
|
|
21
|
-
def demo_attributes(location)
|
22
|
-
keys = parsed_response(location).search("page")[-1].search("table")[0].search("attribute").map {|key| key.child.text.downcase }
|
23
|
-
values = parsed_response(location).search("page")[-1].search("table")[0].search("attribute").search("nation").map { |values| values.child.text }
|
21
|
+
def demo_attributes(location, api_key)
|
22
|
+
keys = parsed_response(location, api_key).search("page")[-1].search("table")[0].search("attribute").map {|key| key.child.text.downcase }
|
23
|
+
values = parsed_response(location, api_key).search("page")[-1].search("table")[0].search("attribute").search("nation").map { |values| values.child.text }
|
24
24
|
Hash[keys.zip(values)]
|
25
25
|
end
|
26
26
|
|
27
|
-
def home_value(location)
|
28
|
-
key = parsed_response(location).search("page").first.search("data").first.search("attribute").first.child.text.downcase
|
29
|
-
value = parsed_response(location).search("page").first.search("data").first.search("nation").first.text
|
27
|
+
def home_value(location, api_key)
|
28
|
+
key = parsed_response(location, api_key).search("page").first.search("data").first.search("attribute").first.child.text.downcase
|
29
|
+
value = parsed_response(location, api_key).search("page").first.search("data").first.search("nation").first.text
|
30
30
|
{ key => value }
|
31
31
|
end
|
32
32
|
|
33
|
-
def find_by_city(location)
|
34
|
-
attributes = demo_attributes(location).merge(home_value(location))
|
33
|
+
def find_by_city(location, api_key)
|
34
|
+
attributes = demo_attributes(location, api_key).merge(home_value(location, api_key))
|
35
35
|
ZillowApi::National.new(attributes)
|
36
36
|
end
|
37
37
|
|
38
|
-
def parsed_response(location)
|
39
|
-
parse_all(client.get_city_data(location))
|
38
|
+
def parsed_response(location, api_key)
|
39
|
+
parse_all(client.get_city_data(location, api_key))
|
40
40
|
end
|
41
41
|
|
42
42
|
def parse_all(xml_package)
|
@@ -21,18 +21,18 @@ module ZillowApi
|
|
21
21
|
ZillowApi::Client.new
|
22
22
|
end
|
23
23
|
|
24
|
-
def demo_attributes(location)
|
25
|
-
keys = parsed_response(location).search("page")[-1].search("table")[0].search("attribute").map {|key| key.child.text.downcase }
|
26
|
-
values = parsed_response(location).search("page")[-1].search("table")[0].search("attribute").search("city").map { |values| values.child.text }
|
24
|
+
def demo_attributes(location, api_key)
|
25
|
+
keys = parsed_response(location, api_key).search("page")[-1].search("table")[0].search("attribute").map {|key| key.child.text.downcase }
|
26
|
+
values = parsed_response(location, api_key).search("page")[-1].search("table")[0].search("attribute").search("city").map { |values| values.child.text }
|
27
27
|
if values == []
|
28
28
|
values = %w[N/A N/A N/A N/A N/A N/A N/A]
|
29
29
|
end
|
30
30
|
Hash[keys.zip(values)]
|
31
31
|
end
|
32
32
|
|
33
|
-
def lives_here_attributes(location)
|
34
|
-
keys = parsed_response(location).search("page")[-1].search("liveshere").search("title").map { |value| value.text.downcase }
|
35
|
-
values = parsed_response(location).search("page")[-1].search("liveshere").search("name").map { |key| key.text }
|
33
|
+
def lives_here_attributes(location, api_key)
|
34
|
+
keys = parsed_response(location, api_key).search("page")[-1].search("liveshere").search("title").map { |value| value.text.downcase }
|
35
|
+
values = parsed_response(location, api_key).search("page")[-1].search("liveshere").search("name").map { |key| key.text }
|
36
36
|
if keys == []
|
37
37
|
{ 'lives here' => 'N/A'}
|
38
38
|
else
|
@@ -40,32 +40,32 @@ module ZillowApi
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
def mode_of_transit(location)
|
44
|
-
key = parsed_response(location).search("uniqueness").search("category").last.attributes['type'].value.downcase
|
45
|
-
value = parsed_response(location).search("uniqueness").search("category").last.children.map {|s| s.text}
|
46
|
-
if
|
47
|
-
|
43
|
+
def mode_of_transit(location, api_key)
|
44
|
+
key = parsed_response(location, api_key).search("uniqueness").search("category").last.attributes['type'].value.downcase
|
45
|
+
value = parsed_response(location, api_key).search("uniqueness").search("category").last.children.map {|s| s.text}
|
46
|
+
if key != "transportation"
|
47
|
+
{ 'transportation' => ["N/A"] }
|
48
48
|
else
|
49
49
|
{ key => value }
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
def home_value(location)
|
54
|
-
key = parsed_response(location).search("page").first.search("data").first.search("attribute").first.child.text.downcase
|
55
|
-
value = parsed_response(location).search("page").first.search("data").first.search("city").first.text
|
56
|
-
if value == []
|
53
|
+
def home_value(location, api_key)
|
54
|
+
key = parsed_response(location, api_key).search("page").first.search("data").first.search("attribute").first.child.text.downcase
|
55
|
+
value = parsed_response(location, api_key).search("page").first.search("data").first.search("city").first.text
|
56
|
+
if value == [] || value.to_i < 25000
|
57
57
|
value = ['N/A']
|
58
58
|
end
|
59
59
|
{ key => value }
|
60
60
|
end
|
61
61
|
|
62
|
-
def find_by_city(location)
|
63
|
-
attributes = lives_here_attributes(location).merge(demo_attributes(location)).merge(home_value(location)).merge(mode_of_transit(location))
|
62
|
+
def find_by_city(location, api_key)
|
63
|
+
attributes = lives_here_attributes(location, api_key).merge(demo_attributes(location, api_key)).merge(home_value(location, api_key)).merge(mode_of_transit(location, api_key))
|
64
64
|
ZillowApi::People.new(attributes)
|
65
65
|
end
|
66
66
|
|
67
|
-
def parsed_response(location)
|
68
|
-
parse_all(client.get_city_data(location))
|
67
|
+
def parsed_response(location, api_key)
|
68
|
+
parse_all(client.get_city_data(location, api_key))
|
69
69
|
end
|
70
70
|
|
71
71
|
def parse_all(xml_package)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zillow_demographics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
16
|
-
requirement: &
|
16
|
+
requirement: &70321333734240 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70321333734240
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: nokogiri
|
27
|
-
requirement: &
|
27
|
+
requirement: &70321333733720 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70321333733720
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70321333733180 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70321333733180
|
47
47
|
description: wrapper for the zillow_demographics api
|
48
48
|
email:
|
49
49
|
- michael.v.verdi@gmail.com
|