Created
January 4, 2012 22:10
-
-
Save DemitryT/1562450 to your computer and use it in GitHub Desktop.
walkscore.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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