class StreetEasy::Property

Constants

OPTIONS

Public Class Methods

all() click to toggle source
# File lib/street_easy/property.rb, line 90
def all
  @limit = 200 # the api limit
  generate_properties
end
limit(limit) click to toggle source
# File lib/street_easy/property.rb, line 85
def limit(limit)
  @limit = limit
  generate_properties
end
neighborhoods(*neighborhood) click to toggle source
# File lib/street_easy/property.rb, line 55
def neighborhoods(*neighborhood)
  @neighborhoods = neighborhood.join(',') if neighborhood.kind_of?(Array)
  @neighborhoods = neighborhood           if neighborhood.kind_of?(String)
  self
end
options(*options) click to toggle source
# File lib/street_easy/property.rb, line 71
def options(*options)
  @options = options.kind_of?(Array) ? options.flatten : options
  self
end
order(sort_type) click to toggle source
# File lib/street_easy/property.rb, line 76
def order(sort_type)
  case sort_type
    when :most_expensive  then @sort_type = "price_desc"
    when :least_expensive then @sort_type = "price_asc"
    when :newest          then @sort_type = "listed_desc"
  end
  self
end
rentals() click to toggle source
# File lib/street_easy/property.rb, line 61
def rentals
  @property_type = 'rentals'
  self
end
sales() click to toggle source
# File lib/street_easy/property.rb, line 66
def sales
  @property_type = 'sales'
  self
end

Private Class Methods

generate_properties() click to toggle source
# File lib/street_easy/property.rb, line 97
def generate_properties
  parsed_reply = get_parsed_reply
  properties = []

  (1...@limit).each do |i|
    break if parsed_reply['listings'][i].nil?
    rental = {}

    OPTIONS.each do |option|
      rental[option] = parsed_reply['listings'][i][option.to_s] if @options.include?(option)
    end

    properties << rental
  end

  properties
end
get_parsed_reply() click to toggle source
# File lib/street_easy/property.rb, line 115
def get_parsed_reply
  uri = StreetEasy::Client.construct_url({
    property_type: @property_type,
    neighborhoods: @neighborhoods,
    limit: @limit,
    order: @sort_type
  })

  reply = uri.read
  parsed_reply = JSON.parse(reply)
end