lib/rentjuicer/listings.rb in rentjuicer-0.2.1 vs lib/rentjuicer/listings.rb in rentjuicer-0.3.0
- old
+ new
@@ -6,14 +6,10 @@
def initialize(client)
self.client = client
self.resource = "/listings.json"
end
- def find_by_id(listing_id)
- SearchResponse.new(self.client.class.get(resource, :query => {:rentjuice_id => listing_id}))
- end
-
def search(params = {})
limit = params[:limit] || 20
params[:order_by] ||= "rent"
params[:order_direction] ||= "asc"
SearchResponse.new(self.client.class.get(resource, :query => params), limit)
@@ -22,10 +18,15 @@
def featured(params = {})
params.merge!(:featured => 1)
search(params)
end
+ def find_by_id(listing_id)
+ response = SearchResponse.new(self.client.class.get(resource, :query => {:rentjuice_id => listing_id}))
+ (response.success? && response.properties.size > 0) ? response.properties.first : nil
+ end
+
def find_all(params = {})
per_page = params[:limit] || 20
all_listings = []
response = search(params)
@@ -61,23 +62,23 @@
super(response)
@limit = limit
end
def properties
- return [] if @body.listings.blank?
+ return [] if self.body.listings.blank?
props = []
- @body.listings.each do |listing|
+ self.body.listings.each do |listing|
props << Rentjuicer::Listing.new(listing)
end
props
end
def paginator
paginator_cache if paginator_cache
self.paginator_cache = WillPaginate::Collection.create(
- @body.page,
+ self.body.page,
@limit,
- (@body.total_count ? @body.total_count : properties.size)) do |pager|
+ (self.body.total_count ? self.body.total_count : properties.size)) do |pager|
pager.replace properties
end
end
end