Sha256: 5a971d339de04c23eee85ca6f7eaa1cf87373d2e7e0aaaaa48ae4c7f0e17abb5

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

module Trulia4r
  class LocationInfo
    
    attr_accessor :client, :default_params
    
    def initialize(client)
      @client = client
      @default_params = @client.class.default_params.merge({:library => 'LocationInfo'})
    end
    
    def get_cities_in_state(state)
      options = {:function => 'getCitiesInState', :state => state}
      process(options, 'city')
    end
    
    def get_counties_in_state(state)
      options = {:function => 'getCountiesInState', :state => state}
      process(options, 'county')
    end
    
    def get_neighborhoods_in_city(city, state)
      options = {:function => 'getNeighborhoodsInCity', :city => city, :state => state}
      process(options, 'neighborhood')
    end
    
    def get_states
      options = {:function => 'getStates'}
      process(options, 'state')
    end
    
    def get_zip_codes_in_state(state)
      options = {:function => 'getZipCodesInState', :state => state}
      process(options, 'zipCode')
    end
    
    private
    
    def process(options, body_hash)
      Response.new(@client.class.get(@client.api_page, :query => options.merge(@default_params)), body_hash)
    end
    
    class Response
      attr_accessor :body, :body_hash
      
      def initialize(body, body_hash)
        @body = body
        @body_hash = body_hash
      end
      
      def data
        @body['TruliaWebServices']['response']['LocationInfo'][@body_hash]
      end
      
      def error
        @body['TruliaWebServices']['response']['LocationInfo']['error']
      end
      
      def success?
        error.blank? && !data.blank?
      end
      
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tcocca-trulia4r-1.0.1 lib/trulia4r/location_info.rb