zillow_demographics 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,7 +35,7 @@ module ZillowApi
35
35
 
36
36
  def mode_of_transit(location)
37
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
38
+ value = parsed_response(location).search("uniqueness").search("category").last.children.map {|s| s.text}
39
39
  { key => value }
40
40
  end
41
41
 
@@ -1,3 +1,3 @@
1
1
  module ZillowDemographics
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe ZillowApi::Client do
4
+ let(:client) { ZillowApi::Client.new }
5
+ VALID_CITY = ({city: 'chicago', state: 'il'})
6
+ INVALID_CITY = ({city: 'denver'})
7
+ REQUEST = {
8
+ '0' => "Request successfully processed",
9
+ '1' => "Error: missing parameters"
10
+ }
11
+
12
+ describe "#get_city_data" do
13
+ context "when given a hash including a valid city and state" do
14
+ it "returns an xml package of data for the specified city" do
15
+ response = Nokogiri::HTML(client.get_city_data(VALID_CITY))
16
+ message = response.search("message").children.first.text
17
+ message.should == REQUEST['0']
18
+ end
19
+ end
20
+
21
+ context "when given an invalid hash" do
22
+ it "returns an error message" do
23
+ response = Nokogiri::HTML(client.get_city_data(INVALID_CITY))
24
+ message = response.search("message").children.first.text
25
+ message.should == REQUEST['1']
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ class MockClient
4
+ def get_city_data
5
+
6
+ end
7
+ end
8
+
9
+ describe ZillowApi::People do
10
+ describe ".demo_attributes" do
11
+ end
12
+
13
+ describe ".lives_here_attributes" do
14
+ end
15
+
16
+ describe '.mode_of_transit' do
17
+ end
18
+
19
+ describe '.home_value' do
20
+ end
21
+
22
+ describe '.find_by_city' do
23
+ end
24
+
25
+ describe '.parse_all' do
26
+ end
27
+
28
+ describe '.parsed_response' do
29
+ end
30
+
31
+
32
+ end
@@ -0,0 +1,13 @@
1
+ require 'rspec'
2
+ require 'faraday'
3
+ require 'nokogiri'
4
+ require './lib/zillow_demographics'
5
+ require 'client_spec'
6
+ # require 'people_spec'
7
+ # require 'national_spec'
8
+
9
+ RSpec.configure do |config|
10
+ config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+ end
@@ -4,8 +4,8 @@ require File.expand_path('../lib/zillow_demographics/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["michael verdi"]
6
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}
7
+ gem.description = %q{wrapper for the zillow_demographics api}
8
+ gem.summary = %q{wrapper for the zillow_demographics api}
9
9
  gem.homepage = ""
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
@@ -17,4 +17,5 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_runtime_dependency('faraday')
19
19
  gem.add_runtime_dependency('nokogiri')
20
+ gem.add_development_dependency('rspec')
20
21
  end
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.1
4
+ version: 0.0.2
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-22 00:00:00.000000000 Z
12
+ date: 2012-06-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
16
- requirement: &70308717122000 !ruby/object:Gem::Requirement
16
+ requirement: &70342049238340 !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: *70308717122000
24
+ version_requirements: *70342049238340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &70308717121460 !ruby/object:Gem::Requirement
27
+ requirement: &70342049237720 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,8 +32,19 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70308717121460
36
- description: wrapper for the zillow zillow_demographics api
35
+ version_requirements: *70342049237720
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70342049237020 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70342049237020
47
+ description: wrapper for the zillow_demographics api
37
48
  email:
38
49
  - michael.v.verdi@gmail.com
39
50
  executables: []
@@ -45,14 +56,14 @@ files:
45
56
  - LICENSE
46
57
  - README.md
47
58
  - Rakefile
48
- - client.rb
49
59
  - lib/zillow_demographics.rb
50
60
  - lib/zillow_demographics/client.rb
51
61
  - lib/zillow_demographics/national.rb
52
62
  - lib/zillow_demographics/people.rb
53
63
  - lib/zillow_demographics/version.rb
54
- - national.rb
55
- - people.rb
64
+ - spec/client_spec.rb
65
+ - spec/people_spec.rb
66
+ - spec/spec_helper.rb
56
67
  - version.rb
57
68
  - zillow_demographics.gemspec
58
69
  homepage: ''
@@ -78,5 +89,8 @@ rubyforge_project:
78
89
  rubygems_version: 1.8.17
79
90
  signing_key:
80
91
  specification_version: 3
81
- summary: wrapper for the zillow zillow_demographics api
82
- test_files: []
92
+ summary: wrapper for the zillow_demographics api
93
+ test_files:
94
+ - spec/client_spec.rb
95
+ - spec/people_spec.rb
96
+ - spec/spec_helper.rb
data/client.rb DELETED
@@ -1,23 +0,0 @@
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
data/national.rb DELETED
@@ -1,48 +0,0 @@
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 DELETED
@@ -1,63 +0,0 @@
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