Module: Auth::Centric::Captcha::Retrieve

Included in:
SecurityCaptcha
Defined in:
lib/auth/centric/captcha/retrieve.rb,
sig/auth/centric/captcha/retrieve.rbs

Instance Method Summary collapse

Instance Method Details

#find_or_create_pathtring

Returns:

  • (tring)


34
35
36
# File 'lib/auth/centric/captcha/retrieve.rb', line 34

def find_or_create_path
  [host, 'api/v1/security_captchas'].join('/')
end

#retrieve_captcha{

Returns:

  • ({)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/auth/centric/captcha/retrieve.rb', line 7

def retrieve_captcha
  return true unless enabled?

  payload = {
    security_captcha: {
      ip: @ip_address,
      session_id: @session_id
    }
  }

  http = HTTP
         .timeout(timeout_seconds)
         .headers(apikey:)
         .post(find_or_create_path, json: payload)

  case http.status
    when 200..202
      JSON.parse(http.body)['data']['attributes'].except('session_id', 'ip')
    when 422
      raise http.body.to_s
    else
      raise "HTTP Status #{http.status}. HTTP Body: #{http.body.to_s.gsub(/<[^>]*>/, '')}"
  end
rescue HTTP::TimeoutError
  true
end