mollom 0.1.1 → 0.1.2
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 → README.rdoc} +1 -1
- data/lib/mollom.rb +21 -14
- data/test/mollom_test.rb +4 -2
- metadata +5 -5
data/{README → README.rdoc}
RENAMED
@@ -22,7 +22,7 @@ After you have requested a public/private key-pair from Mollom (on http://www.mo
|
|
22
22
|
content = m.check_content(:post_title => 'Mollem is an open API',
|
23
23
|
:post_body => "Lorem Ipsum dolor...",
|
24
24
|
:author_name => 'Jan De Poorter',
|
25
|
-
:author_url => 'http://
|
25
|
+
:author_url => 'http://workswithruby.com')
|
26
26
|
if content.spam?
|
27
27
|
puts "You, sir, are a spammer.. Goodbye!"
|
28
28
|
elsif content.unsure?
|
data/lib/mollom.rb
CHANGED
@@ -14,6 +14,7 @@ class Mollom
|
|
14
14
|
end
|
15
15
|
|
16
16
|
attr_accessor :private_key, :public_key
|
17
|
+
attr_writer :server_list
|
17
18
|
|
18
19
|
# Creates a new Mollom object. Takes +private_key+ and +public_key+ as keys.
|
19
20
|
#
|
@@ -110,11 +111,25 @@ class Mollom
|
|
110
111
|
# low-quality
|
111
112
|
# unwanted
|
112
113
|
#
|
113
|
-
#
|
114
|
+
# mollom.send_feedback :session_id => 'a9616e6b4cd6a81ecdd509fa624d895d', :feedback => 'unwanted'
|
114
115
|
def send_feedback feedback = {}
|
115
116
|
return send_command('mollom.sendFeedback', feedback)
|
116
117
|
end
|
117
118
|
|
119
|
+
# Gets a list of servers from Mollom. You should cache this information in your application in a temporary file or in a database. You can set this with Mollom#server_list=
|
120
|
+
#
|
121
|
+
# Takes an optional parameter +refresh+, which resets the cached value.
|
122
|
+
#
|
123
|
+
# mollom.server_list
|
124
|
+
# # => [{:proto=>"http", :ip=>"88.151.243.81"}, {:proto=>"http", :ip=>"82.103.131.136"}]
|
125
|
+
def server_list refresh = false
|
126
|
+
@server_list = nil if refresh
|
127
|
+
@server_list ||= XMLRPC::Client.new("xmlrpc.mollom.com", "/#{API_VERSION}").call('mollom.getServerList', authentication_hash).collect do |server|
|
128
|
+
proto, ip = server.split('://')
|
129
|
+
{:proto => proto, :ip => ip}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
118
133
|
private
|
119
134
|
def send_command(command, data = {})
|
120
135
|
server_list.each do |server|
|
@@ -141,25 +156,17 @@ class Mollom
|
|
141
156
|
server_list(true)
|
142
157
|
retry
|
143
158
|
end
|
144
|
-
|
145
|
-
#
|
146
|
-
def server_list refresh = false
|
147
|
-
@server_list = nil if refresh
|
148
|
-
@server_list ||= XMLRPC::Client.new("xmlrpc.mollom.com", "/#{API_VERSION}").call('mollom.getServerList', authentication_hash).collect do |server|
|
149
|
-
proto, ip = server.split('://')
|
150
|
-
{:proto => proto, :ip => ip}
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
# Creates a HMAC-SHA1 Hash with the current timestamp, and your private key.
|
159
|
+
|
160
|
+
# Creates a HMAC-SHA1 Hash with the current timestamp, a nonce, and your private key.
|
155
161
|
def authentication_hash
|
156
162
|
now = Time.now.gmtime.strftime('%Y-%m-%dT%H:%M:%S.000+0000')
|
163
|
+
nonce = Kernel.rand(2**31) # Random signed int
|
157
164
|
|
158
165
|
hash = Base64.encode64(
|
159
|
-
OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, @private_key, now)
|
166
|
+
OpenSSL::HMAC.digest(OpenSSL::Digest::SHA1.new, @private_key, "#{now}:#{nonce}:#{@private_key}")
|
160
167
|
).chomp
|
161
168
|
|
162
|
-
return :public_key=> @public_key, :time => now, :hash => hash
|
169
|
+
return :public_key=> @public_key, :time => now, :hash => hash, :nonce => nonce
|
163
170
|
end
|
164
171
|
|
165
172
|
class ContentResponse
|
data/test/mollom_test.rb
CHANGED
@@ -25,10 +25,12 @@ class TestMollom < Test::Unit::TestCase
|
|
25
25
|
time = mock
|
26
26
|
time.expects(:strftime).with('%Y-%m-%dT%H:%M:%S.000+0000').returns('2008-04-01T13:54:26.000+0000')
|
27
27
|
Time.stubs(:now).returns(stub(:gmtime => time))
|
28
|
+
Kernel.expects(:rand).with(2**31).returns(42)
|
28
29
|
hash = @mollom.authentication_hash
|
29
|
-
assert_equal("
|
30
|
+
assert_equal("oWN15TqrbLVdTAgcuDmofskaNyM=", hash[:hash])
|
30
31
|
assert_equal('yyyyyyyyy', hash[:public_key])
|
31
32
|
assert_equal('2008-04-01T13:54:26.000+0000', hash[:time])
|
33
|
+
assert_equal(42, hash[:nonce])
|
32
34
|
end
|
33
35
|
|
34
36
|
def test_server_list
|
@@ -73,7 +75,7 @@ class TestMollom < Test::Unit::TestCase
|
|
73
75
|
|
74
76
|
def test_send_command_with_reload_exception
|
75
77
|
# TODO: Test this
|
76
|
-
@mollom.send_command('mollom.testMessage', {:options => 'foo'})
|
78
|
+
# @mollom.send_command('mollom.testMessage', {:options => 'foo'})
|
77
79
|
end
|
78
80
|
|
79
81
|
def test_send_command_with_bad_command
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mollom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan De Poorter
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-04-
|
12
|
+
date: 2008-04-24 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -20,10 +20,10 @@ executables: []
|
|
20
20
|
extensions: []
|
21
21
|
|
22
22
|
extra_rdoc_files:
|
23
|
-
- README
|
23
|
+
- README.rdoc
|
24
24
|
files:
|
25
25
|
- lib/mollom.rb
|
26
|
-
- README
|
26
|
+
- README.rdoc
|
27
27
|
has_rdoc: true
|
28
28
|
homepage: mollom.rubyforge.com
|
29
29
|
post_install_message:
|
@@ -46,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
requirements: []
|
47
47
|
|
48
48
|
rubyforge_project: mollom
|
49
|
-
rubygems_version: 1.0
|
49
|
+
rubygems_version: 1.1.0
|
50
50
|
signing_key:
|
51
51
|
specification_version: 2
|
52
52
|
summary: Ruby class for easy interfacing with the mollom.com open API for spam detection and content quality assesment.
|