Skip to content

Instantly share code, notes, and snippets.

@iduuck
Created May 7, 2016 21:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iduuck/48887a69e31fa41d58ffcfc9be1a2f47 to your computer and use it in GitHub Desktop.
Save iduuck/48887a69e31fa41d58ffcfc9be1a2f47 to your computer and use it in GitHub Desktop.
How to reject a post based on some attributes
# We are using the default ruby http client for the request to the
# shortened url, because otherwise a Gemfile or something different
# would be necessary
require 'net/http'
# I am using an example url from webdesignshare.com (with url shortener)
uri = URI('http://url.tusiad.org/make-people-stay-website')
res = Net::HTTP.get_response(uri)
# Here you could also countercheck a blacklist array or something
# Just check for the domain name, because otherwise wds will change to https
if res.code === '301' && res.read_header['Location'].include?('webdesignshare.com') {
# Reject or do something different
@post.reject!
} else {
# Accept the posting here posting
@post.accept!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment