Class: VerifIP::CheckResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/verifip/models.rb

Overview

Response from a single IP check containing fraud score, threat flags, geolocation data, and signal breakdown.

Constant Summary collapse

FIELDS =
%i[
  request_id ip fraud_score is_proxy is_vpn is_tor is_datacenter
  country_code country_name region city isp asn connection_type
  hostname signal_breakdown error
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ CheckResponse

Returns a new instance of CheckResponse.



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

def initialize(**kwargs)
  @request_id       = kwargs.fetch(:request_id, "")
  @ip               = kwargs.fetch(:ip, "")
  @fraud_score      = kwargs.fetch(:fraud_score, 0)
  @is_proxy         = kwargs.fetch(:is_proxy, false)
  @is_vpn           = kwargs.fetch(:is_vpn, false)
  @is_tor           = kwargs.fetch(:is_tor, false)
  @is_datacenter    = kwargs.fetch(:is_datacenter, false)
  @country_code     = kwargs.fetch(:country_code, "")
  @country_name     = kwargs.fetch(:country_name, "")
  @region           = kwargs.fetch(:region, "")
  @city             = kwargs.fetch(:city, "")
  @isp              = kwargs.fetch(:isp, "")
  @asn              = kwargs.fetch(:asn, 0)
  @connection_type  = kwargs.fetch(:connection_type, "")
  @hostname         = kwargs.fetch(:hostname, "")
  @signal_breakdown = kwargs.fetch(:signal_breakdown, {})
  @error            = kwargs.fetch(:error, nil)
end

Class Method Details

.from_hash(hash) ⇒ CheckResponse

Build a CheckResponse from a parsed JSON hash.

Parameters:

  • hash (Hash)

    parsed API response

Returns:



39
40
41
42
# File 'lib/verifip/models.rb', line 39

def self.from_hash(hash)
  hash = _symbolize(hash)
  new(**hash.slice(*FIELDS))
end

Instance Method Details

#datacenter?Boolean

Returns:

  • (Boolean)


47
# File 'lib/verifip/models.rb', line 47

def datacenter? = @is_datacenter

#inspectObject



57
# File 'lib/verifip/models.rb', line 57

def inspect = to_s

#proxy?Boolean

Returns:

  • (Boolean)


44
# File 'lib/verifip/models.rb', line 44

def proxy?     = @is_proxy

#to_hObject



49
50
51
# File 'lib/verifip/models.rb', line 49

def to_h
  FIELDS.each_with_object({}) { |f, h| h[f] = send(f) }
end

#to_sObject



53
54
55
# File 'lib/verifip/models.rb', line 53

def to_s
  "CheckResponse(ip=#{@ip}, fraud_score=#{@fraud_score}, proxy=#{@is_proxy}, vpn=#{@is_vpn})"
end

#tor?Boolean

Returns:

  • (Boolean)


46
# File 'lib/verifip/models.rb', line 46

def tor?       = @is_tor

#vpn?Boolean

Returns:

  • (Boolean)


45
# File 'lib/verifip/models.rb', line 45

def vpn?       = @is_vpn