mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 01:01:39 -05:00
31 lines
729 B
Ruby
31 lines
729 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ReverseGeocoding::Points::FetchData
|
|
attr_reader :point
|
|
|
|
def initialize(point_id)
|
|
@point = Point.find(point_id)
|
|
rescue ActiveRecord::RecordNotFound => e
|
|
Rails.logger.error("Point with id #{point_id} not found: #{e.message}")
|
|
end
|
|
|
|
def call
|
|
return if point.reverse_geocoded?
|
|
|
|
update_point_with_geocoding_data
|
|
end
|
|
|
|
private
|
|
|
|
def update_point_with_geocoding_data
|
|
response = Geocoder.search([point.latitude, point.longitude]).first
|
|
return if response.blank? || response.data['error'].present?
|
|
|
|
point.update!(
|
|
city: response.city,
|
|
country: response.country,
|
|
geodata: response.data,
|
|
reverse_geocoded_at: Time.current
|
|
)
|
|
end
|
|
end
|