zester 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -18,6 +18,16 @@ You do not need to pass the 'zws-id' param to any api calls, this param will be
18
18
 
19
19
  All other params for each api call are passed as a hash with the keys as strings in the exact same format as specified in the Zillow API docs
20
20
 
21
+ There is also an optional parameter to set the timeout in seconds, passing this will raise a Timeout::Error after that number of seconds
22
+
23
+ ```ruby
24
+ zester = Zester::Client.new('your_api_key', 5) # raises a Timeout::Error after 5 seconds with no response
25
+ ```
26
+
27
+ Timeout::Errors and other Exceptions are automatically rescued in the Zester::Resource class and will return a
28
+ fake response telling you 'Web services are currently unavailable' in the @response.error_message method, same as any actual Zillow api error messages.
29
+ Also, the @response.response_code will be 3.
30
+
21
31
  ### Home Valuation
22
32
 
23
33
  Zillow 'Home Valuation' calls are accessed off of the client#valuation method:
data/lib/zester/client.rb CHANGED
@@ -5,15 +5,23 @@ module Zester
5
5
  format :xml
6
6
  base_uri "http://www.zillow.com/webservice"
7
7
 
8
- attr_accessor :zws_id
8
+ attr_accessor :zws_id, :http_timeout
9
9
 
10
- def initialize(zws_id)
10
+ def initialize(zws_id, http_timeout = nil)
11
11
  self.zws_id = zws_id
12
+ self.http_timeout = http_timeout
12
13
  self.class.default_params "zws-id" => zws_id
13
14
  end
14
15
 
15
16
  def perform_get(endpoint, params = {})
16
- self.class.get("/#{endpoint}.htm", :query => params)
17
+ http_params = {}
18
+ unless params.empty?
19
+ http_params[:query] = params
20
+ end
21
+ unless self.http_timeout.nil?
22
+ http_params[:timeout] = self.http_timeout
23
+ end
24
+ self.class.get("/#{endpoint}.htm", http_params)
17
25
  end
18
26
 
19
27
  def property
@@ -8,7 +8,11 @@ module Zester
8
8
  end
9
9
 
10
10
  def get_results(endpoint, resource_type, params = {})
11
- Response.new(self.client.perform_get(endpoint, params), resource_type)
11
+ begin
12
+ Response.new(self.client.perform_get(endpoint, params), resource_type)
13
+ rescue Timeout::Error, Exception
14
+ Response.new({resource_type => {:message => {:code => "3", :text => "Web services are currently unavailable"}}}, resource_type)
15
+ end
12
16
  end
13
17
 
14
18
  end
@@ -1,3 +1,3 @@
1
1
  module Zester
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -3,3 +3,7 @@ ZWS_ID = YAML.load_file(File.join(File.dirname(__FILE__), '/../zillow_api_key.ym
3
3
  def new_zester
4
4
  Zester::Client.new(ZWS_ID)
5
5
  end
6
+
7
+ def new_timeout_zester
8
+ Zester::Client.new(ZWS_ID, 5)
9
+ end
@@ -1,34 +1,47 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Zester::Client do
4
- let!(:zester) {new_zester}
4
+ context "basic" do
5
+ let!(:zester) {new_zester}
5
6
 
6
- it "should set the zws_id" do
7
- zester.zws_id.should == ZWS_ID
8
- zester.class.default_params.should == {'zws-id' => ZWS_ID}
9
- end
7
+ it "should set the zws_id" do
8
+ zester.zws_id.should == ZWS_ID
9
+ zester.http_timeout.should be_nil
10
+ zester.class.default_params.should == {'zws-id' => ZWS_ID}
11
+ end
10
12
 
11
- it "should set the base uri for the client" do
12
- zester.class.base_uri.should == "http://www.zillow.com/webservice"
13
- end
13
+ it "should set the base uri for the client" do
14
+ zester.class.base_uri.should == "http://www.zillow.com/webservice"
15
+ end
14
16
 
15
- it "should return an instance of Zester::Valuation for valuation" do
16
- zester.valuation.should be_kind_of(Zester::Valuation)
17
- zester.valuation.client.should == zester
18
- end
17
+ it "should return an instance of Zester::Valuation for valuation" do
18
+ zester.valuation.should be_kind_of(Zester::Valuation)
19
+ zester.valuation.client.should == zester
20
+ end
19
21
 
20
- it "should return an instance of Zester::Valuatiion for property" do
21
- zester.property.should be_kind_of(Zester::Property)
22
- zester.property.client.should == zester
23
- end
22
+ it "should return an instance of Zester::Valuatiion for property" do
23
+ zester.property.should be_kind_of(Zester::Property)
24
+ zester.property.client.should == zester
25
+ end
26
+
27
+ it "should return an instance of Zester::Valuatiion for mortgage" do
28
+ zester.mortgage.should be_kind_of(Zester::Mortgage)
29
+ zester.mortgage.client.should == zester
30
+ end
24
31
 
25
- it "should return an instance of Zester::Valuatiion for mortgage" do
26
- zester.mortgage.should be_kind_of(Zester::Mortgage)
27
- zester.mortgage.client.should == zester
32
+ it "should return an instance of Zester::Valuatiion for neighborhood" do
33
+ zester.neighborhood.should be_kind_of(Zester::Neighborhood)
34
+ zester.neighborhood.client.should == zester
35
+ end
28
36
  end
29
37
 
30
- it "should return an instance of Zester::Valuatiion for neighborhood" do
31
- zester.neighborhood.should be_kind_of(Zester::Neighborhood)
32
- zester.neighborhood.client.should == zester
38
+ context "timeout" do
39
+ let!(:zester) {new_timeout_zester}
40
+
41
+ it "should set the zws_id" do
42
+ zester.zws_id.should == ZWS_ID
43
+ zester.http_timeout.should == 5
44
+ zester.class.default_params.should == {'zws-id' => ZWS_ID}
45
+ end
33
46
  end
34
47
  end
@@ -17,4 +17,23 @@ describe Zester::Resource do
17
17
  end
18
18
  end
19
19
 
20
+ context "timeout error" do
21
+ before(:all) do
22
+ VCR.turn_off!
23
+ end
24
+
25
+ after(:all) do
26
+ VCR.turn_on!
27
+ end
28
+
29
+ it "should rescue a timeout error" do
30
+ stub_request(:get, "http://www.zillow.com/webservice/GetRateSummary.htm?zws-id=#{ZWS_ID}").to_timeout
31
+ response = resource.get_results('GetRateSummary', :rate_summary)
32
+ response.success?.should be_false
33
+ response.message.should_not be_nil
34
+ response.message.code.should == "3"
35
+ response.response_code.should == 3
36
+ end
37
+ end
38
+
20
39
  end
@@ -8,7 +8,7 @@ describe Zester::Response do
8
8
  VCR.use_cassette('response') do
9
9
  response = resource.get_results('GetRateSummary', :rate_summary)
10
10
  response.success?.should be_true
11
- response.message.should_not be_nill
11
+ response.message.should_not be_nil
12
12
  response.message.code.should == "0"
13
13
  response.response_code.should == 0
14
14
  response.should be_instance_of(Zester::Response)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zester
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 2
8
9
  - 1
9
- - 0
10
- version: 0.1.0
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tom Cocca
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-09 00:00:00 Z
18
+ date: 2012-12-20 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :runtime