Skip to content

Instantly share code, notes, and snippets.

@azuby
Created February 24, 2012 00:20
Show Gist options
  • Save azuby/1896047 to your computer and use it in GitHub Desktop.
Save azuby/1896047 to your computer and use it in GitHub Desktop.
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