Module: YandexCaptcha::Verify
- Defined in:
- lib/yandex_captcha/verify.rb
Class Method Summary collapse
- .get_captcha(request_id = nil) ⇒ Object
- .spam?(*options) ⇒ Boolean
- .valid_captcha?(captcha_id = nil, value = nil, request_id = nil) ⇒ Boolean
Class Method Details
.get_captcha(request_id = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/yandex_captcha/verify.rb', line 25 def get_captcha(request_id=nil) 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
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/yandex_captcha/verify.rb', line 9 def spam?(*) response = api_check_spam() doc = Nokogiri::XML(response) spam_result = doc.xpath('//check-spam-result') request_id_tag = spam_result.xpath('id') spam_flag_tag = spam_result.xpath('text') raise BadResponseException if request_id_tag.size.zero? request_id = request_id_tag.first spam_flag = spam_flag_tag.first.attributes["spam-flag"] spam_check request_id.content, spam_result, spam_flag.content end |
.valid_captcha?(captcha_id = nil, value = nil, request_id = nil) ⇒ Boolean
35 36 37 38 39 |
# File 'lib/yandex_captcha/verify.rb', line 35 def valid_captcha?(captcha_id=nil, value=nil, request_id=nil) response = api_check_captcha(request_id, captcha_id, value) doc = Nokogiri::XML(response) doc.xpath('//check-captcha-result/ok').any? end |