Whoops - no BookoAgent
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
class Ipapi
|
||||
include BookoAgent
|
||||
include HTTParty
|
||||
BASE_URL = "https://api.ipapi.is/"
|
||||
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)
|
||||
|
||||
@@ -13,22 +16,24 @@ class Ipapi
|
||||
end
|
||||
|
||||
def data(ip)
|
||||
uri = URI.parse(BASE_URL)
|
||||
|
||||
if ip.is_a?(Array)
|
||||
post_data(ip)
|
||||
else
|
||||
uri.query = "q=#{ip}"
|
||||
JSON.parse(http.request(uri).body)
|
||||
response = self.class.get("#{BASE_URL}", query: { q: ip, key: API_KEY })
|
||||
response.parsed_response
|
||||
end
|
||||
rescue JSON::ParserError
|
||||
{}
|
||||
end
|
||||
|
||||
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|
|
||||
IPAddr.new(ip)
|
||||
|
||||
Reference in New Issue
Block a user