sjain-redfin_api 0.1.2 → 0.1.3

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.
data/Manifest CHANGED
@@ -11,6 +11,10 @@ test/data/gis_id_search.json
11
11
  test/data/property_page.html
12
12
  test/data/query_location_listings.json
13
13
  test/data/query_location_pastSalesBuildings.json
14
+ test/data/redfin/gis-id-search-empty.json
15
+ test/data/redfin/gis-id-search-listing.json
16
+ test/data/redfin/query-location-listing.json
17
+ test/data/redfin/query-location-non-listing.json
14
18
  test/test_helper.rb
15
19
  test/test_redfin_api.rb
16
20
  test/test_redfin_base.rb
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 2
4
+ :patch: 3
@@ -5,38 +5,12 @@ require 'net/http'
5
5
  module RedfinApi
6
6
  module Base
7
7
  class << self
8
- # this method is often overridden for testing purposes
9
- def http_get(url)
10
- Net::HTTP.get_response(URI.parse(url)).body
11
- end
12
- def http_get_json(url)
13
- response = http_get(url)
14
- response = response.strip[2..-3] # ignore the /* and */
15
- # puts "response = #{response}"
16
- require 'json'
17
- json_hash = JSON.parse(response)
18
- # TODO symbolize_keys! here
19
- json_hash
20
- end
21
- def fetch_address(url)
22
- response = http_get(url)
23
- doc = Hpricot(response)
24
- address = {}
25
- address[:address_line_1] = (doc/'#address_line_1')[0].to_plain_text rescue nil
26
- address[:city] = (doc/'#address_line_2 .locality')[0].to_plain_text rescue nil
27
- address[:state] = (doc/'#address_line_2 .region')[0].to_plain_text rescue nil
28
- address[:zip] = (doc/'#address_line_2 .postal-code')[0].to_plain_text rescue nil
29
- address[:pin] = extract_pin(response)
30
- address
31
- end
32
- def extract_pin(html)
33
- /Parcel Identification Number:\s*(\d{10,14})/.match(html)[1].strip
34
- end
35
8
  def query_location(address)
36
9
  url = "http://www.redfin.com/stingray/do/query-location?location=#{URI.encode(address)}"
37
10
  location = http_get_json(url)
38
11
  # we either get a postSalesBuildings element or listings element
39
12
  item = location['pastSalesBuildings'].not_nil? ? location['pastSalesBuildings'][0] : location['listings'][0]
13
+ return nil if !item
40
14
  address = item['address']
41
15
  hash = {
42
16
  :lat => item['point']['lat'].to_s,
@@ -75,6 +49,26 @@ module RedfinApi
75
49
  :url => "http://www.redfin.com#{payload['URL']}",
76
50
  }
77
51
  end
52
+ def extract_pin(url)
53
+ response = http_get(url)
54
+ /Parcel Identification Number:\s*(\d{10,14})/.match(response)[1].strip
55
+ rescue
56
+ puts "Failed to extract PIN from redfin url: #{$!}"
57
+ nil
58
+ end
59
+ # this method is often overridden for testing purposes
60
+ def http_get(url)
61
+ Net::HTTP.get_response(URI.parse(url)).body
62
+ end
63
+ def http_get_json(url)
64
+ response = http_get(url)
65
+ response = response.strip[2..-3] # ignore the /* and */
66
+ # puts "response = #{response}"
67
+ require 'json'
68
+ json_hash = JSON.parse(response)
69
+ # TODO symbolize_keys! here
70
+ json_hash
71
+ end
78
72
  end
79
73
  end
80
74
  end
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{redfin_api}
5
- s.version = "0.1.2"
5
+ s.version = "0.1.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Sharad Jain"]
9
- s.date = %q{2009-09-16}
9
+ s.date = %q{2009-09-17}
10
10
  s.description = %q{Redfin.com webservice interface}
11
11
  s.email = %q{shaanjain@gmail.com}
12
12
  s.extra_rdoc_files = ["README.rdoc", "lib/object.rb", "lib/redfin_api.rb", "lib/redfin_api/base.rb", "tasks/redfin.rake"]
13
- s.files = ["Manifest", "README.rdoc", "Rakefile", "VERSION.yml", "lib/object.rb", "lib/redfin_api.rb", "lib/redfin_api/base.rb", "redfin_api.gemspec", "tasks/redfin.rake", "test/data/gis_id_search.json", "test/data/property_page.html", "test/data/query_location_listings.json", "test/data/query_location_pastSalesBuildings.json", "test/test_helper.rb", "test/test_redfin_api.rb", "test/test_redfin_base.rb"]
13
+ s.files = ["Manifest", "README.rdoc", "Rakefile", "VERSION.yml", "lib/object.rb", "lib/redfin_api.rb", "lib/redfin_api/base.rb", "redfin_api.gemspec", "tasks/redfin.rake", "test/data/gis_id_search.json", "test/data/property_page.html", "test/data/query_location_listings.json", "test/data/query_location_pastSalesBuildings.json", "test/data/redfin/gis-id-search-empty.json", "test/data/redfin/gis-id-search-listing.json", "test/data/redfin/query-location-listing.json", "test/data/redfin/query-location-non-listing.json", "test/test_helper.rb", "test/test_redfin_api.rb", "test/test_redfin_base.rb"]
14
14
  s.has_rdoc = true
15
15
  s.homepage = %q{http://github.com/sjain/redfin_api}
16
16
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Redfin_api", "--main", "README.rdoc"]
@@ -0,0 +1 @@
1
+ /*({"errorMessage":"No error.","resultCode":0,"payload":[],"version":10})*/
@@ -0,0 +1 @@
1
+ /*({"errorMessage":"No error.","resultCode":0,"payload":[{"is_short_sale":false,"dom":5,"original_price":399900,"visibility_profile":"111111111111111111","mls_status":85,"type":"residential","date":1252998000000,"sqft":3454,"available_photos":"0:0","id":4658217,"search_status":2,"parcel":{"id":16957456,"longitude":-88.19809,"latitude":42.004822},"last_sale_date":"2006-09-27","is_new":false,"price_display":"$409,900","price_is_above_min":true,"est_redfin_direct_rebate":4748,"est_connect_rebate":1537,"URL":"/IL/Bartlett/438-Timber-Ridge-Dr-60103/home/13753708","baths":3,"address_data":{"zip":"60103","street":"Timber Ridge","state":"IL","unmapped":false,"number":"438","display":"438 Timber Ridge Ln","undisclosed":false,"type":"Ln","city":"BARTLETT"},"year_built":1989,"listing_type":1,"neighborhood":"Bartlett","property":{"id":13753708},"service_region_type":2,"open_house_time_end":1253394000000,"display_order":1,"lotsize":21344,"datasource_id":68,"securePhotoNum":0,"mlsid":"07323121","listing_broker_name":"KMS Realty, Inc.","beds":4,"price":409900,"market_id":6,"fixer":false,"open_house_time_display":"Sat, Sep 19 1 - 4 PM","listing_added":1252768338454,"open_house_time_start":1253383200000,"property_type_raw":6,"last_sale_price":518000}],"version":10})*/
@@ -0,0 +1 @@
1
+ /*{"listings":[{"id":4658217,"point":{"long":-88.19809,"lat":42.004822},"market":"chicago","address":{"zip":"60103","state":"IL","streetName":"Timber Ridge","number":"438","undisclosed":false,"streetType":"Ln","city":"BARTLETT"},"visibility_profile":"111111111111111111"}],"regions":[]}*/
@@ -0,0 +1 @@
1
+ /*{"pastSalesBuildings":[{"id":12562821,"point":{"long":-88.136536,"lat":42.052528},"market":"chicago","address":{"zip":"60169","unitType":"","state":"IL","streetName":"Poplar Creek","number":"1552","directionalPrefix":"","streetType":"Dr","unitValue":"","city":"Hoffman Estates","directionalSuffix":""}}],"listings":[],"regions":[]}*/
@@ -7,18 +7,13 @@ class TestRedfinApiBase < Test::Unit::TestCase
7
7
  RedfinApi::Base.stubs(:http_get).with(@url).returns(File.read(File.dirname(__FILE__) + "/data/property_page.html"))
8
8
  end
9
9
  should "extract PIN information" do
10
- address = RedfinApi::Base.fetch_address(@url)
11
- assert_equal("07343000300000", address[:pin])
10
+ pin = RedfinApi::Base.extract_pin(@url)
11
+ assert_equal("07343000300000", pin)
12
12
  end
13
13
  end
14
- should "fetch address from redfin url" do
15
- url = "http://www.redfin.com/IL/Roselle/999-Main-St-60606/home/99999999"
16
- RedfinApi::Base.stubs(:http_get).with(url).returns(File.read(File.dirname(__FILE__) + "/data/property_page.html"))
17
- address = RedfinApi::Base.fetch_address(url)
18
- assert_equal("640 WASHINGTON Ct", address[:address_line_1])
19
- assert_equal("ROSELLE", address[:city])
20
- assert_equal("IL", address[:state])
21
- assert_equal("60172", address[:zip])
14
+ should "return nil when specified address could not be found" do
15
+ RedfinApi::Base.stubs(:http_get).returns('/*{"listings":[],"regions":[]}*/')
16
+ assert_equal(nil, RedfinApi::Base.query_location("some unlocatable address"))
22
17
  end
23
18
  context "with query location returning pastSalesBuildings" do
24
19
  setup do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sjain-redfin_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharad Jain
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-16 00:00:00 -07:00
12
+ date: 2009-09-17 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -39,6 +39,10 @@ files:
39
39
  - test/data/property_page.html
40
40
  - test/data/query_location_listings.json
41
41
  - test/data/query_location_pastSalesBuildings.json
42
+ - test/data/redfin/gis-id-search-empty.json
43
+ - test/data/redfin/gis-id-search-listing.json
44
+ - test/data/redfin/query-location-listing.json
45
+ - test/data/redfin/query-location-non-listing.json
42
46
  - test/test_helper.rb
43
47
  - test/test_redfin_api.rb
44
48
  - test/test_redfin_base.rb