Sha256: f6ff7f6bd8847ef29bd18af403760bdb8c4fd9d7a6557ecd863b65db1f28006e

Contents?: true

Size: 926 Bytes

Versions: 13

Compression:

Stored size: 926 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 NameError
          raise "Add the geocoder gem to your Gemfile to use geocoding"
        rescue => e
          Ahoy.log "Geocode error: #{e.class.name}: #{e.message}"
          nil
        end

      if location && location.country.present?
        data = {
          country: location.country,
          country_code: location.try(:country_code).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

13 entries across 13 versions & 1 rubygems

Version Path
ahoy_matey-5.2.1 lib/ahoy/geocode_v2_job.rb
ahoy_matey-5.2.0 lib/ahoy/geocode_v2_job.rb
ahoy_matey-5.1.0 lib/ahoy/geocode_v2_job.rb
ahoy_matey-5.0.2 lib/ahoy/geocode_v2_job.rb
ahoy_matey-5.0.1 lib/ahoy/geocode_v2_job.rb
ahoy_matey-5.0.0 lib/ahoy/geocode_v2_job.rb
ahoy_matey-4.2.1 app/jobs/ahoy/geocode_v2_job.rb
ahoy_matey-4.2.0 app/jobs/ahoy/geocode_v2_job.rb
ahoy_matey-4.1.0 app/jobs/ahoy/geocode_v2_job.rb
ahoy_matey-4.0.3 app/jobs/ahoy/geocode_v2_job.rb
ahoy_matey-4.0.2 app/jobs/ahoy/geocode_v2_job.rb
ahoy_matey-4.0.1 app/jobs/ahoy/geocode_v2_job.rb
ahoy_matey-4.0.0 app/jobs/ahoy/geocode_v2_job.rb