lib/mihari/models/geolocation.rb in mihari-3.6.1 vs lib/mihari/models/geolocation.rb in mihari-3.7.0
- old
+ new
@@ -1,9 +1,29 @@
# frozen_string_literal: true
require "active_record"
+require "normalize_country"
module Mihari
class Geolocation < ActiveRecord::Base
- has_one :artifact, dependent: :destroy
+ belongs_to :artifact
+
+ class << self
+ #
+ # Build Geolocation
+ #
+ # @param [String] ip
+ #
+ # @return [Mihari::Geolocation, nil]
+ #
+ def build_by_ip(ip)
+ res = Enrichers::IPInfo.query(ip)
+
+ unless res.nil?
+ return new(country: NormalizeCountry(res.country_code, to: :short), country_code: res.country_code)
+ end
+
+ nil
+ end
+ end
end
end