rentjuicer 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.1
1
+ 0.7.2
@@ -65,7 +65,7 @@ module Rentjuicer
65
65
  end
66
66
 
67
67
  def properties
68
- return [] if self.body.listings.blank?
68
+ return [] if !self.success? || self.body.listings.blank?
69
69
  @cached_properties ||= begin
70
70
  props = []
71
71
  self.body.listings.each do |listing|
data/lib/rentjuicer.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'httparty'
3
- require 'hashie'
4
3
  require 'rash'
5
4
  require 'will_paginate/collection'
6
5
  require 'active_support/core_ext/array/grouping'
data/rentjuicer.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rentjuicer}
8
- s.version = "0.7.1"
8
+ s.version = "0.7.2"
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-10-30}
12
+ s.date = %q{2012-01-27}
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 = [
@@ -40,6 +40,7 @@ Gem::Specification.new do |s|
40
40
  "spec/rentjuicer/neighborhoods_spec.rb",
41
41
  "spec/rentjuicer/response_spec.rb",
42
42
  "spec/rentjuicer_api_key.yml.example",
43
+ "spec/responses/empty_response.json",
43
44
  "spec/responses/error.json",
44
45
  "spec/responses/featured.json",
45
46
  "spec/responses/find_all_1.json",
@@ -51,9 +52,10 @@ Gem::Specification.new do |s|
51
52
  "spec/responses/lead.json",
52
53
  "spec/responses/lead_error.json",
53
54
  "spec/responses/listings.json",
55
+ "spec/responses/missing_listings.json",
54
56
  "spec/responses/mls_listings.json",
55
57
  "spec/responses/neighborhoods.json",
56
- "spec/responses/no_listings.json",
58
+ "spec/responses/null_listings.json",
57
59
  "spec/spec_helper.rb",
58
60
  "spec/support/listing_helper.rb",
59
61
  "spec/support/webmock_helper.rb"
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rentjuicer::Listing do
4
-
4
+
5
5
  before do
6
6
  @listing = Rentjuicer::Listing.new(valid_listing_rash)
7
7
  end
8
-
8
+
9
9
  it "should create methods from all hash keys" do
10
10
  @listing.should respond_to(
11
11
  "address", "agent_phone", "bedrooms", "latitude", "title", "photos", "featured", "url", "date_available",
@@ -14,23 +14,23 @@ describe Rentjuicer::Listing do
14
14
  "longitude", "description", "agent_name", "rentjuice_id"
15
15
  )
16
16
  end
17
-
17
+
18
18
  it "should return rentjuice_id for id" do
19
19
  @listing.id.should == 200306
20
20
  end
21
-
21
+
22
22
  it "should return the first neighborhood in the array for neighborhood_name" do
23
23
  @listing.neighborhood_name.should == 'South Boston'
24
24
  end
25
-
25
+
26
26
  it "should return the thumbnail url of the first sorted pic for thumb_pic" do
27
27
  @listing.thumb_pic.should == "http://static.rentjuice.com/frames/2010/08/25/3008760.jpg"
28
28
  end
29
-
29
+
30
30
  it "should return the fullsize url of the first sorted pic for first_pic" do
31
31
  @listing.first_pic.should == "http://static.rentjuice.com/frames/2010/08/25/3008757.jpg"
32
32
  end
33
-
33
+
34
34
  it "should return the first element of the sorted photos for main_pic" do
35
35
  @listing.main_pic.should == Hashie::Rash.new({
36
36
  "thumbnail" => "http://static.rentjuice.com/frames/2010/08/25/3008760.jpg",
@@ -39,11 +39,11 @@ describe Rentjuicer::Listing do
39
39
  "fullsize" => "http://static.rentjuice.com/frames/2010/08/25/3008757.jpg"
40
40
  })
41
41
  end
42
-
42
+
43
43
  it "should return an array of photos sorted by the sort_order key for sorted_photos" do
44
44
  @listing.sorted_photos.should == sorted_photos_array
45
45
  end
46
-
46
+
47
47
  context "default similar listings" do
48
48
  before do
49
49
  @rentjuicer = new_rentjuicer
@@ -61,14 +61,14 @@ describe Rentjuicer::Listing do
61
61
  })
62
62
  @similar_props = @listing.similar_listings(@rentjuicer)
63
63
  end
64
-
64
+
65
65
  it "should return an array of listings" do
66
66
  @similar_props.should be_kind_of(Array)
67
67
  @similar_props.should have_at_most(6).listings
68
68
  @similar_props.collect{|x| x.id}.should_not include(@listing.id)
69
69
  end
70
70
  end
71
-
71
+
72
72
  context "similar listings with custom limit" do
73
73
  before do
74
74
  @rentjuicer = new_rentjuicer
@@ -86,14 +86,85 @@ describe Rentjuicer::Listing do
86
86
  })
87
87
  @similar_props = @listing.similar_listings(@rentjuicer, 4)
88
88
  end
89
-
89
+
90
90
  it "should return an array of listings" do
91
91
  @similar_props.should be_kind_of(Array)
92
92
  @similar_props.should have_at_most(4).listings
93
93
  @similar_props.collect{|x| x.id}.should_not include(@listing.id)
94
94
  end
95
95
  end
96
-
96
+
97
+ context "nil similar listings" do
98
+ context "null listings" do
99
+ before do
100
+ @rentjuicer = new_rentjuicer
101
+ mock_get('/listings.json', 'null_listings.json', {
102
+ :neighborhoods => "South Boston",
103
+ :min_rent => "2250.0",
104
+ :max_rent => "2750.0",
105
+ :min_beds => "2",
106
+ :max_beds => "4",
107
+ :min_baths => "0",
108
+ :max_baths => "2",
109
+ :limit => "7",
110
+ :order_by => "rent",
111
+ :order_direction => "asc"
112
+ })
113
+ @similar_props = @listing.similar_listings(@rentjuicer)
114
+ end
115
+
116
+ it "should return an empty array of listings" do
117
+ @similar_props.should be_empty
118
+ end
119
+ end
120
+
121
+ context "missing listings" do
122
+ before do
123
+ @rentjuicer = new_rentjuicer
124
+ mock_get('/listings.json', 'missing_listings.json', {
125
+ :neighborhoods => "South Boston",
126
+ :min_rent => "2250.0",
127
+ :max_rent => "2750.0",
128
+ :min_beds => "2",
129
+ :max_beds => "4",
130
+ :min_baths => "0",
131
+ :max_baths => "2",
132
+ :limit => "7",
133
+ :order_by => "rent",
134
+ :order_direction => "asc"
135
+ })
136
+ @similar_props = @listing.similar_listings(@rentjuicer)
137
+ end
138
+
139
+ it "should return an empty array of listings" do
140
+ @similar_props.should be_empty
141
+ end
142
+ end
143
+
144
+ context "empty response" do
145
+ before do
146
+ @rentjuicer = new_rentjuicer
147
+ mock_get('/listings.json', 'empty_response.json', {
148
+ :neighborhoods => "South Boston",
149
+ :min_rent => "2250.0",
150
+ :max_rent => "2750.0",
151
+ :min_beds => "2",
152
+ :max_beds => "4",
153
+ :min_baths => "0",
154
+ :max_baths => "2",
155
+ :limit => "7",
156
+ :order_by => "rent",
157
+ :order_direction => "asc"
158
+ })
159
+ @similar_props = @listing.similar_listings(@rentjuicer)
160
+ end
161
+
162
+ it "should return an empty array of listings" do
163
+ @similar_props.should be_empty
164
+ end
165
+ end
166
+ end
167
+
97
168
  context "mls_listing" do
98
169
  context "mlspin - 2 br tags" do
99
170
  before do
@@ -103,14 +174,14 @@ describe Rentjuicer::Listing do
103
174
  "attribution" => "This listing courtesy of Holly Kampler at Classic Realty<br \/><br \/>The property listing data and information, or the Images, set forth herein were provided to MLS Property Information Network, Inc. from third party sources, including sellers, lessors and public records, and were compiled by MLS Property Information Network, Inc. The property listing data and information, and the Images, are for the personal, non-commercial use of consumers having a good faith interest in purchasing or leasing listed properties of the type displayed to them and may not be used for any purpose other than to identify prospective properties which such consumers may have a good faith interest in purchasing or leasing. MLS Property Information Network, Inc. and its subscribers disclaim any and all representations and warranties as to the accuracy of the property listing data and information, or as to the accuracy of any of the Images, set forth herein."
104
175
  }))
105
176
  end
106
-
177
+
107
178
  it { @listing.mls_listing?.should be_true }
108
179
  it { @listing.source_name.should == "MLS PIN" }
109
180
  it { @listing.attribution.should == "This listing courtesy of Holly Kampler at Classic Realty<br \/><br \/>The property listing data and information, or the Images, set forth herein were provided to MLS Property Information Network, Inc. from third party sources, including sellers, lessors and public records, and were compiled by MLS Property Information Network, Inc. The property listing data and information, and the Images, are for the personal, non-commercial use of consumers having a good faith interest in purchasing or leasing listed properties of the type displayed to them and may not be used for any purpose other than to identify prospective properties which such consumers may have a good faith interest in purchasing or leasing. MLS Property Information Network, Inc. and its subscribers disclaim any and all representations and warranties as to the accuracy of the property listing data and information, or as to the accuracy of any of the Images, set forth herein."}
110
181
  it { @listing.courtesy_of.should == "This listing courtesy of Holly Kampler at Classic Realty"}
111
182
  it { @listing.mls_disclaimer.should == "The property listing data and information, or the Images, set forth herein were provided to MLS Property Information Network, Inc. from third party sources, including sellers, lessors and public records, and were compiled by MLS Property Information Network, Inc. The property listing data and information, and the Images, are for the personal, non-commercial use of consumers having a good faith interest in purchasing or leasing listed properties of the type displayed to them and may not be used for any purpose other than to identify prospective properties which such consumers may have a good faith interest in purchasing or leasing. MLS Property Information Network, Inc. and its subscribers disclaim any and all representations and warranties as to the accuracy of the property listing data and information, or as to the accuracy of any of the Images, set forth herein."}
112
183
  end
113
-
184
+
114
185
  context "RAMB - no disclaimer, attribution only" do
115
186
  before do
116
187
  @listing = Rentjuicer::Listing.new(valid_listing_rash.merge({
@@ -119,14 +190,14 @@ describe Rentjuicer::Listing do
119
190
  "attribution" => "This listing is courtesy of XYZ Realty"
120
191
  }))
121
192
  end
122
-
193
+
123
194
  it { @listing.mls_listing?.should be_true }
124
195
  it { @listing.source_name.should == "RAMB" }
125
196
  it { @listing.attribution.should == "This listing is courtesy of XYZ Realty"}
126
197
  it { @listing.courtesy_of.should == "This listing is courtesy of XYZ Realty"}
127
198
  it { @listing.mls_disclaimer.should be_nil}
128
199
  end
129
-
200
+
130
201
  context "MRED - 1 br and an image" do
131
202
  before do
132
203
  @listing = Rentjuicer::Listing.new(valid_listing_rash.merge({
@@ -135,14 +206,14 @@ describe Rentjuicer::Listing do
135
206
  "attribution" => "<img src=\"http://idx.advancedaccess.com/disclaimer/brlogo125.jpg\" style=\"float:left; padding-right:10px;\" />Listing office: XYZ Realty<br />Properties marked with the MRED approved icon are courtesy of Midwest Real Estate Data, LLC. Information deemed reliable but not guaranteed. Copyright&copy; 2010 Midwest Real Estate Data LLC. All rights reserved."
136
207
  }))
137
208
  end
138
-
209
+
139
210
  it { @listing.mls_listing?.should be_true }
140
211
  it { @listing.source_name.should == "MRED" }
141
212
  it { @listing.attribution.should == "<img src=\"http://idx.advancedaccess.com/disclaimer/brlogo125.jpg\" style=\"float:left; padding-right:10px;\" />Listing office: XYZ Realty<br />Properties marked with the MRED approved icon are courtesy of Midwest Real Estate Data, LLC. Information deemed reliable but not guaranteed. Copyright&copy; 2010 Midwest Real Estate Data LLC. All rights reserved."}
142
213
  it { @listing.courtesy_of.should == "<img src=\"http://idx.advancedaccess.com/disclaimer/brlogo125.jpg\" style=\"float:left; padding-right:10px;\" />Listing office: XYZ Realty"}
143
214
  it { @listing.mls_disclaimer.should == "Properties marked with the MRED approved icon are courtesy of Midwest Real Estate Data, LLC. Information deemed reliable but not guaranteed. Copyright&copy; 2010 Midwest Real Estate Data LLC. All rights reserved."}
144
215
  end
145
-
216
+
146
217
  context "nil attribution" do
147
218
  before do
148
219
  @listing = Rentjuicer::Listing.new(valid_listing_rash.merge({
@@ -151,14 +222,14 @@ describe Rentjuicer::Listing do
151
222
  "attribution" => nil
152
223
  }))
153
224
  end
154
-
225
+
155
226
  it { @listing.mls_listing?.should be_true }
156
227
  it { @listing.source_name.should == "MLS PIN" }
157
228
  it { @listing.attribution.should == nil}
158
229
  it { @listing.courtesy_of.should == nil}
159
230
  it { @listing.mls_disclaimer.should == nil}
160
231
  end
161
-
232
+
162
233
  context "missing attribution" do
163
234
  before do
164
235
  @listing = Rentjuicer::Listing.new(valid_listing_rash.merge({
@@ -166,14 +237,14 @@ describe Rentjuicer::Listing do
166
237
  "source_name" => "MLS PIN"
167
238
  }))
168
239
  end
169
-
240
+
170
241
  it { @listing.mls_listing?.should be_true }
171
242
  it { @listing.source_name.should == "MLS PIN" }
172
243
  it { @listing.attribution.should == nil}
173
244
  it { @listing.courtesy_of.should == nil}
174
245
  it { @listing.mls_disclaimer.should == nil}
175
246
  end
176
-
247
+
177
248
  context "blank attribution" do
178
249
  before do
179
250
  @listing = Rentjuicer::Listing.new(valid_listing_rash.merge({
@@ -182,7 +253,7 @@ describe Rentjuicer::Listing do
182
253
  "attribution" => ""
183
254
  }))
184
255
  end
185
-
256
+
186
257
  it { @listing.mls_listing?.should be_true }
187
258
  it { @listing.source_name.should == "MLS PIN" }
188
259
  it { @listing.attribution.should == ""}
@@ -190,5 +261,5 @@ describe Rentjuicer::Listing do
190
261
  it { @listing.mls_disclaimer.should == nil}
191
262
  end
192
263
  end
193
-
264
+
194
265
  end
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rentjuicer::Listing do
4
-
4
+
5
5
  before do
6
6
  @rentjuicer = new_rentjuicer
7
7
  @listings = Rentjuicer::Listings.new(@rentjuicer)
8
8
  end
9
-
9
+
10
10
  context "search" do
11
11
  before do
12
12
  mock_get('/listings.json', 'listings.json', {
@@ -16,21 +16,22 @@ describe Rentjuicer::Listing do
16
16
  })
17
17
  @result = @listings.search(:neighborhoods => "South Boston")
18
18
  end
19
-
19
+
20
20
  it { @result.should be_kind_of(Rentjuicer::Listings::SearchResponse) }
21
21
  it { @result.success?.should be_true }
22
-
22
+
23
23
  context "search response" do
24
24
  it { @result.should be_kind_of(Rentjuicer::Response)}
25
+
25
26
  it { @result.should respond_to(:properties, :paginator) }
26
-
27
+
27
28
  it "should return an array of properties" do
28
29
  @result.properties.should be_kind_of(Array)
29
30
  @result.properties.each do |property|
30
31
  property.should be_kind_of(Rentjuicer::Listing)
31
32
  end
32
33
  end
33
-
34
+
34
35
  it "should return a will_paginate collection" do
35
36
  @result.paginator.should be_kind_of(WillPaginate::Collection)
36
37
  @result.paginator.collect{|p| p.id}.should == @result.properties.collect{|p| p.id}
@@ -47,10 +48,10 @@ describe Rentjuicer::Listing do
47
48
  })
48
49
  @result = @listings.search(:include_mls => "1")
49
50
  end
50
-
51
+
51
52
  context "search response" do
52
53
  it { @result.mls_results?.should be_true }
53
-
54
+
54
55
  it "should return an array of uniq property mls_disclaimers" do
55
56
  @result.mls_disclaimers.should == [
56
57
  "The property listing data and information, or the Images, set forth herein were provided to MLS Property Information Network, Inc. from third party sources, including sellers, lessors and public records, and were compiled by MLS Property Information Network, Inc. The property listing data and information, and the Images, are for the personal, non-commercial use of consumers having a good faith interest in purchasing or leasing listed properties of the type displayed to them and may not be used for any purpose other than to identify prospective properties which such consumers may have a good faith interest in purchasing or leasing. MLS Property Information Network, Inc. and its subscribers disclaim any and all representations and warranties as to the accuracy of the property listing data and information, or as to the accuracy of any of the Images, set forth herein."
@@ -66,21 +67,62 @@ describe Rentjuicer::Listing do
66
67
  })
67
68
  @listing = @listings.find_by_id(200306)
68
69
  end
69
-
70
+
70
71
  it { @listing.should be_kind_of(Rentjuicer::Listing) }
71
72
  end
72
-
73
+
73
74
  context "find_by_id missing" do
74
75
  before do
75
- mock_get('/listings.json', 'no_listings.json', {
76
+ mock_get('/listings.json', 'null_listings.json', {
76
77
  :rentjuice_id => "1"
77
78
  })
78
79
  @listing = @listings.find_by_id(1)
79
80
  end
80
-
81
+
81
82
  it { @listing.should be_nil }
82
83
  end
83
-
84
+
85
+ context "nil listings" do
86
+ context "null listings" do
87
+ before do
88
+ mock_get('/listings.json', 'null_listings.json', {
89
+ :limit => "20",
90
+ :order_by => "rent",
91
+ :order_direction => "asc"
92
+ })
93
+ @results = @listings.search(:limit => 20, :order_by => "rent", :order_direction => "asc")
94
+ end
95
+
96
+ it { @results.properties.should be_empty }
97
+ end
98
+
99
+ context "missing listings" do
100
+ before do
101
+ mock_get('/listings.json', 'missing_listings.json', {
102
+ :limit => "20",
103
+ :order_by => "rent",
104
+ :order_direction => "asc"
105
+ })
106
+ @results = @listings.search(:limit => 20, :order_by => "rent", :order_direction => "asc")
107
+ end
108
+
109
+ it { @results.properties.should be_empty }
110
+ end
111
+
112
+ context "empty response" do
113
+ before do
114
+ mock_get('/listings.json', 'empty_response.json', {
115
+ :limit => "20",
116
+ :order_by => "rent",
117
+ :order_direction => "asc"
118
+ })
119
+ @results = @listings.search(:limit => 20, :order_by => "rent", :order_direction => "asc")
120
+ end
121
+
122
+ it { @results.properties.should be_empty }
123
+ end
124
+ end
125
+
84
126
  context "featured" do
85
127
  before do
86
128
  mock_get('/listings.json', 'featured.json', {
@@ -90,15 +132,16 @@ describe Rentjuicer::Listing do
90
132
  })
91
133
  @result = @listings.featured
92
134
  end
93
-
135
+
94
136
  it { @result.should be_kind_of(Rentjuicer::Listings::SearchResponse) }
137
+
95
138
  it { @result.success?.should be_true }
96
-
139
+
97
140
  it "should only return featured properties" do
98
141
  @result.properties.collect{|p| p.featured == 1}.size.should == @result.properties.size
99
142
  end
100
143
  end
101
-
144
+
102
145
  context "find_all_by_ids" do
103
146
  before do
104
147
  @find_ids = [
@@ -119,14 +162,14 @@ describe Rentjuicer::Listing do
119
162
  })
120
163
  @properties = @listings.find_all_by_ids(@find_ids.join(','))
121
164
  end
122
-
165
+
123
166
  context "passing a string of ids" do
124
167
  before do
125
168
  @properties = @listings.find_all_by_ids(@find_ids.join(','))
126
169
  end
127
-
170
+
128
171
  it { @properties.should be_kind_of(Array) }
129
-
172
+
130
173
  it "should only return properties for requested ids" do
131
174
  @property_ids = @properties.collect{|p| p.rentjuice_id}
132
175
  @find_ids.each do |id|
@@ -134,14 +177,14 @@ describe Rentjuicer::Listing do
134
177
  end
135
178
  end
136
179
  end
137
-
180
+
138
181
  context "passing an array of ids" do
139
182
  before do
140
183
  @properties = @listings.find_all_by_ids(@find_ids)
141
184
  end
142
-
185
+
143
186
  it { @properties.should be_kind_of(Array) }
144
-
187
+
145
188
  it "should only return properties for requested ids" do
146
189
  @property_ids = @properties.collect{|p| p.rentjuice_id}
147
190
  @find_ids.each do |id|
@@ -150,7 +193,7 @@ describe Rentjuicer::Listing do
150
193
  end
151
194
  end
152
195
  end
153
-
196
+
154
197
  context "find_all" do
155
198
  before do
156
199
  search_params = {
@@ -164,9 +207,8 @@ describe Rentjuicer::Listing do
164
207
  mock_get('/listings.json', 'find_all_3.json', mock_parms.merge!(:page => "3"))
165
208
  @properties = @listings.find_all(search_params)
166
209
  end
167
-
210
+
168
211
  it { @properties.should be_kind_of(Array)}
169
-
170
212
  end
171
-
213
+
172
214
  end
File without changes
@@ -0,0 +1,7 @@
1
+ {
2
+ "status": "ok",
3
+ "page": 1,
4
+ "count": 0,
5
+ "total_count": 0,
6
+ "runtime": 0.056
7
+ }
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: 1
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 1
10
- version: 0.7.1
9
+ - 2
10
+ version: 0.7.2
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-10-30 00:00:00 -04:00
18
+ date: 2012-01-27 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -159,6 +159,7 @@ files:
159
159
  - spec/rentjuicer/neighborhoods_spec.rb
160
160
  - spec/rentjuicer/response_spec.rb
161
161
  - spec/rentjuicer_api_key.yml.example
162
+ - spec/responses/empty_response.json
162
163
  - spec/responses/error.json
163
164
  - spec/responses/featured.json
164
165
  - spec/responses/find_all_1.json
@@ -170,9 +171,10 @@ files:
170
171
  - spec/responses/lead.json
171
172
  - spec/responses/lead_error.json
172
173
  - spec/responses/listings.json
174
+ - spec/responses/missing_listings.json
173
175
  - spec/responses/mls_listings.json
174
176
  - spec/responses/neighborhoods.json
175
- - spec/responses/no_listings.json
177
+ - spec/responses/null_listings.json
176
178
  - spec/spec_helper.rb
177
179
  - spec/support/listing_helper.rb
178
180
  - spec/support/webmock_helper.rb