module PwnedCheck
PwnedCheck
module
Public Class Methods
check(item)
click to toggle source
Check an address against haveibeenpwned.com
@param item [String] the item to check. Could be an email address, phone number, or username @return [Array] an array of sites that the email address is associated with
# File lib/pwnedcheck.rb, line 48 def self.check(item) begin uri = URI.parse "https://haveibeenpwned.com/api/v2/breachedaccount/#{CGI::escape(item)}" response = Net::HTTP.get_response uri case response.code when '200' JSON.parse response.body when '404' [] when '400' fail InvalidEmail when '429' raise RequestThrottled.new response.header['Retry-After'] end rescue RequestThrottled => err sleep err.timeout retry end end
check_pastes(item)
click to toggle source
Check an address for pastes against haveibeenpwned.com
@param item [String] the item to check. Could be an email address, phone number, or username @return [Array] an array of pastes that the email address is associated with
# File lib/pwnedcheck.rb, line 72 def self.check_pastes(item) begin uri = URI.parse "https://haveibeenpwned.com/api/v2/pasteaccount/#{CGI::escape(item)}" response = Net::HTTP.get_response uri case response.code when '200' JSON.parse response.body when '404' [] when '400' fail InvalidEmail when '429' raise RequestThrottled.new response.header['Retry-After'] end rescue RequestThrottled => err sleep err.timeout retry end end