Whoops - no BookoAgent
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
class Ipapi
|
class Ipapi
|
||||||
include BookoAgent
|
include HTTParty
|
||||||
BASE_URL = "https://api.ipapi.is/"
|
BASE_URL = "https://api.ipapi.is/"
|
||||||
API_KEY = Rails.application.credentials.ipapi_key
|
API_KEY = Rails.application.credentials.ipapi_key
|
||||||
|
|
||||||
def lookup(ip) = json_at("#{BASE_URL}?q=#{ip}&key=#{API_KEY}")
|
def lookup(ip)
|
||||||
|
response = self.class.get("#{BASE_URL}", query: { q: ip, key: API_KEY })
|
||||||
|
response.parsed_response
|
||||||
|
end
|
||||||
|
|
||||||
def self.lookup(ip) = new.lookup(ip)
|
def self.lookup(ip) = new.lookup(ip)
|
||||||
|
|
||||||
@@ -13,22 +16,24 @@ class Ipapi
|
|||||||
end
|
end
|
||||||
|
|
||||||
def data(ip)
|
def data(ip)
|
||||||
uri = URI.parse(BASE_URL)
|
|
||||||
|
|
||||||
if ip.is_a?(Array)
|
if ip.is_a?(Array)
|
||||||
post_data(ip)
|
post_data(ip)
|
||||||
else
|
else
|
||||||
uri.query = "q=#{ip}"
|
response = self.class.get("#{BASE_URL}", query: { q: ip, key: API_KEY })
|
||||||
JSON.parse(http.request(uri).body)
|
response.parsed_response
|
||||||
end
|
end
|
||||||
rescue JSON::ParserError
|
rescue JSON::ParserError
|
||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
|
|
||||||
def post_data(ips)
|
def post_data(ips)
|
||||||
url = URI.parse(BASE_URL + "?key=#{API_KEY}")
|
response = self.class.post("#{BASE_URL}",
|
||||||
|
query: { key: API_KEY },
|
||||||
|
body: { ips: ips }.to_json,
|
||||||
|
headers: { 'Content-Type' => 'application/json' }
|
||||||
|
)
|
||||||
|
|
||||||
results = post_json(url, body: ips)
|
results = response.parsed_response
|
||||||
|
|
||||||
results["response"].map do |ip, data|
|
results["response"].map do |ip, data|
|
||||||
IPAddr.new(ip)
|
IPAddr.new(ip)
|
||||||
|
|||||||
Reference in New Issue
Block a user