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
28 29 30 31 32 33 34 35 36 |
# File 'lib/yandex_captcha/verify.rb', line 28 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 24 25 26 |
# 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') raise BadResponseException unless 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.content spam_flag = spam_flag_tag.first.attributes["spam-flag"].content spam_flag_check request_id, spam_result, spam_flag end |
.valid_captcha?(captcha_id = nil, value = nil, request_id = nil) ⇒ Boolean
38 39 40 41 42 43 44 |
# File 'lib/yandex_captcha/verify.rb', line 38 def valid_captcha?(captcha_id=nil, value=nil, request_id=nil) true if YandexCaptcha.skip_env response = api_check_captcha(request_id, captcha_id, value) doc = Nokogiri::XML(response) doc.xpath('//check-captcha-result/ok').any? end |