stoolie 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ca19f561e69ea9b59e6f99a52eac6c83060df20d
4
- data.tar.gz: 37f3c585bd23ab5c67a3c3375978fe74bfb31827
3
+ metadata.gz: b08dfb182be3bffe1d92f2d467324d00230d7d1c
4
+ data.tar.gz: 622872b0bb0ca414c4fb6757761781a7a706634d
5
5
  SHA512:
6
- metadata.gz: bef278518cb9933be6b5b145f0a4f0be41e9d7da55d329bdb04cb5742ad5fc1082fb272bbd427ae6f9282c8ce2316da374b46a4aec0b3a94bc4a09912f99dcc2
7
- data.tar.gz: 2557aa46e4a39bde6736362f042d44e6bdb4e47958e3094ce320be1748e1a23699fcf7a42e633a17dbcfdef5bc351fcf47dc58b084b1ee09a6315397b2604409
6
+ metadata.gz: 6c111411770de04086328bc58551176c5fa8c52722461b96e631128fffa88e10af85c7fa2fcdfc1dc895602771ffe1bac600182f5e3918603c32e7d85e8db54f
7
+ data.tar.gz: 11f58c2850469b8fcd5f02786ee26a4e1bb2b1eb0fe5c014d1289429565046d4add0fbaa23e258d685c0b97d81b2272dbc3db995dfdecf5130e729d652122371
data/README.md CHANGED
@@ -10,7 +10,7 @@ The easiest way to install is with [Bundler](http://gembundler.com)
10
10
  gem 'stoolie'
11
11
  ```
12
12
 
13
- Stoolie will work on Ruby 1.8.7+
13
+ Stoolie will work on Ruby 1.8.7+, however the development gems (such as rspec) will only work on 1.9.3+.
14
14
 
15
15
  ## Configuration
16
16
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -1,5 +1,5 @@
1
1
  module Stoolie
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
 
4
4
  class << self
5
5
  attr_accessor :config
@@ -0,0 +1,100 @@
1
+ # © Prevoty SmartFilter
2
+ # https://github.com/smartfiltersecurity/smartfilter-ruby
3
+
4
+ require 'rubygems'
5
+ require 'httparty'
6
+ require 'json'
7
+
8
+ class SmartFilterNetworkException < Exception; end
9
+ class SmartFilterBadInputParameter < Exception; end
10
+ class SmartFilterBadAPIKey < Exception; end
11
+ class SmartFilterRequestTooLarge < Exception; end
12
+ class SmartFilterInternalError < Exception; end
13
+ class SmartFilterAccountQuotaExceeded < Exception; end
14
+
15
+ class PrevotySmartFilter
16
+ attr_accessor :key, :base
17
+
18
+ def initialize(key)
19
+ @key = key
20
+ @base = 'https://api.prevoty.com/1'
21
+ end
22
+
23
+ # Endpoint: /key/verify
24
+ def verify
25
+ begin
26
+ return verify!
27
+ rescue => e
28
+ return nil
29
+ end
30
+ end
31
+
32
+ def verify!
33
+ options = {:api_key => @key}
34
+ response = HTTParty.get("#{@base}/key/verify", :query => options)
35
+ return true if response.code == 200
36
+ raise SmartFilterBadInputParameter.new if response.code == 400
37
+ raise SmartFilterBadAPIKey.new if response.code == 403
38
+ raise SmartFilterInternalError.new if response.code == 500
39
+ false
40
+ end
41
+
42
+ # Endpoint: /key/info
43
+ def info
44
+ begin
45
+ return info!
46
+ rescue => e
47
+ return nil
48
+ end
49
+ end
50
+
51
+ def info!
52
+ options = {:api_key => @key}
53
+ response = HTTParty.get("#{@base}/key/info", :query => options)
54
+ return JSON.parse(response.body) if response.code == 200
55
+ raise SmartFilterBadInputParameter.new if response.code == 400
56
+ raise SmartFilterBadAPIKey.new if response.code == 403
57
+ raise SmartFilterInternalError.new if response.code == 500
58
+ Array.new
59
+ end
60
+
61
+ # Endpoint: /rule/verify
62
+ def verify_rule(rule_key)
63
+ begin
64
+ return verify_rule!(rule_key)
65
+ rescue => e
66
+ return nil
67
+ end
68
+ end
69
+
70
+ def verify_rule!(rule_key)
71
+ options = {:api_key => @key, :rule_key => rule_key}
72
+ response = HTTParty.get("#{@base}/rule/verify", :query => options)
73
+ return true if response.code == 200
74
+ raise SmartFilterBadInputParameter.new if response.code == 400
75
+ raise SmartFilterBadAPIKey.new if response.code == 403
76
+ raise SmartFilterInternalError.new if response.code == 500
77
+ false
78
+ end
79
+
80
+ # Endpoint: /xss/filter
81
+ def filter(input, rule_key)
82
+ begin
83
+ return filter!(input, rule_key)
84
+ rescue => e
85
+ return nil
86
+ end
87
+ end
88
+
89
+ def filter!(input, rule_key)
90
+ options = {:api_key => @key, :input => input, :rule_key => rule_key}
91
+ response = HTTParty.post("#{@base}/xss/filter", :query => options)
92
+ return JSON.parse(response.body) if response.code == 200
93
+ raise SmartFilterBadInputParameter.new if response.code == 400
94
+ raise SmartFilterBadAPIKey.new if response.code == 403
95
+ raise SmartFilterRequestTooLarge.new if response.code == 413
96
+ raise SmartFilterInternalError.new if response.code == 500
97
+ raise SmartFilterAccountQuotaExceeded.new if response.code == 507
98
+ Array.new
99
+ end
100
+ end
@@ -1,52 +1,28 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../result')
2
- require 'yaml'
3
- require 'httparty'
2
+ require File.expand_path(File.dirname(__FILE__) + '/prevoty/smartfilter')
4
3
 
5
- class SmartFilterNetworkException < Exception; end
6
- class SmartFilterBadInputParameter < Exception; end
7
- class SmartFilterBadAPIKey < Exception; end
8
- class SmartFilterRequestTooLarge < Exception; end
9
- class SmartFilterInternalError < Exception; end
10
- class SmartFilterAccountQuotaExceeded < Exception; end
4
+ class SmartFilterBadRuleKey < Exception; end
11
5
 
12
- class SmartFilter
13
- attr_accessor :rule_key, :api_key, :base
14
- attr_accessor :input, :output
6
+ class SmartFilter < PrevotySmartFilter
7
+ alias_method :api_key, :key
8
+ alias_method :api_key=, :key=
15
9
 
16
- def initialize(opts = {})
17
- @config = SmartFilter.config(Stoolie.config.smart_filter)
10
+ attr_accessor :rule_key, :input, :output, :response
18
11
 
19
- @rule_key = opts[:rule_key] || @config[:rule_key]
20
- @api_key = @config[:api_key]
12
+ def initialize(key = nil)
13
+ @config = SmartFilter.config(Stoolie.config.smart_filter)
21
14
 
22
- @base = 'https://api.prevoty.com/1'
23
- end
15
+ super(key)
24
16
 
25
- # Endpoint: /xss/filter
26
- def filter(input, rule_key)
27
- begin
28
- return filter!(input, rule_key)
29
- rescue => e
30
- return nil
31
- end
17
+ @rule_key = key || @config[:rule_key]
18
+ @api_key = @key = @config[:api_key]
32
19
  end
33
20
 
34
- def filter!(input, rule_key = nil)
21
+ def filter!(input, rule_key)
35
22
  rule_key ||= @rule_key
36
- options = {:api_key => @api_key, :input => input, :rule_key => rule_key}
37
- response = HTTParty.post("#{@base}/xss/filter", :query => options, :timeout => 5)
23
+ raise SmartFilterBadRuleKey.new unless rule_key
38
24
 
39
- unless rule_key and @api_key
40
- raise "You must configure Smart Filter to use a rule key and api key"
41
- end
42
-
43
- return JSON.parse(response.body) if response.code == 200
44
- raise SmartFilterBadInputParameter if response.code == 400
45
- raise SmartFilterBadAPIKey if response.code == 403
46
- raise SmartFilterRequestTooLarge if response.code == 413
47
- raise SmartFilterInternalError if response.code == 500
48
- raise SmartFilterAccountQuotaExceeded if response.code == 507
49
- Array.new
25
+ super(input, rule_key)
50
26
  end
51
27
 
52
28
  # Public: allows changing the thresholds at which the xss, spam & offensive methods will trigger
@@ -102,9 +78,10 @@ class SmartFilter
102
78
  # Returns a Stoolie::Result object
103
79
  def analyze(input = '')
104
80
  @input = input
105
- result = filter!(@input)
106
- @stats = result['statistics']
107
- @output = result['output']
81
+ @response = filter!(@input, rule_key)
82
+ @output = @response['output']
83
+ @stats = @response['statistics']
84
+
108
85
  @result = Stoolie::Result.new(self)
109
86
  end
110
87
 
@@ -1,4 +1,7 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/clients/smart_filter')
1
+ # ideally, we would only require a client if it's in use
2
+ Dir[File.expand_path(File.dirname(__FILE__) + '/clients/*.rb')].each { |file| require file }
3
+
4
+ class StoolieFilterClientException < Exception; end
2
5
 
3
6
  module Stoolie
4
7
  class Filter
@@ -6,7 +9,9 @@ module Stoolie
6
9
 
7
10
  # Public: takes the class name of the filter client to use - e.g. SmartFilter
8
11
  def initialize(client = nil)
9
- @config = Stoolie.config
12
+ raise StoolieFilterClientException.new("client must be a Class") if client and !client.is_a?(Class)
13
+
14
+ @config = Stoolie.configure
10
15
 
11
16
  @client = client || Stoolie.config.client
12
17
  @client = @client.send(:new)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "stoolie"
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Wallis"]
12
- s.date = "2014-06-06"
12
+ s.date = "2014-07-01"
13
13
  s.description = "Content filter to determine the XSS, spam or offensive quality of text."
14
14
  s.email = "awallis@bleacherreport.com"
15
15
  s.extra_rdoc_files = [
@@ -25,6 +25,7 @@ Gem::Specification.new do |s|
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "lib/stoolie.rb",
28
+ "lib/stoolie/clients/prevoty/smartfilter.rb",
28
29
  "lib/stoolie/clients/smart_filter.rb",
29
30
  "lib/stoolie/filter.rb",
30
31
  "lib/stoolie/railtie.rb",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stoolie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Wallis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-06 00:00:00.000000000 Z
11
+ date: 2014-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: loofah
@@ -166,6 +166,7 @@ files:
166
166
  - Rakefile
167
167
  - VERSION
168
168
  - lib/stoolie.rb
169
+ - lib/stoolie/clients/prevoty/smartfilter.rb
169
170
  - lib/stoolie/clients/smart_filter.rb
170
171
  - lib/stoolie/filter.rb
171
172
  - lib/stoolie/railtie.rb