Skip to content

Instantly share code, notes, and snippets.

@RyanHarijanto
Last active October 3, 2015 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyanHarijanto/4d4008f5994177cdc05a to your computer and use it in GitHub Desktop.
Save RyanHarijanto/4d4008f5994177cdc05a to your computer and use it in GitHub Desktop.
BlockThem Ruby Example
#!/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