Skip to content

Commit

Permalink
Merge pull request #1 from jvanderhoof/master
Browse files Browse the repository at this point in the history
Single Picture & YGL hard limit fixes
  • Loading branch information
tcocca committed Dec 6, 2011
2 parents 1568db5 + 3821751 commit 0ffec41
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/you_got_listed.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'rash' require 'rash'
require 'will_paginate/collection' require 'will_paginate/collection'
require 'active_support/core_ext/array/grouping' require 'active_support/core_ext/array/grouping'
require 'active_support/core_ext/object/blank'


require 'you_got_listed/client' require 'you_got_listed/client'
require 'you_got_listed/resource' require 'you_got_listed/resource'
Expand Down
2 changes: 1 addition & 1 deletion lib/you_got_listed/listing.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def city_neighborhood
end end


def pictures def pictures
self.photos.photo unless self.photos.blank? || self.photos.photo.blank? (self.photos.photo.is_a?(Array) ? self.photos.photo : [self.photos.photo]) unless self.photos.blank? || self.photos.photo.blank?
end end


def main_picture def main_picture
Expand Down
4 changes: 2 additions & 2 deletions lib/you_got_listed/listings.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ def find_all_by_ids(listing_ids, include_off_market = true)
if listing_ids.any?{|list_id| list_id !=~ /[A-Z]{3}-[0-9]{3}-[0-9]{3}/} if listing_ids.any?{|list_id| list_id !=~ /[A-Z]{3}-[0-9]{3}-[0-9]{3}/}
search_params[:include_mls] = 1 search_params[:include_mls] = 1
end end
listing_ids.in_groups_of(500, false).each_with_index do |group, index| # YGL no longer allows you to pass page_count > 10, so we're stuck paging
listing_ids.in_groups_of(10, false).each_with_index do |group, index|
group.delete_if{|x| x.nil?} group.delete_if{|x| x.nil?}
search_params[:listing_ids] = group.join(',') search_params[:listing_ids] = group.join(',')
search_params[:page_count] = 500
search_params[:page_index] = index + 1 search_params[:page_index] = index + 1
all_listings << find_all(search_params) all_listings << find_all(search_params)
end end
Expand Down
8 changes: 8 additions & 0 deletions spec/you_got_listed/listing_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@
@listing.stub!(:pictures).and_return(nil) @listing.stub!(:pictures).and_return(nil)
@listing.main_picture.should be_nil @listing.main_picture.should be_nil
end end

it "should return an array if the property has only one photo" do
rash = valid_listing_rash
rash[:photos].merge!(:photo => 'http://ygl-photos.s3.amazonaws.com/1236380.jpg')
@listing = YouGotListed::Listing.new(rash, @ygl)
@listing.pictures.is_a?(Array).should be_true
@listing.main_picture.should == 'http://ygl-photos.s3.amazonaws.com/1236380.jpg'
end
end end


context "latitude" do context "latitude" do
Expand Down

0 comments on commit 0ffec41

Please sign in to comment.