defender 0.2.0 → 1.0.0beta1
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.
- data/README.md +132 -0
- data/lib/defender.rb +16 -59
- data/lib/defender/document.rb +51 -385
- data/lib/defender/version.rb +3 -0
- metadata +54 -56
- data/.document +0 -5
- data/.gitignore +0 -23
- data/README.rdoc +0 -22
- data/Rakefile +0 -74
- data/VERSION +0 -1
- data/defender.gemspec +0 -70
- data/lib/defender/statistics.rb +0 -176
- data/spec/defender_spec.rb +0 -24
- data/spec/document_spec.rb +0 -155
- data/spec/spec.opts +0 -1
- data/spec/spec_helper.rb +0 -14
- data/spec/statistics_spec.rb +0 -37
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: defender
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: true
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0beta1
|
9
|
+
version: 1.0.0beta1
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Henrik Hodne
|
@@ -9,104 +14,97 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-04-06 00:00:00 +02:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
name: defensio
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ~>
|
22
26
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 9
|
30
|
+
- 1
|
31
|
+
version: 0.9.1
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: rspec
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ~>
|
32
40
|
- !ruby/object:Gem::Version
|
33
|
-
|
34
|
-
|
41
|
+
segments:
|
42
|
+
- 1
|
43
|
+
- 3
|
44
|
+
- 0
|
45
|
+
version: 1.3.0
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
35
48
|
- !ruby/object:Gem::Dependency
|
36
49
|
name: yard
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
52
|
requirements:
|
41
53
|
- - ~>
|
42
54
|
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
45
|
-
-
|
46
|
-
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
- 5
|
58
|
+
- 0
|
59
|
+
version: 0.5.0
|
47
60
|
type: :development
|
48
|
-
|
49
|
-
version_requirements: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 1.2.7
|
54
|
-
version:
|
61
|
+
version_requirements: *id003
|
55
62
|
description: A wrapper of the Defensio spam filtering service.
|
56
|
-
email:
|
63
|
+
email:
|
64
|
+
- henrik.hodne@binaryhex.com
|
57
65
|
executables: []
|
58
66
|
|
59
67
|
extensions: []
|
60
68
|
|
61
|
-
extra_rdoc_files:
|
62
|
-
|
63
|
-
- README.rdoc
|
69
|
+
extra_rdoc_files: []
|
70
|
+
|
64
71
|
files:
|
65
|
-
- .document
|
66
|
-
- .gitignore
|
67
|
-
- LICENSE
|
68
|
-
- README.rdoc
|
69
|
-
- Rakefile
|
70
|
-
- VERSION
|
71
|
-
- defender.gemspec
|
72
|
-
- lib/defender.rb
|
73
72
|
- lib/defender/document.rb
|
74
|
-
- lib/defender/
|
75
|
-
-
|
76
|
-
-
|
77
|
-
-
|
78
|
-
- spec/spec_helper.rb
|
79
|
-
- spec/statistics_spec.rb
|
73
|
+
- lib/defender/version.rb
|
74
|
+
- lib/defender.rb
|
75
|
+
- LICENSE
|
76
|
+
- README.md
|
80
77
|
has_rdoc: true
|
81
78
|
homepage: http://github.com/dvyjones/defender
|
82
79
|
licenses: []
|
83
80
|
|
84
81
|
post_install_message:
|
85
|
-
rdoc_options:
|
86
|
-
|
82
|
+
rdoc_options: []
|
83
|
+
|
87
84
|
require_paths:
|
88
85
|
- lib
|
89
86
|
required_ruby_version: !ruby/object:Gem::Requirement
|
90
87
|
requirements:
|
91
88
|
- - ">="
|
92
89
|
- !ruby/object:Gem::Version
|
90
|
+
segments:
|
91
|
+
- 0
|
93
92
|
version: "0"
|
94
|
-
version:
|
95
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
94
|
requirements:
|
97
95
|
- - ">="
|
98
96
|
- !ruby/object:Gem::Version
|
99
|
-
|
100
|
-
|
97
|
+
segments:
|
98
|
+
- 1
|
99
|
+
- 3
|
100
|
+
- 6
|
101
|
+
version: 1.3.6
|
101
102
|
requirements: []
|
102
103
|
|
103
104
|
rubyforge_project:
|
104
|
-
rubygems_version: 1.3.
|
105
|
+
rubygems_version: 1.3.6
|
105
106
|
signing_key:
|
106
107
|
specification_version: 3
|
107
108
|
summary: Ruby API wrapper for Defensio
|
108
|
-
test_files:
|
109
|
-
|
110
|
-
- spec/document_spec.rb
|
111
|
-
- spec/defender_spec.rb
|
112
|
-
- spec/statistics_spec.rb
|
109
|
+
test_files: []
|
110
|
+
|
data/.document
DELETED
data/.gitignore
DELETED
data/README.rdoc
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
= defender
|
2
|
-
|
3
|
-
This is a Ruby wrapper of the Defensio[http://defensio.com] spam filtering API. To use this library, you need an API key from Defensio. Go ahead and {get one}[http://defensio.com/signup/].
|
4
|
-
|
5
|
-
Thanks to Defensio for the excellent documentation, the documentation in the code is more or less copied from them.
|
6
|
-
|
7
|
-
Defender follows the {Semantic Versioning}[http://semver.org/] spec.
|
8
|
-
|
9
|
-
== Note on Patches/Pull Requests
|
10
|
-
|
11
|
-
* Fork the project.
|
12
|
-
* Make your feature addition or bug fix.
|
13
|
-
* Add tests for it. This is important so I don't break it in a
|
14
|
-
future version unintentionally.
|
15
|
-
* Commit, do not mess with rakefile, version, or history.
|
16
|
-
(if you want to have your own version, that is fine but
|
17
|
-
bump version in a commit by itself I can ignore when I pull)
|
18
|
-
* Send me a pull request. Bonus points for topic branches.
|
19
|
-
|
20
|
-
== Copyright
|
21
|
-
|
22
|
-
Copyright (c) 2009-2010 Henrik Hodne. See LICENSE for details.
|
data/Rakefile
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "defender"
|
8
|
-
gem.summary = %Q{Ruby API wrapper for Defensio}
|
9
|
-
gem.description = %Q{A wrapper of the Defensio spam filtering service.}
|
10
|
-
gem.email = "henrik.hodne@binaryhex.com"
|
11
|
-
gem.homepage = "http://github.com/dvyjones/defender"
|
12
|
-
gem.authors = ["Henrik Hodne"]
|
13
|
-
gem.add_dependency "httparty", "~> 0.4.3"
|
14
|
-
gem.add_development_dependency "rspec", "~> 1.2.9"
|
15
|
-
gem.add_development_dependency "yard", "~> 0.4.0"
|
16
|
-
gem.add_development_dependency "fakeweb", "~> 1.2.7"
|
17
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
|
-
end
|
19
|
-
Jeweler::GemcutterTasks.new
|
20
|
-
rescue LoadError
|
21
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
22
|
-
end
|
23
|
-
|
24
|
-
require 'spec/rake/spectask'
|
25
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
26
|
-
spec.libs << 'lib' << 'spec'
|
27
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
28
|
-
end
|
29
|
-
|
30
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
31
|
-
spec.libs << 'lib' << 'spec'
|
32
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
33
|
-
spec.rcov = true
|
34
|
-
end
|
35
|
-
|
36
|
-
task :spec => :check_dependencies
|
37
|
-
|
38
|
-
begin
|
39
|
-
require 'reek/adapters/rake_task'
|
40
|
-
Reek::RakeTask.new do |t|
|
41
|
-
t.verbose = false
|
42
|
-
t.source_files = 'lib/**/*.rb'
|
43
|
-
end
|
44
|
-
rescue LoadError
|
45
|
-
task :reek do
|
46
|
-
abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
begin
|
51
|
-
require 'roodi'
|
52
|
-
require 'roodi_task'
|
53
|
-
RoodiTask.new do |t|
|
54
|
-
t.verbose = false
|
55
|
-
end
|
56
|
-
rescue LoadError
|
57
|
-
task :roodi do
|
58
|
-
abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
task :default => :spec
|
63
|
-
|
64
|
-
begin
|
65
|
-
require 'yard'
|
66
|
-
YARD::Rake::YardocTask.new do |conf|
|
67
|
-
#conf.options = ["-mmarkdown"]
|
68
|
-
conf.files = ["lib/**/*.rb", "-", "LICENSE"]
|
69
|
-
end
|
70
|
-
rescue LoadError
|
71
|
-
task :yard do
|
72
|
-
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
73
|
-
end
|
74
|
-
end
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.2.0
|
data/defender.gemspec
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{defender}
|
8
|
-
s.version = "0.2.0"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Henrik Hodne"]
|
12
|
-
s.date = %q{2010-01-20}
|
13
|
-
s.description = %q{A wrapper of the Defensio spam filtering service.}
|
14
|
-
s.email = %q{henrik.hodne@binaryhex.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"defender.gemspec",
|
27
|
-
"lib/defender.rb",
|
28
|
-
"lib/defender/document.rb",
|
29
|
-
"lib/defender/statistics.rb",
|
30
|
-
"spec/defender_spec.rb",
|
31
|
-
"spec/document_spec.rb",
|
32
|
-
"spec/spec.opts",
|
33
|
-
"spec/spec_helper.rb",
|
34
|
-
"spec/statistics_spec.rb"
|
35
|
-
]
|
36
|
-
s.homepage = %q{http://github.com/dvyjones/defender}
|
37
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
-
s.require_paths = ["lib"]
|
39
|
-
s.rubygems_version = %q{1.3.5}
|
40
|
-
s.summary = %q{Ruby API wrapper for Defensio}
|
41
|
-
s.test_files = [
|
42
|
-
"spec/spec_helper.rb",
|
43
|
-
"spec/document_spec.rb",
|
44
|
-
"spec/defender_spec.rb",
|
45
|
-
"spec/statistics_spec.rb"
|
46
|
-
]
|
47
|
-
|
48
|
-
if s.respond_to? :specification_version then
|
49
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
|
-
s.specification_version = 3
|
51
|
-
|
52
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
53
|
-
s.add_runtime_dependency(%q<httparty>, ["~> 0.4.3"])
|
54
|
-
s.add_development_dependency(%q<rspec>, ["~> 1.2.9"])
|
55
|
-
s.add_development_dependency(%q<yard>, ["~> 0.4.0"])
|
56
|
-
s.add_development_dependency(%q<fakeweb>, ["~> 1.2.7"])
|
57
|
-
else
|
58
|
-
s.add_dependency(%q<httparty>, ["~> 0.4.3"])
|
59
|
-
s.add_dependency(%q<rspec>, ["~> 1.2.9"])
|
60
|
-
s.add_dependency(%q<yard>, ["~> 0.4.0"])
|
61
|
-
s.add_dependency(%q<fakeweb>, ["~> 1.2.7"])
|
62
|
-
end
|
63
|
-
else
|
64
|
-
s.add_dependency(%q<httparty>, ["~> 0.4.3"])
|
65
|
-
s.add_dependency(%q<rspec>, ["~> 1.2.9"])
|
66
|
-
s.add_dependency(%q<yard>, ["~> 0.4.0"])
|
67
|
-
s.add_dependency(%q<fakeweb>, ["~> 1.2.7"])
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
data/lib/defender/statistics.rb
DELETED
@@ -1,176 +0,0 @@
|
|
1
|
-
module Defender
|
2
|
-
class Statistics
|
3
|
-
class Extended
|
4
|
-
##
|
5
|
-
# The starting date.
|
6
|
-
#
|
7
|
-
# @return [String] Is in the format YYYY-MM-DD.
|
8
|
-
attr_reader :from
|
9
|
-
|
10
|
-
##
|
11
|
-
# The ending date.
|
12
|
-
#
|
13
|
-
# @return [String] Is in the form YYYY-MM-DD.
|
14
|
-
attr_reader :to
|
15
|
-
|
16
|
-
##
|
17
|
-
# Provides a set of URLs that chart the data provided in the data array.
|
18
|
-
#
|
19
|
-
# The Hash returned will have the keys `:accuracy`, `:unwanted` and
|
20
|
-
# `:legitimate`, which all refer to the same fields in the {#data} hash.
|
21
|
-
#
|
22
|
-
# @return [Hash{Symbol => String}]
|
23
|
-
attr_reader :chart_urls
|
24
|
-
|
25
|
-
##
|
26
|
-
# The set of dates within the retrieved period.
|
27
|
-
#
|
28
|
-
# The keys are the date in YYYY-MM-DD format.
|
29
|
-
#
|
30
|
-
# Each date has the following keys:
|
31
|
-
#
|
32
|
-
# * `:false_negatives` - The number of false negatives for the specified
|
33
|
-
# date.
|
34
|
-
# * `:false_positives` - The number of false positives for the specified
|
35
|
-
# date.
|
36
|
-
# * `:legitimate` - The number of legitimate documents processed on the
|
37
|
-
# specified date.
|
38
|
-
# * `:accuracy` - How accurate Defensio has recently been for the current
|
39
|
-
# user on the specified date. This is returned as a Float between 0
|
40
|
-
# and 1. For example, 0.9525 means 95.25% accurate.
|
41
|
-
# * `:unwanted` - The number of unwanted documents processed on the
|
42
|
-
# specified date.
|
43
|
-
#
|
44
|
-
# @return [Hash{String => Hash{Symbol => Object}}]
|
45
|
-
attr_reader :data
|
46
|
-
|
47
|
-
##
|
48
|
-
# Retrieves extended statistics from a given date to another one.
|
49
|
-
#
|
50
|
-
# @param [#strftime, #to_s] from The starting date.
|
51
|
-
# @param [#strftime, #to_s] to The ending date.
|
52
|
-
def initialize(from, to)
|
53
|
-
@from = from.respond_to?(:strftime) ? from.strftime('%Y-%m-%d') : from.to_s
|
54
|
-
@to = to.respond_to?(:strftime) ? to.strftime('%Y-%m-%d') : to.to_s
|
55
|
-
|
56
|
-
response = Defender.get("/#{Defender.api_key}/extended-stats.json", :from => @from, :to => @to)['defensio-result']
|
57
|
-
if response['status'] == 'success'
|
58
|
-
@chart_urls = {
|
59
|
-
:accuracy => response['chart-urls']['recent-accuracy'],
|
60
|
-
:unwanted => response['chart-urls']['total-unwanted'],
|
61
|
-
:legitimate => response['chart-urls']['total-legitimate']
|
62
|
-
}
|
63
|
-
|
64
|
-
@data = {}
|
65
|
-
response['data'].each do |data|
|
66
|
-
@data[data['date']] = {
|
67
|
-
:false_negatives => data['false-negatives'],
|
68
|
-
:false_positives => data['false-positives'],
|
69
|
-
:legitimate => data['legitimate'],
|
70
|
-
:accuracy => data['recent-accuracy'],
|
71
|
-
:unwanted => data['unwanted']
|
72
|
-
}
|
73
|
-
end
|
74
|
-
else
|
75
|
-
raise StandardError, response['message']
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
##
|
81
|
-
# The version of the Defensio API being used. Should be the same as
|
82
|
-
# {Defender::API_VERSION}.
|
83
|
-
#
|
84
|
-
# @return [String]
|
85
|
-
attr_reader :api_version
|
86
|
-
|
87
|
-
##
|
88
|
-
# The number of documents that have been allowed but that should have been
|
89
|
-
# blocked.
|
90
|
-
#
|
91
|
-
# @return [Fixnum]
|
92
|
-
attr_reader :false_negatives
|
93
|
-
|
94
|
-
##
|
95
|
-
# The number of documents that have been blocked but that should have been
|
96
|
-
# allowed.
|
97
|
-
#
|
98
|
-
# @return [Fixnum]
|
99
|
-
attr_reader :false_positives
|
100
|
-
|
101
|
-
##
|
102
|
-
# Whether Defensio is learning from the documents you post.
|
103
|
-
#
|
104
|
-
# @return [Boolean]
|
105
|
-
attr_reader :learning
|
106
|
-
|
107
|
-
##
|
108
|
-
# A message explaining why Defensio is in learning mode.
|
109
|
-
#
|
110
|
-
# @return [String]
|
111
|
-
attr_reader :learning_status
|
112
|
-
|
113
|
-
##
|
114
|
-
# The total number of legitimate documents analyzed.
|
115
|
-
#
|
116
|
-
# @return [Fixnum]
|
117
|
-
attr_reader :legitimate_total
|
118
|
-
|
119
|
-
##
|
120
|
-
# How accurate Defensio has recently been for this user.
|
121
|
-
#
|
122
|
-
# This returns a floating point value between 0 and 1. For example, 0.9525
|
123
|
-
# means 95.25% accurate.
|
124
|
-
#
|
125
|
-
# @return [Float<0..1>]
|
126
|
-
attr_reader :recent_accuracy
|
127
|
-
|
128
|
-
##
|
129
|
-
# The number of documents containing malicious content.
|
130
|
-
#
|
131
|
-
# @return [Fixnum]
|
132
|
-
attr_reader :unwanted_malicious
|
133
|
-
|
134
|
-
##
|
135
|
-
# The number of spam documents analyzed.
|
136
|
-
#
|
137
|
-
# @return [Fixnum]
|
138
|
-
attr_reader :unwanted_spam
|
139
|
-
|
140
|
-
##
|
141
|
-
# The total number of unwanted documents.
|
142
|
-
#
|
143
|
-
# @return [Fixnum]
|
144
|
-
attr_reader :unwanted_total
|
145
|
-
|
146
|
-
##
|
147
|
-
# Initialize the object and retrieve basic statistics.
|
148
|
-
#
|
149
|
-
# @raise StandardError if any of the calls to the server during retrieving
|
150
|
-
# of statistics fail.
|
151
|
-
def initialize
|
152
|
-
retrieve_basic_stats
|
153
|
-
end
|
154
|
-
|
155
|
-
private
|
156
|
-
|
157
|
-
def retrieve_basic_stats
|
158
|
-
response = Defender.get("/#{Defender.api_key}/basic-stats.json")['defensio-result']
|
159
|
-
|
160
|
-
if response['status'] == 'success'
|
161
|
-
@api_version = response["api-version"]
|
162
|
-
@false_negatives = response["false-negatives"]
|
163
|
-
@false_positives = response["false-positives"]
|
164
|
-
@learning = response["learning"]
|
165
|
-
@learning_status = response["learning-status"]
|
166
|
-
@legitimate_total = response["legitimate"]["total"]
|
167
|
-
@recent_accuracy = response["recent-accuracy"]
|
168
|
-
@unwanted_malicious = response["unwanted"]["malicious"]
|
169
|
-
@unwanted_spam = response["unwanted"]["spam"]
|
170
|
-
@unwanted_total = response["unwanted"]["total"]
|
171
|
-
else
|
172
|
-
raise StandardError, response['message']
|
173
|
-
end
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|