Skip to content

Instantly share code, notes, and snippets.

@tcocca
Forked from DemitryT/walkscore.rb
Created January 5, 2012 15:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcocca/1565782 to your computer and use it in GitHub Desktop.
Save tcocca/1565782 to your computer and use it in GitHub Desktop.
walkscore.rb
require 'httparty'
class Walkscore
include HTTParty
default_params :format => 'json'
attr_accessor :api_key, :property
def initialize(api_key, property)
self.api_key = api_key
self.property = property
self.class.default_params.merge(:wsapikey => api_key)
end
def walk_score
self.class.get('http://api.walkscore.com/score', :query => {
:address => address,
:lat => property.latitude,
:lon => property.longitude
})
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