ip addresses: move more logic to Danbooru::IpAddress.
* Move `is_local?` from IpLookup to Danbooru::IpAddress. * Refactor more things to use Danbooru::IpAddress instead of using IPAddress directly.
This commit is contained in:
@@ -10,12 +10,13 @@ class IpLookup
|
||||
end
|
||||
|
||||
def initialize(ip_addr, api_key: Danbooru.config.ip_registry_api_key, cache_duration: 3.days)
|
||||
@ip_addr = IPAddress.parse(ip_addr.to_s)
|
||||
@ip_addr = Danbooru::IpAddress.new(ip_addr)
|
||||
@api_key = api_key
|
||||
@cache_duration = cache_duration
|
||||
end
|
||||
|
||||
def ip_info
|
||||
return {} if ip_addr.is_local?
|
||||
return {} if response.blank?
|
||||
|
||||
{
|
||||
@@ -43,14 +44,6 @@ class IpLookup
|
||||
json
|
||||
end
|
||||
|
||||
def is_local?
|
||||
if ip_addr.ipv4?
|
||||
ip_addr.loopback? || ip_addr.link_local? || ip_addr.private?
|
||||
elsif ip_addr.ipv6?
|
||||
ip_addr.loopback? || ip_addr.link_local? || ip_addr.unique_local?
|
||||
end
|
||||
end
|
||||
|
||||
def is_proxy?
|
||||
response[:security].present? && response[:security].values.any?
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user