Skip to content

Instantly share code, notes, and snippets.

@installero
Last active August 10, 2022 15:20
Show Gist options
  • Save installero/44df53efc851036174c2aaebb9bc46e5 to your computer and use it in GitHub Desktop.
Save installero/44df53efc851036174c2aaebb9bc46e5 to your computer and use it in GitHub Desktop.
Stop Forum Spam username, ip, email check on Ruby
# https://www.stopforumspam.com/usage
# require 'byebug'
require 'httparty'
url = 'http://api.stopforumspam.org/api';
username, email, ip = ARGV[0..2]
data = {username: [username], email: email, ip: ip}
response = HTTParty.post(url, query: data, format: :xml)
check_results_hash = response['response']
# {
# username: {appears: false},
# email: {appears: true, frequency: 321, last_seen_at: '2022-07-18 16:44:41'},
# ip: {appears: true, frequency: 2875, last_seen_at: '2022-08-02 23:02:01'}
# }
result = {}
last_seen_index_offset = 0
check_results_hash['type'].each.with_index do |field_name, index|
appears = check_results_hash['appears'][index] == 'yes'
result[field_name] = {appears: appears}
unless appears
last_seen_index_offset -= 1
next
end
result[field_name].merge!({
frequency: check_results_hash['frequency'][index],
last_seen_at: check_results_hash['lastseen'][index + last_seen_index_offset]
})
end
puts result.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment