ruby-stopforumspam 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +20 -0
  3. data/README.md +63 -0
  4. data/lib/stopforumspam.rb +58 -0
  5. metadata +61 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 46238cf4be69c6e2b4e4baec594c51bfe6ff85c0
4
+ data.tar.gz: 7970d43bc00bc301a050c160d7d6033fbdab381f
5
+ SHA512:
6
+ metadata.gz: e5b42f9b9f6c0d2846330cdc15f04be3d4c0b13879af8667cf97f5782e550fb5774210e2e80edf2a421c9579e002e747361b018e2f19c51ac4d87a0976a97e3e
7
+ data.tar.gz: ba5200ffab33f34bcddd76b2138441ef96bb4ea2c1c507d53c1c9f0aeaf3bc9eec429854ba1dfb5978aa1fc734ece01c5d4da39d45cd9dd68a6831a62890ae18
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (C) 2015 Warren Guy <warren@guy.net.au>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # ruby-stopforumspam
2
+
3
+ Ruby wrapper for stopforumspam.com API. Check IP addresses, email addresses,
4
+ and usernames for known spam activity.
5
+
6
+ ## Usage
7
+
8
+ Add the gem to your Gemfile:
9
+
10
+ ```ruby
11
+ gem 'ruby-stopforumspam'
12
+ ```
13
+
14
+ Then in your project:
15
+
16
+ ```ruby
17
+ require 'stopforumspam'
18
+
19
+ spam_check = StopForumSpam::Check.new(parameters)
20
+ spam.check.spammer? # returns Boolean
21
+ spam.check.result # returns Hash
22
+ ```
23
+
24
+ Supply a String to check one IP address, e-mail, or username:
25
+
26
+ ```ruby
27
+ spam_check = StopForumSpam::Check.new('198.51.100.1')
28
+ spam_check.spammer? # is this person a spammer?
29
+ => false
30
+ spam_check.result # see full results from API
31
+ => {"ip"=>{"value"=>"198.51.100.1", "frequency"=>"0", "appears"=>"0"}}
32
+ ```
33
+
34
+ Or supply an Array of Strings:
35
+
36
+ ```ruby
37
+ spam_check = StopForumSpam::Check.new(['198.51.100.1', 'test@example.com'])
38
+ spam_check.spammer?
39
+ => true
40
+ spam_check.result
41
+ => {"ip"=>{"value"=>"198.51.100.1", "frequency"=>"0", "appears"=>"0"}, "email"=>{"value"=>"test@example.com", "lastseen"=>"2014-10-06 13:33:08", "frequency"=>"3", "appears"=>"1"}}
42
+ ```
43
+
44
+ Or supply an Array of Hashes to override the check type (e.g. to force a
45
+ username check for a string that looks like an IP address):
46
+
47
+ ```ruby
48
+ spam_check = StopForumSpam::Check.new([{check: '198.51.100.1', type: 'username'}])
49
+ spam_check.spammer?
50
+ => true
51
+ spam_check.result
52
+ => {"username"=>{"value"=>"198.51.100.1", "frequency"=>"0", "appears"=>"0"}}
53
+ ```
54
+
55
+ ## License
56
+
57
+ MIT license. See LICENSE.
58
+
59
+ ## Author
60
+
61
+ Warren Guy <warren@guy.net.au>
62
+
63
+ https://warrenguy.me
@@ -0,0 +1,58 @@
1
+ require 'ipaddr'
2
+ require 'xmlsimple'
3
+ require 'open-uri'
4
+
5
+ module StopForumSpam
6
+ class Check
7
+ def initialize(checks = [])
8
+ @checks = parse_checks([*checks])
9
+ end
10
+
11
+ def result
12
+ @result ||= do_check
13
+ end
14
+
15
+ def spammer?
16
+ result.map{|type, checks| checks}.flatten.map{|check| check['appears']}.include? '1'
17
+ end
18
+
19
+ private
20
+
21
+ def do_check
22
+ response = XmlSimple.xml_in(
23
+ open(
24
+ 'http://api.stopforumspam.org/api?' +
25
+ @checks.map{|check| "#{check[:type]}[]=#{check[:check]}"}.join('&')
26
+ ),
27
+ { 'ForceArray' => false }
28
+ )
29
+
30
+ raise "Unsuccesful response from API" unless response['success'] && (response.delete('success') == '1')
31
+
32
+ return response
33
+ end
34
+
35
+ def parse_checks(checks)
36
+ return checks.map{|check|
37
+ case check.class.to_s
38
+ when 'String'
39
+ {check: check, type: check_type(check)}
40
+ when 'Hash'
41
+ {check: check[:check], type: (check[:type] || check_type(check[:check]))}
42
+ end
43
+ }
44
+ end
45
+
46
+ def check_type(check)
47
+ return 'email' if check =~ /.*@.*/
48
+
49
+ begin
50
+ check_ip = IPAddr.new(check)
51
+ return 'ip' if check_ip.ipv4? or check_ip.ipv6?
52
+ rescue IPAddr::InvalidAddressError
53
+ end
54
+
55
+ return 'username'
56
+ end
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-stopforumspam
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Warren Guy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: xml-simple
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Ruby wrapper for stopforumspam.com API. Check IP addresses, email addresses,
28
+ and usernames for known spam activity.
29
+ email: warren@guy.net.au
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README.md
36
+ - lib/stopforumspam.rb
37
+ homepage: https://github.com/warrenguy/ruby-stopforumspam
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.2.2
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Ruby wrapper for stopforumspam.com API.
61
+ test_files: []