Class: AuthTrail::GeocodeJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/auth_trail/geocode_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(login_activity) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/jobs/auth_trail/geocode_job.rb', line 3

def perform()
  result =
    begin
      Geocoder.search(.ip).first
    rescue => e
      Rails.logger.info "Geocode failed: #{e.message}"
      nil
    end

  if result
    attributes = {
      city: result.try(:city),
      region: result.try(:state),
      country: result.try(:country),
      latitude: result.try(:latitude),
      longitude: result.try(:longitude)
    }
    attributes.each do |k, v|
      .try("#{k}=", v.presence)
    end
    .save!
  end
end