feat(poc): Disable widget based on country (#6658)

This commit is contained in:
Pranav Raj S
2023-03-14 09:09:57 -07:00
committed by GitHub
parent e8a174f689
commit eb7070d946
8 changed files with 72 additions and 53 deletions

33
lib/tasks/ip_lookup.rake Normal file
View File

@@ -0,0 +1,33 @@
require 'rubygems/package'
namespace :ip_lookup do
task setup: :environment do
next if File.exist?(GeocoderConfiguration::LOOK_UP_DB)
ip_lookup_api_key = ENV.fetch('IP_LOOKUP_API_KEY')
next if ip_lookup_api_key.blank?
puts '[rake ip_lookup:setup] Fetch GeoLite2-City database'
begin
base_url = 'https://download.maxmind.com/app/geoip_download'
source_file = Down.download(
"#{base_url}?edition_id=GeoLite2-City&suffix=tar.gz&license_key=#{ip_lookup_api_key}"
)
tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(source_file))
tar_extract.rewind
tar_extract.each do |entry|
next unless entry.full_name.include?('GeoLite2-City.mmdb') && entry.file?
File.open GeocoderConfiguration::LOOK_UP_DB, 'wb' do |f|
f.print entry.read
end
end
puts '[rake ip_lookup:setup] Fetch complete'
rescue StandardError => e
puts "[rake ip_lookup:setup] #{e.message}"
end
end
end