Sha256: 3abcc8bd6597d6286c195b88972aca6fa3e55f2e73124717bc5a69a6f8781c87

Contents?: true

Size: 805 Bytes

Versions: 1

Compression:

Stored size: 805 Bytes

Contents

module Ahoy
  class GeocodeV2Job < ActiveJob::Base
    queue_as { Ahoy.job_queue }

    def perform(visit_token, ip)
      location =
        begin
          Geocoder.search(ip).first
        rescue => e
          Rails.logger.warn "[ahoy] Geocode error: #{e.class.name}: #{e.message}"
          nil
        end

      if location
        data = {
          visit_token: visit_token,
          country: location.try(:country).presence,
          region: location.try(:state).presence,
          city: location.try(:city).presence,
          postal_code: location.try(:postal_code).presence,
          latitude: location.try(:latitude).presence,
          longitude: location.try(:longitude).presence
        }

        Ahoy::Tracker.new(visit_token: visit_token).geocode(data)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ahoy_matey-2.0.1 app/jobs/ahoy/geocode_v2_job.rb