Created
February 24, 2012 00:20
-
-
Save azuby/1896047 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def location | |
# return nil if !subscribed? | |
if last_location && (Time.now - last_location.created_at) < 5.minutes | |
return locations.create!( latitude: last_location.latitude, longitude: last_location.longitude, radius: last_location.radius ) | |
end | |
locate | |
end | |
def locate | |
client = Savon::Client.new(CONFIG['locator_wsdl']) | |
response = client.request(CONFIG['locator_params']) | |
if response.success? && response.to_array(:location_response, :status).first == "FOUND" | |
lat = response.to_array(:location_response, :coordinate_geo, :y).first | |
long = response.to_array(:location_response, :coordinate_geo, :x).first | |
rad = response.to_array(:location_response, :geometry, :radius).first | |
return locations.create!( response: response.inspect, latitude: lat, longitude: long, radius: rad ) | |
end | |
raise APIError, "A problem was encountered with the API response: #{response.inspect}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment