yandex_cleanweb 0.0.4 → 0.0.5
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/lib/yandex_cleanweb/version.rb +1 -1
- data/lib/yandex_cleanweb.rb +11 -3
- data/test/test_helper.rb +1 -0
- data/test/yandex_cleanweb_test.rb +68 -24
- data/yandex_cleanweb.gemspec +1 -0
- metadata +18 -2
data/lib/yandex_cleanweb.rb
CHANGED
|
@@ -5,6 +5,8 @@ require "nokogiri"
|
|
|
5
5
|
require "net/http"
|
|
6
6
|
|
|
7
7
|
module YandexCleanweb
|
|
8
|
+
class NoApiKeyException < Exception; end
|
|
9
|
+
|
|
8
10
|
API_URL = 'http://cleanweb-api.yandex.ru/1.0/'
|
|
9
11
|
|
|
10
12
|
class << self
|
|
@@ -54,7 +56,7 @@ module YandexCleanweb
|
|
|
54
56
|
def api_check_captcha(request_id, captcha_id, value)
|
|
55
57
|
check_captcha_url = "#{API_URL}/check-captcha"
|
|
56
58
|
params = {
|
|
57
|
-
:key =>
|
|
59
|
+
:key => prepare_api_key,
|
|
58
60
|
:id => request_id,
|
|
59
61
|
:captcha => captcha_id,
|
|
60
62
|
:value => value
|
|
@@ -68,7 +70,7 @@ module YandexCleanweb
|
|
|
68
70
|
|
|
69
71
|
def api_get_captcha(request_id)
|
|
70
72
|
get_captcha_url = "#{API_URL}/get-captcha"
|
|
71
|
-
params = { :key =>
|
|
73
|
+
params = { :key => prepare_api_key, :id => request_id }
|
|
72
74
|
|
|
73
75
|
uri = URI.parse(get_captcha_url)
|
|
74
76
|
uri.query = URI.encode_www_form(params)
|
|
@@ -77,7 +79,7 @@ module YandexCleanweb
|
|
|
77
79
|
end
|
|
78
80
|
|
|
79
81
|
def api_check_spam(options)
|
|
80
|
-
cleanweb_options = { :key =>
|
|
82
|
+
cleanweb_options = { :key => prepare_api_key }
|
|
81
83
|
|
|
82
84
|
if options[0].is_a?(String) # quick check
|
|
83
85
|
cleanweb_options[:body_plain] = options[0]
|
|
@@ -91,5 +93,11 @@ module YandexCleanweb
|
|
|
91
93
|
response = Net::HTTP.post_form(uri, cleanweb_options)
|
|
92
94
|
response.body
|
|
93
95
|
end
|
|
96
|
+
|
|
97
|
+
def prepare_api_key
|
|
98
|
+
raise NoApiKeyException if api_key.nil? || api_key.empty?
|
|
99
|
+
|
|
100
|
+
api_key
|
|
101
|
+
end
|
|
94
102
|
end
|
|
95
103
|
end
|
data/test/test_helper.rb
CHANGED
|
@@ -2,47 +2,91 @@
|
|
|
2
2
|
require "test_helper"
|
|
3
3
|
|
|
4
4
|
describe YandexCleanweb do
|
|
5
|
-
before do
|
|
6
|
-
YandexCleanweb.api_key = "cw.1.1.20121227T080449Z.51de1ee126e5ced6.f4f417fb55727520d7e39b00cf5393d4b1ca5e78"
|
|
7
|
-
end
|
|
8
5
|
|
|
9
|
-
|
|
6
|
+
context "without api key" do
|
|
7
|
+
before do
|
|
8
|
+
YandexCleanweb.api_key = nil
|
|
9
|
+
end
|
|
10
10
|
|
|
11
|
-
describe "
|
|
12
|
-
it "
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
describe "#spam?" do
|
|
12
|
+
it "raise an error" do
|
|
13
|
+
-> {
|
|
14
|
+
YandexCleanweb.spam?("anything")
|
|
15
|
+
}.must_raise YandexCleanweb::NoApiKeyException
|
|
15
16
|
end
|
|
16
17
|
end
|
|
17
18
|
|
|
18
|
-
describe "
|
|
19
|
-
it "
|
|
20
|
-
|
|
19
|
+
describe "#get_captcha" do
|
|
20
|
+
it "raise an error" do
|
|
21
|
+
-> {
|
|
22
|
+
YandexCleanweb.get_captcha("anything")
|
|
23
|
+
}.must_raise YandexCleanweb::NoApiKeyException
|
|
21
24
|
end
|
|
25
|
+
end
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
describe "#valid_captcha?" do
|
|
28
|
+
it "raise an error" do
|
|
29
|
+
-> {
|
|
30
|
+
YandexCleanweb.valid_captcha?("anything", "anything", 123)
|
|
31
|
+
}.must_raise YandexCleanweb::NoApiKeyException
|
|
28
32
|
end
|
|
33
|
+
end
|
|
29
34
|
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context "with empty api key" do
|
|
38
|
+
before do
|
|
39
|
+
YandexCleanweb.api_key = ""
|
|
30
40
|
end
|
|
31
41
|
|
|
42
|
+
it "raise an error" do
|
|
43
|
+
-> {
|
|
44
|
+
YandexCleanweb.spam?("anything")
|
|
45
|
+
}.must_raise YandexCleanweb::NoApiKeyException
|
|
46
|
+
end
|
|
32
47
|
end
|
|
33
48
|
|
|
34
|
-
|
|
49
|
+
context "with api key" do
|
|
35
50
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
51
|
+
before do
|
|
52
|
+
YandexCleanweb.api_key = "cw.1.1.20121227T080449Z.51de1ee126e5ced6.f4f417fb55727520d7e39b00cf5393d4b1ca5e78"
|
|
53
|
+
end
|
|
39
54
|
|
|
40
|
-
|
|
41
|
-
captcha[:captcha].wont_be_empty
|
|
55
|
+
describe "#spam?" do
|
|
42
56
|
|
|
43
|
-
|
|
44
|
-
|
|
57
|
+
describe "simple check" do
|
|
58
|
+
it "works" do
|
|
59
|
+
YandexCleanweb.spam?("фраза").must_equal false
|
|
60
|
+
YandexCleanweb.spam?("недорого увеличение пениса проститутки").must_equal false
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe "advanced mode" do
|
|
65
|
+
it "works" do
|
|
66
|
+
YandexCleanweb.spam?(:body_plain => "my text", :ip => "80.80.40.3").must_equal false
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "with some html" do
|
|
70
|
+
result = YandexCleanweb.spam?(:body_html => "some spam <a href='http://spam.com'>spam link</a>")
|
|
71
|
+
|
|
72
|
+
result[:id].wont_be_empty
|
|
73
|
+
result[:links].must_be_empty
|
|
74
|
+
end
|
|
75
|
+
end
|
|
45
76
|
end
|
|
46
77
|
|
|
78
|
+
describe "#get_captcha + #valid_captcha?" do
|
|
79
|
+
|
|
80
|
+
it "works for not valid captchas" do
|
|
81
|
+
result = YandexCleanweb.spam?(:body_html => "some spam <a href='http://spam.com'>spam link</a>")
|
|
82
|
+
captcha = YandexCleanweb.get_captcha(result[:id])
|
|
83
|
+
|
|
84
|
+
captcha[:url].wont_be_empty
|
|
85
|
+
captcha[:captcha].wont_be_empty
|
|
86
|
+
|
|
87
|
+
valid = YandexCleanweb.valid_captcha?(result[:id], captcha[:captcha], "1234")
|
|
88
|
+
valid.must_equal false
|
|
89
|
+
end
|
|
90
|
+
end
|
|
47
91
|
end
|
|
48
92
|
end
|
data/yandex_cleanweb.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yandex_cleanweb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-
|
|
12
|
+
date: 2013-04-12 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: nokogiri
|
|
@@ -59,6 +59,22 @@ dependencies:
|
|
|
59
59
|
- - ~>
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
61
|
version: '3.0'
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
63
|
+
name: minitest-spec-context
|
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
|
65
|
+
none: false
|
|
66
|
+
requirements:
|
|
67
|
+
- - ! '>='
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '0'
|
|
70
|
+
type: :development
|
|
71
|
+
prerelease: false
|
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
+
none: false
|
|
74
|
+
requirements:
|
|
75
|
+
- - ! '>='
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
62
78
|
description: Ruby wrapper for Yandex.Cleanweb
|
|
63
79
|
email:
|
|
64
80
|
- shatrov@me.com
|