Module: MaxmindProxyDetection

Defined in:
lib/maxmind_proxy_detection.rb

Constant Summary collapse

URL =
'https://minfraud.maxmind.com/app/ipauth_http'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.license_key=(value) ⇒ Object (writeonly)

Sets the attribute license_key

Parameters:

  • value

    the value to set the attribute license_key to.



7
8
9
# File 'lib/maxmind_proxy_detection.rb', line 7

def license_key=(value)
  @license_key = value
end

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


9
10
11
12
# File 'lib/maxmind_proxy_detection.rb', line 9

def available?
  return true  if @license_key && !@license_key.empty?
  return false
end

.score(ip) ⇒ Float?

Query Maxmind Proxy Detection service with given ip and set license_key.

Returns:

  • (Float, nil)

    Proxy score from 0.0 to 4.0. Nil if IP is invalid.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/maxmind_proxy_detection.rb', line 16

def score(ip)
  response = request(ip)

  raise 'Request to Maxmind Proxy Detection service failed' unless response.status == 200

  # Parse response
  key, value = response.body.split('=')

  # Process response
  case key
    when 'err'
      raise 'Error returned by Maxmind Proxy Detection service'
    when 'proxyScore'
      return value.to_f  if value
      return nil  # According to documentation, response does not contain value if IP is invalid
    else
      raise 'Unknown response from Maxmind Proxy Detection service'
  end
end