Module: YandexCleanweb
- Defined in:
- lib/yandex_cleanweb.rb,
lib/yandex_cleanweb/version.rb
Defined Under Namespace
Classes: BadResponseException, NoApiKeyException
Constant Summary
collapse
- API_URL =
'http://cleanweb-api.yandex.ru/1.0'
- VERSION =
"0.0.7"
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
14
15
16
|
# File 'lib/yandex_cleanweb.rb', line 14
def api_key
@api_key
end
|
Class Method Details
.get_captcha(request_id) ⇒ Object
67
68
69
70
71
72
73
74
75
|
# File 'lib/yandex_cleanweb.rb', line 67
def get_captcha(request_id)
response = api_get_captcha(request_id)
doc = Nokogiri::XML(response)
url = doc.xpath('//get-captcha-result/url').text
captcha_id = doc.xpath('//get-captcha-result/captcha').text
{ url: url, captcha: captcha_id }
end
|
.spam!(*options) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/yandex_cleanweb.rb', line 41
def spam!(*options)
response = api_check_spam(options)
doc = Nokogiri::XML(response)
request_id_tag = doc.xpath('//check-spam-result/id')
spam_flag_tag = doc.xpath('//check-spam-result/text')
raise BadResponseException if request_id_tag.size.zero?
request_id = request_id_tag[0].content
spam_flag = spam_flag_tag[0].attributes["spam-flag"].content
if spam_flag == 'yes'
true
else
response = api_mark_as_spam(request_id)
doc = Nokogiri::Slop(response)
status = doc.xpath("//complain-result/ok").first.name
if status=='ok'
true
else
false
end
end
end
|
.spam?(*options) ⇒ Boolean
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/yandex_cleanweb.rb', line 16
def spam?(*options)
response = api_check_spam(options)
doc = Nokogiri::XML(response)
request_id_tag = doc.xpath('//check-spam-result/id')
spam_flag_tag = doc.xpath('//check-spam-result/text')
raise BadResponseException if request_id_tag.size.zero?
request_id = request_id_tag[0].content
spam_flag = spam_flag_tag[0].attributes["spam-flag"].content
if spam_flag == 'yes'
links = doc.xpath('//check-spam-result/links')[0].children
links.map do |el|
[el.attributes["url"], el.attributes["spam_flag"] == 'yes']
end
{ id: request_id, links: links }
else
false
end
end
|
.valid_captcha?(request_id, captcha_id, value) ⇒ Boolean
77
78
79
80
81
|
# File 'lib/yandex_cleanweb.rb', line 77
def valid_captcha?(request_id, captcha_id, value)
response = api_check_captcha(request_id, captcha_id, value)
doc = Nokogiri::XML(response)
doc.xpath('//check-captcha-result/ok').any?
end
|