Module: YandexCleanweb
- Defined in:
- lib/yandex_cleanweb.rb,
lib/yandex_cleanweb/version.rb
Constant Summary collapse
- API_URL =
'http://cleanweb-api.yandex.ru/1.0/'
- VERSION =
"0.0.1"
Class Method Summary collapse
- .get_captcha(request_id) ⇒ Object
- .spam?(*options) ⇒ Boolean
- .valid_captcha?(request_id, captcha_id, value) ⇒ Boolean
Class Method Details
.get_captcha(request_id) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/yandex_cleanweb.rb', line 34 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) ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/yandex_cleanweb.rb', line 12 def spam?(*) response = api_check_spam() puts response doc = Nokogiri::XML(response) request_id_tag = doc.xpath('//check-spam-result/id') spam_flag_tag = doc.xpath('//check-spam-result/text') puts spam_flag_tag.inspect request_id = request_id_tag[0] spam_flag = spam_flag_tag[0].attributes["spam-flag"].content if spam_flag == 'yes' links = doc.xpath('//check-spam-result/links').map { |el| [attributes["url"], attributes["spam_flag"] == 'yes'] } { id: request_id, links: links } else false end end |
.valid_captcha?(request_id, captcha_id, value) ⇒ Boolean
47 48 49 50 51 |
# File 'lib/yandex_cleanweb.rb', line 47 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 |