Skip to content

Instantly share code, notes, and snippets.

@DemitryT
Created January 4, 2012 22:10
Show Gist options
  • Save DemitryT/1562450 to your computer and use it in GitHub Desktop.
Save DemitryT/1562450 to your computer and use it in GitHub Desktop.
walkscore.rb
require 'httparty'
class Walkscore
include HTTParty
attr_accessor :api_key, :property
def initialize(api_key, property)
self.api_key = api_key
self.property = property
self.class.default_params :wsapikey => api_key
end
def walk_score
self.class.get('http://api.walkscore.com/score', :query => {
:address => address,
:lat => property.latitude,
:lon => property.longitude,
:format => 'json'
})
end
def transit_score
self.class.get('http://transit.walkscore.com/transit/score/', :query => {
:lat => property.latitude,
:lon => property.longitude,
:city => city,
:state => state
})
end
private
def address
if self.property.is_a?(Mls::Property)
property.complete_address
else
property.full_address
end
end
def city
if self.property.is_a?(Mls::Property)
property.town.try(:name)
else
property.city
end
end
def state
if self.property.is_a?(Mls::Property)
property.state.try(:abbreviation)
else
property.state
end
end
end
#@property = Mls::Property.find(:first)
#walkscore = Walkscore.new('f3e8d1f3835e607eb14f91cd7f0b53f2', @property)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment