zillow_demographics 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in zillow_demographics.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 michael verdi
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # ZillowDemographics
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'zillow_demographics'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install zillow_demographics
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/client.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'faraday'
2
+ require 'nokogiri'
3
+
4
+ module ZillowApi
5
+ class Client
6
+ BASE_URL = 'http://www.zillow.com'
7
+
8
+ def initialize
9
+ @connection = Faraday.new(url: BASE_URL)
10
+ end
11
+
12
+ def get_city_data(location)
13
+ response = @connection.get do |req|
14
+ req.url "/webservice/GetDemographics.htm"
15
+ req.headers['Accepts'] = 'application/xml'
16
+ req.params['zws-id'] = 'X1-ZWz1bn1je20hzf_1wtus'
17
+ req.params['state'] = location[:state]
18
+ req.params['city'] = location[:city]
19
+ end
20
+ response.body
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ require 'faraday'
2
+
3
+ module ZillowApi
4
+ class Client
5
+ BASE_URL = 'http://www.zillow.com'
6
+ ZWSID = 'X1-ZWz1bn1je20hzf_1wtus'
7
+
8
+ def initialize
9
+ @connection = Faraday.new(url: BASE_URL)
10
+ end
11
+
12
+ def get_city_data(location)
13
+ response = @connection.get do |req|
14
+ req.url "/webservice/GetDemographics.htm"
15
+ req.headers['Accepts'] = 'application/xml'
16
+ req.params['zws-id'] = ZWSID
17
+ req.params['state'] = location[:state]
18
+ req.params['city'] = location[:city]
19
+ end
20
+ response.body
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,48 @@
1
+ require 'nokogiri'
2
+
3
+ module ZillowApi
4
+ class National
5
+ attr_accessor :single_males, :single_females, :median_age, :average_commute_time, :home_value
6
+
7
+ def initialize(attributes)
8
+ self.average_commute_time = attributes['average commute time (minutes)']
9
+ self.single_females = attributes['single females']
10
+ self.single_males = attributes['single males']
11
+ self.median_age = attributes['median age']
12
+ self.home_value = attributes['zillow home value index']
13
+ end
14
+
15
+ class << self
16
+
17
+ def client
18
+ ZillowApi::Client.new
19
+ end
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 }
24
+ Hash[keys.zip(values)]
25
+ end
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
30
+ { key => value }
31
+ end
32
+
33
+ def find_by_city(location)
34
+ attributes = demo_attributes(location).merge(home_value(location))
35
+ ZillowApi::National.new(attributes)
36
+ end
37
+
38
+ def parsed_response(location)
39
+ parse_all(client.get_city_data(location))
40
+ end
41
+
42
+ def parse_all(xml_package)
43
+ Nokogiri::HTML(xml_package)
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,62 @@
1
+ require 'nokogiri'
2
+
3
+ module ZillowApi
4
+ class People
5
+ attr_accessor :single_males, :single_females, :median_age, :average_commute_time
6
+ attr_accessor :transportation, :home_value, :who_live_here
7
+
8
+ def initialize(attributes)
9
+ self.average_commute_time = attributes['average commute time (minutes)']
10
+ self.single_females = attributes['single females']
11
+ self.single_males = attributes['single males']
12
+ self.median_age = attributes['median age']
13
+ self.who_live_here = attributes['lives here']
14
+ self.transportation = attributes['transportation']
15
+ self.home_value = attributes['zillow home value index']
16
+ end
17
+
18
+ class << self
19
+
20
+ def client
21
+ ZillowApi::Client.new
22
+ end
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 }
27
+ Hash[keys.zip(values)]
28
+ end
29
+
30
+ def lives_here_attributes(location)
31
+ keys = parsed_response(location).search("page")[-1].search("liveshere").search("title").map { |value| value.text.downcase }
32
+ values = parsed_response(location).search("page")[-1].search("liveshere").search("name").map { |key| key.text }
33
+ { 'lives here' => Hash[keys.zip(values)] }
34
+ end
35
+
36
+ def mode_of_transit(location)
37
+ key = parsed_response(location).search("uniqueness").search("category").last.attributes['type'].value.downcase
38
+ value = parsed_response(location).search("uniqueness").search("category").last.text
39
+ { key => value }
40
+ end
41
+
42
+ def home_value(location)
43
+ key = parsed_response(location).search("page").first.search("data").first.search("attribute").first.child.text.downcase
44
+ value = parsed_response(location).search("page").first.search("data").first.search("city").first.text
45
+ { key => value }
46
+ end
47
+
48
+ def find_by_city(location)
49
+ attributes = lives_here_attributes(location).merge(demo_attributes(location)).merge(home_value(location)).merge(mode_of_transit(location))
50
+ ZillowApi::People.new(attributes)
51
+ end
52
+
53
+ def parsed_response(location)
54
+ parse_all(client.get_city_data(location))
55
+ end
56
+
57
+ def parse_all(xml_package)
58
+ Nokogiri::HTML(xml_package)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ module ZillowDemographics
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "zillow_demographics/version"
2
+ require "zillow_demographics/client"
3
+ require "zillow_demographics/people"
4
+ require "zillow_demographics/national"
5
+
6
+ module ZillowDemographics
7
+ # Your code goes here...
8
+ end
data/national.rb ADDED
@@ -0,0 +1,48 @@
1
+ require 'nokogiri'
2
+
3
+ module ZillowApi
4
+ class National
5
+ attr_accessor :single_males, :single_females, :median_age, :average_commute_time, :home_value
6
+
7
+ def initialize(attributes)
8
+ self.average_commute_time = attributes['average commute time (minutes)']
9
+ self.single_females = attributes['single females']
10
+ self.single_males = attributes['single males']
11
+ self.median_age = attributes['median age']
12
+ self.home_value = attributes['zillow home value index']
13
+ end
14
+
15
+ class << self
16
+
17
+ def client
18
+ ZillowApi::Client.new
19
+ end
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 }
24
+ Hash[keys.zip(values)]
25
+ end
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
30
+ { key => value }
31
+ end
32
+
33
+ def find_by_city(location)
34
+ attributes = demo_attributes(location).merge(home_value(location))
35
+ ZillowApi::National.new(attributes)
36
+ end
37
+
38
+ def parsed_response(location)
39
+ parse_all(client.get_city_data(location))
40
+ end
41
+
42
+ def parse_all(xml_package)
43
+ Nokogiri::HTML(xml_package)
44
+ end
45
+
46
+ end
47
+ end
48
+ end
data/people.rb ADDED
@@ -0,0 +1,63 @@
1
+ require 'nokogiri'
2
+
3
+ module ZillowApi
4
+ class People
5
+ attr_accessor :single_males, :single_females, :median_age, :average_commute_time
6
+ attr_accessor :transportation, :home_value, :who_live_here
7
+
8
+ def initialize(attributes)
9
+ self.average_commute_time = attributes['average commute time (minutes)']
10
+ self.single_females = attributes['single females']
11
+ self.single_males = attributes['single males']
12
+ self.median_age = attributes['median age']
13
+ self.who_live_here = attributes['lives here']
14
+ self.transportation = attributes['transportation']
15
+ self.home_value = attributes['zillow home value index']
16
+ end
17
+
18
+ class << self
19
+
20
+ def client
21
+ ZillowApi::Client.new
22
+ end
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 }
27
+ Hash[keys.zip(values)]
28
+ end
29
+
30
+ def lives_here_attributes(location)
31
+ keys = parsed_response(location).search("page")[-1].search("liveshere").search("title").map { |value| value.text.downcase }
32
+ values = parsed_response(location).search("page")[-1].search("liveshere").search("name").map { |key| key.text }
33
+ { 'lives here' => Hash[keys.zip(values)] }
34
+ end
35
+
36
+ def mode_of_transit(location)
37
+ key = parsed_response(location).search("uniqueness").search("category").last.attributes['type'].value.downcase
38
+ value = parsed_response(location).search("uniqueness").search("category").last.text
39
+ { key => value }
40
+ end
41
+
42
+ def home_value(location)
43
+ key = parsed_response(location).search("page").first.search("data").first.search("attribute").first.child.text.downcase
44
+ value = parsed_response(location).search("page").first.search("data").first.search("city").first.text
45
+ { key => value }
46
+ end
47
+
48
+ def find_by_city(location)
49
+ attributes = lives_here_attributes(location).merge(demo_attributes(location)).merge(home_value(location)).merge(mode_of_transit(location))
50
+ ZillowApi::People.new(attributes)
51
+ end
52
+
53
+ def parsed_response(location)
54
+ parse_all(client.get_city_data(location))
55
+ end
56
+
57
+ def parse_all(xml_package)
58
+ Nokogiri::HTML(xml_package)
59
+ end
60
+
61
+ end
62
+ end
63
+ end
data/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module ZillowDemographics
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/zillow_demographics/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["michael verdi"]
6
+ gem.email = ["michael.v.verdi@gmail.com"]
7
+ gem.description = %q{wrapper for the zillow zillow_demographics api}
8
+ gem.summary = %q{wrapper for the zillow zillow_demographics api}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "zillow_demographics"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = ZillowDemographics::VERSION
17
+
18
+ gem.add_runtime_dependency('faraday')
19
+ gem.add_runtime_dependency('nokogiri')
20
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zillow_demographics
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - michael verdi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: &70308717122000 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70308717122000
25
+ - !ruby/object:Gem::Dependency
26
+ name: nokogiri
27
+ requirement: &70308717121460 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70308717121460
36
+ description: wrapper for the zillow zillow_demographics api
37
+ email:
38
+ - michael.v.verdi@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - LICENSE
46
+ - README.md
47
+ - Rakefile
48
+ - client.rb
49
+ - lib/zillow_demographics.rb
50
+ - lib/zillow_demographics/client.rb
51
+ - lib/zillow_demographics/national.rb
52
+ - lib/zillow_demographics/people.rb
53
+ - lib/zillow_demographics/version.rb
54
+ - national.rb
55
+ - people.rb
56
+ - version.rb
57
+ - zillow_demographics.gemspec
58
+ homepage: ''
59
+ licenses: []
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 1.8.17
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: wrapper for the zillow zillow_demographics api
82
+ test_files: []