File: ipqualityscore.rb

package info (click to toggle)
ruby-geocoder 1.8.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 900 kB
  • sloc: ruby: 8,419; makefile: 3
file content (54 lines) | stat: -rw-r--r-- 1,364 bytes parent folder | download
1
2
3
4
5
6
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require 'geocoder/results/base'

module Geocoder
  module Result
    class Ipqualityscore < Base

      def self.key_method_mappings
        {
          'request_id' => :request_id,
          'success' => :success?,
          'message' => :message,
          'city' => :city,
          'region' => :state,
          'country_code' => :country_code,
          'mobile' => :mobile?,
          'fraud_score' => :fraud_score,
          'ISP' => :isp,
          'ASN' => :asn,
          'organization' => :organization,
          'is_crawler' => :crawler?,
          'host' => :host,
          'proxy' => :proxy?,
          'vpn' => :vpn?,
          'tor' => :tor?,
          'active_vpn' => :active_vpn?,
          'active_tor' => :active_tor?,
          'recent_abuse' => :recent_abuse?,
          'bot_status' => :bot?,
          'connection_type' => :connection_type,
          'abuse_velocity' => :abuse_velocity,
          'timezone' => :timezone,
        }
      end

      key_method_mappings.each_pair do |key, meth|
        define_method meth do
          @data[key]
        end
      end

      alias_method :state_code, :state
      alias_method :country, :country_code

      def postal_code
        '' # No suitable fallback
      end

      def address
        [city, state, country_code].compact.reject(&:empty?).join(', ')
      end

    end
  end
end