Class: VerifIP::CheckResponse
- Inherits:
-
Object
- Object
- VerifIP::CheckResponse
- 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
-
.from_hash(hash) ⇒ CheckResponse
Build a CheckResponse from a parsed JSON hash.
Instance Method Summary collapse
- #datacenter? ⇒ Boolean
-
#initialize(**kwargs) ⇒ CheckResponse
constructor
A new instance of CheckResponse.
- #inspect ⇒ Object
- #proxy? ⇒ Boolean
- #to_h ⇒ Object
- #to_s ⇒ Object
- #tor? ⇒ Boolean
- #vpn? ⇒ Boolean
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.
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
47 |
# File 'lib/verifip/models.rb', line 47 def datacenter? = @is_datacenter |
#inspect ⇒ Object
57 |
# File 'lib/verifip/models.rb', line 57 def inspect = to_s |
#proxy? ⇒ Boolean
44 |
# File 'lib/verifip/models.rb', line 44 def proxy? = @is_proxy |
#to_h ⇒ Object
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_s ⇒ Object
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
46 |
# File 'lib/verifip/models.rb', line 46 def tor? = @is_tor |
#vpn? ⇒ Boolean
45 |
# File 'lib/verifip/models.rb', line 45 def vpn? = @is_vpn |