Last active
October 3, 2015 09:50
-
-
Save RyanHarijanto/4d4008f5994177cdc05a to your computer and use it in GitHub Desktop.
BlockThem Ruby Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'net/http' | |
require 'uri' | |
require 'json' | |
def isDomainBlockedLive(domain, jsonFile) | |
domain = domain.sub(/http(s?):\/\//, '').sub(/^www\./, '').sub(/\/$/, '') | |
list = JSON.parse(Net::HTTP.get(URI.parse(jsonFile))) | |
return list.include? domain | |
end | |
def isDomainBlockedCached(domain, jsonFile) | |
domain = domain.sub(/http(s?):\/\//, '').sub(/^www\./, '').sub(/\/$/, '') | |
list = JSON.parse(IO.read(jsonFile)) | |
return list.include? domain | |
end | |
# Example: Live | |
# Output: false | |
puts isDomainBlockedLive('gmail.com', 'http://api.blockthem.io/v1/blacklist.json') | |
# Example: Cached | |
# Output: true | |
puts isDomainBlockedCached('mailinator.com', 'blacklist.json') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment