lib/mihari/models/geolocation.rb in mihari-6.3.0 vs lib/mihari/models/geolocation.rb in mihari-7.0.0
- old
+ new
@@ -9,29 +9,24 @@
#
class Geolocation < ActiveRecord::Base
belongs_to :artifact
class << self
- include Dry::Monads[:result]
-
#
# Build Geolocation
#
# @param [String] ip
- # @param [Mihari::Enrichers::IPinfo] enricher
+ # @param [Mihari::Enrichers::MMDB] enricher
#
# @return [Mihari::Geolocation, nil]
#
- def build_by_ip(ip, enricher: Enrichers::IPInfo.new)
- result = enricher.result(ip).bind do |res|
- value = res&.country_code
- if value.nil?
- Success nil
- else
- Success new(country: NormalizeCountry(value, to: :short), country_code: value)
+ def build_by_ip(ip, enricher: Enrichers::MMDB.new)
+ enricher.result(ip).fmap do |res|
+ if res.country_code
+ new(country: NormalizeCountry(res.country_code, to: :short),
+ country_code: res.country_code)
end
- end
- result.value_or nil
+ end.value_or nil
end
end
end
end
end