rentjuicer 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,6 +34,9 @@ Rentjuicer::Response also implements some method_missing so any methods on respo
34
34
 
35
35
  @results.neighborhoods == @results.body.neighborhoods
36
36
 
37
+ Rentjuicer::Response by default does not raise an exception if the API errors, but the success? method will return false.
38
+ There are some methods that you can call that will trigger exceptions (typically the ! methods, see below).
39
+
37
40
  In the rest of the README I will be accessing the methods off of response as I think it is cleaner to use and read.
38
41
 
39
42
 
@@ -53,7 +56,11 @@ To get a list of your neighborhoods in rentjuice you can access the neighborhood
53
56
 
54
57
  @response.neighborhoods contains an array of Rentjuice neighborhood objects in Hashie::Rash format
55
58
 
56
- if the request is invalid a Rentjuicer::Error exception will be raised
59
+ If the request is invalid a Rentjuicer::Error exception will be not be raised but the @response.success? will return false.
60
+ To trigger an error to raise if the request is invalid call:
61
+
62
+ @response = @neighborhoods.find_all!
63
+
57
64
 
58
65
 
59
66
  === Adding a lead to your account
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
1
+ 0.6.0
@@ -11,5 +11,19 @@ module Rentjuicer
11
11
  self.class.base_uri "api.rentjuice.com/#{self.api_key}"
12
12
  end
13
13
 
14
+ def process_get(resource, params = {})
15
+ begin
16
+ unless params.blank?
17
+ self.class.get(resource, :query => params)
18
+ else
19
+ self.class.get(resource)
20
+ end
21
+ rescue Timeout::Error
22
+ {"status" => "timeout", "code" => "0", "message" => "Rentjuice API is timing out."}
23
+ rescue Exception
24
+ {"status" => "busted", "code" => "0", "message" => "Rentjuice API is erroring."}
25
+ end
26
+ end
27
+
14
28
  end
15
29
  end
@@ -10,7 +10,7 @@ module Rentjuicer
10
10
 
11
11
  def create(name, params = {}, raise_error = false)
12
12
  params.merge!(:name => name)
13
- Response.new(self.client.class.get(resource, :query => params), raise_error)
13
+ Response.new(self.client.process_get(resource, params), raise_error)
14
14
  end
15
15
 
16
16
  def create!(name, params = {})
@@ -12,7 +12,7 @@ module Rentjuicer
12
12
  limit = params[:limit] || 20
13
13
  params[:order_by] ||= "rent"
14
14
  params[:order_direction] ||= "asc"
15
- SearchResponse.new(self.client.class.get(resource, :query => params), limit)
15
+ SearchResponse.new(self.client.process_get(resource, params), limit)
16
16
  end
17
17
 
18
18
  def featured(params = {})
@@ -21,7 +21,7 @@ module Rentjuicer
21
21
  end
22
22
 
23
23
  def find_by_id(listing_id)
24
- response = SearchResponse.new(self.client.class.get(resource, :query => {:rentjuice_id => listing_id}))
24
+ response = SearchResponse.new(self.client.process_get(resource, {:rentjuice_id => listing_id}))
25
25
  (response.success? && response.properties.size > 0) ? response.properties.first : nil
26
26
  end
27
27
 
@@ -8,8 +8,12 @@ module Rentjuicer
8
8
  self.resource = "/neighborhoods.json"
9
9
  end
10
10
 
11
- def find_all
12
- Response.new(self.client.class.get(resource))
11
+ def find_all(raise_error = false)
12
+ Response.new(self.client.process_get(resource), raise_error)
13
+ end
14
+
15
+ def find_all!
16
+ find_all(true)
13
17
  end
14
18
 
15
19
  end
@@ -3,13 +3,13 @@ module Rentjuicer
3
3
 
4
4
  attr_accessor :body
5
5
 
6
- def initialize(response, raise_error = true)
6
+ def initialize(response, raise_error = false)
7
7
  rash_response(response)
8
8
  raise Error.new(self.body.code, self.body.message) if !success? && raise_error
9
9
  end
10
10
 
11
11
  def success?
12
- self.body.status == "ok"
12
+ self.body && !self.body.blank? && self.body.respond_to?(:status) && self.body.status == "ok"
13
13
  end
14
14
 
15
15
  def method_missing(method_name, *args)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rentjuicer}
8
- s.version = "0.5.1"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["tcocca"]
12
- s.date = %q{2011-04-19}
12
+ s.date = %q{2011-04-21}
13
13
  s.description = %q{Ruby API wrapper for rentjuice.com built with httparty}
14
14
  s.email = %q{tom.cocca@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -8,9 +8,15 @@ describe Rentjuicer::Error do
8
8
  mock_get(@neighborhoods.resource, 'error.json')
9
9
  end
10
10
 
11
- it "should return an error" do
11
+ it "should not return an error" do
12
12
  lambda {
13
13
  @neighborhoods.find_all
14
+ }.should_not raise_exception
15
+ end
16
+
17
+ it "should return an error" do
18
+ lambda {
19
+ @neighborhoods.find_all!
14
20
  }.should raise_exception(Rentjuicer::Error, "Rentjuicer Error: Invalid API key. (code: 1)")
15
21
  end
16
22
 
@@ -9,26 +9,26 @@ describe Rentjuicer::Response do
9
9
  mock_get(@neighborhoods.resource, 'error.json')
10
10
  end
11
11
 
12
- it "should raise an exception" do
12
+ it "should not raise an exception" do
13
13
  lambda {
14
14
  @neighborhoods.find_all
15
- }.should raise_exception
16
- end
17
- end
18
-
19
- context "passing raise_errors = false" do
20
- it "should not raise errors when raise_errors is false" do
21
- lambda {
22
- Rentjuicer::Response.new(httparty_get('/neighborhoods.json', 'error.json'), false)
23
15
  }.should_not raise_exception
24
16
  end
25
17
 
26
18
  it "should not be a success" do
27
- @response = Rentjuicer::Response.new(httparty_get('/neighborhoods.json', 'error.json'), false)
19
+ @response = Rentjuicer::Response.new(httparty_get('/neighborhoods.json', 'error.json'))
28
20
  @response.success?.should be_false
29
21
  end
30
22
  end
31
23
 
24
+ context "passing raise_errors = true" do
25
+ it "should raise errors when raise_errors is false" do
26
+ lambda {
27
+ Rentjuicer::Response.new(httparty_get('/neighborhoods.json', 'error.json'), true)
28
+ }.should raise_exception(Rentjuicer::Error, "Rentjuicer Error: Invalid API key. (code: 1)")
29
+ end
30
+ end
31
+
32
32
  context "should return a response" do
33
33
  before do
34
34
  @rentjuicer = new_rentjuicer
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rentjuicer
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 5
9
- - 1
10
- version: 0.5.1
8
+ - 6
9
+ - 0
10
+ version: 0.6.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - tcocca
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-19 00:00:00 -04:00
18
+ date: 2011-04-21 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency