vpndetection 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa0cdfbbc74c41bcfe5ecb123df7dc02f4d9255229d5b96764cd3046f290004a
4
- data.tar.gz: 540b91db33957765bed48ab55b3cacc10dab5b55fa8d8a91d51ad21a3cee86de
3
+ metadata.gz: 6d5875418fd7eb25808f8708537f8a17008502cf24bf3ffcd808595f95f5d8d4
4
+ data.tar.gz: c695e3f997ddb7284324f8c990a910083b183bb6d379046c27258bd4ceeb09d4
5
5
  SHA512:
6
- metadata.gz: 020525503bb0410d9c9a79b04230b6ce2956798813583d7dee1dd4f92c3f00cee496a273a5d8a4db240a1661d19674d939e8c0ceb9a2949669c2793eb3170a97
7
- data.tar.gz: c0071cc728e2a67f3da1e6c33974ef223bc46e8b96057ea4a013909f408fc781246ba9ec4216ec35bd34001428d004f0d7709ea9957dac2689398b8c27349e15
6
+ metadata.gz: c69b0dad9c16c852b58d98faf6356a1f19704126f9963605afd002b7b186b7fdec26511219a68a7d111b4e4e718ca2a5a1415f01121046b0fe67a81bc20d8b6e
7
+ data.tar.gz: 2bc760ccdcf01d2ca3bb02489e4d12dc390af9e077bc35904d0147b24c4761f99632715c9b6c9ae2789cd48041191e644498681e059251ebe4476719e98a83c7
data/README.md CHANGED
@@ -70,7 +70,7 @@ Usage counts against the anniversary of your subscription, not the calendar mont
70
70
 
71
71
  ### Batch lookup
72
72
 
73
- You can do batch lookups with a list, which parallelizes requests for you efficiently:
73
+ Look up many addresses at once. Bogons and cached answers are handled locally, and everything else goes to the batch endpoint in chunks of up to 1000 addresses, in parallel:
74
74
 
75
75
  ```ruby
76
76
  results = client.lookup_batch(['45.83.91.1', '8.8.8.8', '1.1.1.1'])
@@ -84,12 +84,12 @@ results.each do |ip, result|
84
84
  end
85
85
  ```
86
86
 
87
- Results are keyed by address, so duplicates in your list collapse into a single request and one address failing never loses the rest.
87
+ Results are keyed by address, in the order you first listed each one, so duplicates in your list collapse into a single entry and one address failing never loses the rest: it carries its error as its value, with the status the API would have given that address on its own.
88
88
 
89
- Concurrency and other variables are configurable per-call:
89
+ How many chunks are in flight at once, and how many times a failed chunk is retried, are configurable per call:
90
90
 
91
91
  ```ruby
92
- results = client.lookup_batch(many_ips, concurrency: 32, retries: 4)
92
+ results = client.lookup_batch(many_ips, concurrency: 4, retries: 4)
93
93
  ```
94
94
 
95
95
  ### Caching
@@ -19,6 +19,74 @@ module VPNDetection
19
19
  def initialize(api_client = ApiClient.default)
20
20
  @api_client = api_client
21
21
  end
22
+ # Batch
23
+ # Answers up to 1000 addresses in one call. Each distinct string in `ips` is one lookup: it costs exactly what `GET /{ip}` costs for that address and comes back with exactly the fields that call would carry for your plan. Exact duplicates collapse to one entry and one lookup. Both maps in the answer are keyed by the string you sent, so nothing has to be lined up by position; the `ip` inside each result is the normalized form. An address that could not be answered sits in `errors` with the status and message the single lookup would have given, and never disturbs the others: a string that is not an address is a `400` there, and an allowance that runs out part way through leaves the remaining entries as `429`s. The call itself fails only for the reasons below, and a `429` on the call always carries `Retry-After`: the batch is admitted or refused whole by the rate limit, so a per-entry `429` is always a spent allowance and never a throttle.
24
+ # @param batch_lookup_request [BatchLookupRequest]
25
+ # @param [Hash] opts the optional parameters
26
+ # @return [BatchLookupResponse]
27
+ def lookup_batch(batch_lookup_request, opts = {})
28
+ data, _status_code, _headers = lookup_batch_with_http_info(batch_lookup_request, opts)
29
+ data
30
+ end
31
+
32
+ # Batch
33
+ # Answers up to 1000 addresses in one call. Each distinct string in `ips` is one lookup: it costs exactly what `GET /{ip}` costs for that address and comes back with exactly the fields that call would carry for your plan. Exact duplicates collapse to one entry and one lookup. Both maps in the answer are keyed by the string you sent, so nothing has to be lined up by position; the `ip` inside each result is the normalized form. An address that could not be answered sits in `errors` with the status and message the single lookup would have given, and never disturbs the others: a string that is not an address is a `400` there, and an allowance that runs out part way through leaves the remaining entries as `429`s. The call itself fails only for the reasons below, and a `429` on the call always carries `Retry-After`: the batch is admitted or refused whole by the rate limit, so a per-entry `429` is always a spent allowance and never a throttle.
34
+ # @param batch_lookup_request [BatchLookupRequest]
35
+ # @param [Hash] opts the optional parameters
36
+ # @return [Array<(BatchLookupResponse, Integer, Hash)>] BatchLookupResponse data, response status code and response headers
37
+ def lookup_batch_with_http_info(batch_lookup_request, opts = {})
38
+ if @api_client.config.debugging
39
+ @api_client.config.logger.debug 'Calling API: LookupWireApi.lookup_batch ...'
40
+ end
41
+ # verify the required parameter 'batch_lookup_request' is set
42
+ if @api_client.config.client_side_validation && batch_lookup_request.nil?
43
+ fail ArgumentError, "Missing the required parameter 'batch_lookup_request' when calling LookupWireApi.lookup_batch"
44
+ end
45
+ # resource path
46
+ local_var_path = '/batch'
47
+
48
+ # query parameters
49
+ query_params = opts[:query_params] || {}
50
+
51
+ # header parameters
52
+ header_params = opts[:header_params] || {}
53
+ # HTTP header 'Accept' (if needed)
54
+ header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
55
+ # HTTP header 'Content-Type'
56
+ content_type = @api_client.select_header_content_type(['application/json'])
57
+ if !content_type.nil?
58
+ header_params['Content-Type'] = content_type
59
+ end
60
+
61
+ # form parameters
62
+ form_params = opts[:form_params] || {}
63
+
64
+ # http body (model)
65
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(batch_lookup_request)
66
+
67
+ # return_type
68
+ return_type = opts[:debug_return_type] || 'BatchLookupResponse'
69
+
70
+ # auth_names
71
+ auth_names = opts[:debug_auth_names] || ['apiKeyQuery', 'bearerAuth', 'apiKeyHeader']
72
+
73
+ new_options = opts.merge(
74
+ :operation => :"LookupWireApi.lookup_batch",
75
+ :header_params => header_params,
76
+ :query_params => query_params,
77
+ :form_params => form_params,
78
+ :body => post_body,
79
+ :auth_names => auth_names,
80
+ :return_type => return_type
81
+ )
82
+
83
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
84
+ if @api_client.config.debugging
85
+ @api_client.config.logger.debug "API called: LookupWireApi#lookup_batch\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
86
+ end
87
+ return data, status_code, headers
88
+ end
89
+
22
90
  # Lookup
23
91
  # Answers what is known about a single IPv4 or IPv6 address. Which fields come back is decided by the plan behind the presented key; with no key the answer is `ip` and `is_vpn`.
24
92
  # @param ip [String] The IPv4 or IPv6 address to classify.
@@ -9,6 +9,9 @@ module VPNDetection
9
9
  DEFAULT_CONCURRENCY = 8
10
10
  DEFAULT_RETRIES = 2
11
11
  DEFAULT_TIMEOUT = 10
12
+ # The most addresses POST /batch takes in one call; a larger batch is sent in
13
+ # chunks of this size.
14
+ BATCH_MAX = 1000
12
15
 
13
16
  # A client for the VPNDetection API.
14
17
  #
@@ -23,7 +26,7 @@ module VPNDetection
23
26
  # address.
24
27
  # @param cache [Boolean] pass false to disable caching.
25
28
  # @param cache_ttl [Numeric] how long an answer stays fresh, in seconds.
26
- # @param concurrency [Integer] in-flight requests during a batch.
29
+ # @param concurrency [Integer] batch requests - chunks of up to 1000 addresses - in flight during a batch.
27
30
  # @param retries [Integer] extra attempts for a transient failure.
28
31
  # @param transport [Transport, nil] override the HTTP layer, mostly for tests.
29
32
  def initialize(api_key: nil, base_url: DEFAULT_BASE_URL, cache: true,
@@ -108,13 +111,19 @@ module VPNDetection
108
111
  end
109
112
  end
110
113
 
111
- # Classify many addresses in parallel.
114
+ # Classify many addresses in as few requests as possible.
112
115
  #
113
- # Keyed by address rather than positional, so duplicates in the input
114
- # collapse to a single request and the caller never has to line two lists
115
- # up. An address that fails carries its error as its value, so one bad entry
116
- # cannot lose the rest of the answers.
116
+ # Bogons are answered locally and cached answers are reused; everything else
117
+ # goes to the batch endpoint in chunks of up to 1000 addresses, with at most
118
+ # `concurrency` chunks in flight. Keyed by address rather than positional, so
119
+ # duplicates in the input collapse to a single entry and the caller never has
120
+ # to line two lists up. An address that fails carries its error as its value,
121
+ # so one bad entry cannot lose the rest of the answers: the API reports a
122
+ # per-entry failure with the status the single lookup would have answered,
123
+ # and a chunk that fails as a whole marks every address in it.
117
124
  #
125
+ # @param concurrency [Integer, nil] chunks in flight, for THIS batch only.
126
+ # @param retries [Integer, nil] extra attempts for a failed chunk, for THIS batch only.
118
127
  # @return [Hash{String => Result, Error}] in the order the addresses were given
119
128
  def lookup_batch(ips, concurrency: nil, retries: nil)
120
129
  addresses = ips.to_a.uniq
@@ -126,7 +135,8 @@ module VPNDetection
126
135
  hit.nil? ? pending << ip : answers[ip] = hit
127
136
  end
128
137
  unless pending.empty?
129
- run_batch(pending, answers, concurrency || @concurrency, retries || @retries)
138
+ run_batch(pending.each_slice(BATCH_MAX).to_a, answers,
139
+ concurrency || @concurrency, retries || @retries)
130
140
  end
131
141
 
132
142
  # Reinstated in input order: a hydra settles in completion order, and a
@@ -138,37 +148,58 @@ module VPNDetection
138
148
 
139
149
  # One hydra per call, sized for THIS call. Reusing an instance-level hydra
140
150
  # would silently cap a per-call concurrency at the client's setting, and
141
- # would not be safe to drive from two threads either.
142
- def run_batch(pending, answers, concurrency, retries)
151
+ # would not be safe to drive from two threads either. Each request is one
152
+ # chunk of up to 1000 addresses.
153
+ def run_batch(chunks, answers, concurrency, retries)
143
154
  hydra = Typhoeus::Hydra.new(max_concurrency: concurrency)
144
155
  attempts = Hash.new(0)
145
156
 
146
- enqueue = lambda do |ip|
147
- request = @transport.lookup_request(ip)
157
+ enqueue = lambda do |chunk|
158
+ request = @transport.batch_request(chunk)
148
159
  request.on_complete do |response|
149
- outcome = settle(ip, response, attempts, retries, enqueue)
150
- answers[ip] = outcome unless outcome.nil?
160
+ outcome = settle(chunk, response, attempts, retries, enqueue)
161
+ answers.merge!(outcome) unless outcome.nil?
151
162
  end
152
163
  hydra.queue(request)
153
164
  end
154
165
 
155
- pending.each { |ip| enqueue.call(ip) }
166
+ chunks.each { |chunk| enqueue.call(chunk) }
156
167
  hydra.run
157
168
  end
158
169
 
159
- def settle(ip, response, attempts, retries, enqueue)
160
- result = Transport.lookup_result(response)
161
- @cache&.set(ip, result)
162
- result
170
+ # One POST /batch, mapped back onto the addresses it was asked about. A
171
+ # chunk-level failure - the call refused, the transport failing, the retries
172
+ # exhausted - becomes every address's error, exactly as it would have been
173
+ # had each been looked up alone.
174
+ def settle(chunk, response, attempts, retries, enqueue)
175
+ body = Transport.batch_body(response)
176
+ chunk.to_h do |ip|
177
+ answer = batch_answer(ip, body)
178
+ @cache&.set(ip, answer) if answer.is_a?(Result)
179
+ [ip, answer]
180
+ end
163
181
  rescue Error => e
164
- return e unless e.retryable? && attempts[ip] < retries
182
+ return chunk.to_h { |ip| [ip, e] } unless e.retryable? && attempts[chunk] < retries
165
183
 
166
- attempts[ip] += 1
184
+ attempts[chunk] += 1
167
185
  # Sleeping here stalls the whole hydra, which is what a server-supplied
168
186
  # delay asks for: it is telling every request to this host to back off.
169
- sleep(Retries.delay_for(e, attempts[ip]))
170
- enqueue.call(ip)
187
+ sleep(Retries.delay_for(e, attempts[chunk]))
188
+ enqueue.call(chunk)
171
189
  nil
172
190
  end
191
+
192
+ # Every address lands in exactly one of `results` and `errors`; an address in
193
+ # neither is the server breaking its own contract, and is reported as such
194
+ # rather than lost.
195
+ def batch_answer(ip, body)
196
+ if (served = body['results'][ip])
197
+ Result.new(served)
198
+ elsif (failed = body['errors'][ip])
199
+ Error.from_entry(failed['status'], failed['error'])
200
+ else
201
+ Error.new(:server_error, "the batch answer did not include #{ip}", status: 200)
202
+ end
203
+ end
173
204
  end
174
205
  end
@@ -67,6 +67,13 @@ module VPNDetection
67
67
  new(:network, message)
68
68
  end
69
69
 
70
+ # A per-entry failure inside a successful batch: the status the single lookup
71
+ # would have answered, and its message, with no headers at all - so a 429
72
+ # here is a spent allowance, which is the only kind the API puts in an entry.
73
+ def self.from_entry(status, message)
74
+ from_status(status.to_i, {}, nil, message: message.to_s)
75
+ end
76
+
70
77
  # Case-insensitive, and works with a plain Hash as well as with the
71
78
  # case-blind header object Typhoeus builds from a live response.
72
79
  def self.header(headers, name)
@@ -0,0 +1,193 @@
1
+ =begin
2
+ #VPNDetection API
3
+
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
+
6
+ The version of the OpenAPI document: 2026.09.15
7
+ Contact: support@vpndetection.io
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.25.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module VPNDetection
17
+ # Why one entry of a batch was not answered, as the single lookup would have reported it.
18
+ class BatchLookupError < ApiModelBase
19
+ # The HTTP status `GET /{ip}` would have answered for this entry: `400` for a string that is not an address, `429` for a spent allowance, `500` when the VPN dataset could not be consulted. A `429` here is never a throttle; the whole call is refused instead.
20
+ attr_accessor :status
21
+
22
+ # The same message the single lookup carries for that status.
23
+ attr_accessor :error
24
+
25
+ # Attribute mapping from ruby-style variable name to JSON key.
26
+ def self.attribute_map
27
+ {
28
+ :'status' => :'status',
29
+ :'error' => :'error'
30
+ }
31
+ end
32
+
33
+ # Returns attribute mapping this model knows about
34
+ def self.acceptable_attribute_map
35
+ attribute_map
36
+ end
37
+
38
+ # Returns all the JSON keys this model knows about
39
+ def self.acceptable_attributes
40
+ acceptable_attribute_map.values
41
+ end
42
+
43
+ # Attribute type mapping.
44
+ def self.openapi_types
45
+ {
46
+ :'status' => :'Integer',
47
+ :'error' => :'String'
48
+ }
49
+ end
50
+
51
+ # List of attributes with nullable: true
52
+ def self.openapi_nullable
53
+ Set.new([
54
+ ])
55
+ end
56
+
57
+ # Initializes the object
58
+ # @param [Hash] attributes Model attributes in the form of hash
59
+ def initialize(attributes = {})
60
+ if (!attributes.is_a?(Hash))
61
+ fail ArgumentError, "The input argument (attributes) must be a hash in `VPNDetection::BatchLookupError` initialize method"
62
+ end
63
+
64
+ # check to see if the attribute exists and convert string to symbol for hash key
65
+ acceptable_attribute_map = self.class.acceptable_attribute_map
66
+ attributes = attributes.each_with_object({}) { |(k, v), h|
67
+ if (!acceptable_attribute_map.key?(k.to_sym))
68
+ fail ArgumentError, "`#{k}` is not a valid attribute in `VPNDetection::BatchLookupError`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
69
+ end
70
+ h[k.to_sym] = v
71
+ }
72
+
73
+ if attributes.key?(:'status')
74
+ self.status = attributes[:'status']
75
+ else
76
+ self.status = nil
77
+ end
78
+
79
+ if attributes.key?(:'error')
80
+ self.error = attributes[:'error']
81
+ else
82
+ self.error = nil
83
+ end
84
+ end
85
+
86
+ # Show invalid properties with the reasons. Usually used together with valid?
87
+ # @return Array for valid properties with the reasons
88
+ def list_invalid_properties
89
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
90
+ invalid_properties = Array.new
91
+ if @status.nil?
92
+ invalid_properties.push('invalid value for "status", status cannot be nil.')
93
+ end
94
+
95
+ if @error.nil?
96
+ invalid_properties.push('invalid value for "error", error cannot be nil.')
97
+ end
98
+
99
+ invalid_properties
100
+ end
101
+
102
+ # Check to see if the all the properties in the model are valid
103
+ # @return true if the model is valid
104
+ def valid?
105
+ warn '[DEPRECATED] the `valid?` method is obsolete'
106
+ return false if @status.nil?
107
+ return false if @error.nil?
108
+ true
109
+ end
110
+
111
+ # Custom attribute writer method with validation
112
+ # @param [Object] status Value to be assigned
113
+ def status=(status)
114
+ if status.nil?
115
+ fail ArgumentError, 'status cannot be nil'
116
+ end
117
+
118
+ @status = status
119
+ end
120
+
121
+ # Custom attribute writer method with validation
122
+ # @param [Object] error Value to be assigned
123
+ def error=(error)
124
+ if error.nil?
125
+ fail ArgumentError, 'error cannot be nil'
126
+ end
127
+
128
+ @error = error
129
+ end
130
+
131
+ # Checks equality by comparing each attribute.
132
+ # @param [Object] Object to be compared
133
+ def ==(o)
134
+ return true if self.equal?(o)
135
+ self.class == o.class &&
136
+ status == o.status &&
137
+ error == o.error
138
+ end
139
+
140
+ # @see the `==` method
141
+ # @param [Object] Object to be compared
142
+ def eql?(o)
143
+ self == o
144
+ end
145
+
146
+ # Calculates hash code according to all attributes.
147
+ # @return [Integer] Hash code
148
+ def hash
149
+ [status, error].hash
150
+ end
151
+
152
+ # Builds the object from hash
153
+ # @param [Hash] attributes Model attributes in the form of hash
154
+ # @return [Object] Returns the model itself
155
+ def self.build_from_hash(attributes)
156
+ return nil unless attributes.is_a?(Hash)
157
+ attributes = attributes.transform_keys(&:to_sym)
158
+ transformed_hash = {}
159
+ openapi_types.each_pair do |key, type|
160
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
161
+ transformed_hash["#{key}"] = nil
162
+ elsif type =~ /\AArray<(.*)>/i
163
+ # check to ensure the input is an array given that the attribute
164
+ # is documented as an array but the input is not
165
+ if attributes[attribute_map[key]].is_a?(Array)
166
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
167
+ end
168
+ elsif !attributes[attribute_map[key]].nil?
169
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
170
+ end
171
+ end
172
+ new(transformed_hash)
173
+ end
174
+
175
+ # Returns the object in the form of hash
176
+ # @return [Hash] Returns the object in the form of hash
177
+ def to_hash
178
+ hash = {}
179
+ self.class.attribute_map.each_pair do |attr, param|
180
+ value = self.send(attr)
181
+ if value.nil?
182
+ is_nullable = self.class.openapi_nullable.include?(attr)
183
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
184
+ end
185
+
186
+ hash[param] = _to_hash(value)
187
+ end
188
+ hash
189
+ end
190
+
191
+ end
192
+
193
+ end
@@ -0,0 +1,185 @@
1
+ =begin
2
+ #VPNDetection API
3
+
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
+
6
+ The version of the OpenAPI document: 2026.09.15
7
+ Contact: support@vpndetection.io
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.25.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module VPNDetection
17
+ class BatchLookupRequest < ApiModelBase
18
+ # The addresses to classify, 1 to 1000 per call, counted before duplicates collapse. Each distinct string is one lookup.
19
+ attr_accessor :ips
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :'ips' => :'ips'
25
+ }
26
+ end
27
+
28
+ # Returns attribute mapping this model knows about
29
+ def self.acceptable_attribute_map
30
+ attribute_map
31
+ end
32
+
33
+ # Returns all the JSON keys this model knows about
34
+ def self.acceptable_attributes
35
+ acceptable_attribute_map.values
36
+ end
37
+
38
+ # Attribute type mapping.
39
+ def self.openapi_types
40
+ {
41
+ :'ips' => :'Array<String>'
42
+ }
43
+ end
44
+
45
+ # List of attributes with nullable: true
46
+ def self.openapi_nullable
47
+ Set.new([
48
+ ])
49
+ end
50
+
51
+ # Initializes the object
52
+ # @param [Hash] attributes Model attributes in the form of hash
53
+ def initialize(attributes = {})
54
+ if (!attributes.is_a?(Hash))
55
+ fail ArgumentError, "The input argument (attributes) must be a hash in `VPNDetection::BatchLookupRequest` initialize method"
56
+ end
57
+
58
+ # check to see if the attribute exists and convert string to symbol for hash key
59
+ acceptable_attribute_map = self.class.acceptable_attribute_map
60
+ attributes = attributes.each_with_object({}) { |(k, v), h|
61
+ if (!acceptable_attribute_map.key?(k.to_sym))
62
+ fail ArgumentError, "`#{k}` is not a valid attribute in `VPNDetection::BatchLookupRequest`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
63
+ end
64
+ h[k.to_sym] = v
65
+ }
66
+
67
+ if attributes.key?(:'ips')
68
+ if (value = attributes[:'ips']).is_a?(Array)
69
+ self.ips = value
70
+ end
71
+ else
72
+ self.ips = nil
73
+ end
74
+ end
75
+
76
+ # Show invalid properties with the reasons. Usually used together with valid?
77
+ # @return Array for valid properties with the reasons
78
+ def list_invalid_properties
79
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
80
+ invalid_properties = Array.new
81
+ if @ips.nil?
82
+ invalid_properties.push('invalid value for "ips", ips cannot be nil.')
83
+ end
84
+
85
+ if @ips.length > 1000
86
+ invalid_properties.push('invalid value for "ips", number of items must be less than or equal to 1000.')
87
+ end
88
+
89
+ if @ips.length < 1
90
+ invalid_properties.push('invalid value for "ips", number of items must be greater than or equal to 1.')
91
+ end
92
+
93
+ invalid_properties
94
+ end
95
+
96
+ # Check to see if the all the properties in the model are valid
97
+ # @return true if the model is valid
98
+ def valid?
99
+ warn '[DEPRECATED] the `valid?` method is obsolete'
100
+ return false if @ips.nil?
101
+ return false if @ips.length > 1000
102
+ return false if @ips.length < 1
103
+ true
104
+ end
105
+
106
+ # Custom attribute writer method with validation
107
+ # @param [Object] ips Value to be assigned
108
+ def ips=(ips)
109
+ if ips.nil?
110
+ fail ArgumentError, 'ips cannot be nil'
111
+ end
112
+
113
+ if ips.length > 1000
114
+ fail ArgumentError, 'invalid value for "ips", number of items must be less than or equal to 1000.'
115
+ end
116
+
117
+ if ips.length < 1
118
+ fail ArgumentError, 'invalid value for "ips", number of items must be greater than or equal to 1.'
119
+ end
120
+
121
+ @ips = ips
122
+ end
123
+
124
+ # Checks equality by comparing each attribute.
125
+ # @param [Object] Object to be compared
126
+ def ==(o)
127
+ return true if self.equal?(o)
128
+ self.class == o.class &&
129
+ ips == o.ips
130
+ end
131
+
132
+ # @see the `==` method
133
+ # @param [Object] Object to be compared
134
+ def eql?(o)
135
+ self == o
136
+ end
137
+
138
+ # Calculates hash code according to all attributes.
139
+ # @return [Integer] Hash code
140
+ def hash
141
+ [ips].hash
142
+ end
143
+
144
+ # Builds the object from hash
145
+ # @param [Hash] attributes Model attributes in the form of hash
146
+ # @return [Object] Returns the model itself
147
+ def self.build_from_hash(attributes)
148
+ return nil unless attributes.is_a?(Hash)
149
+ attributes = attributes.transform_keys(&:to_sym)
150
+ transformed_hash = {}
151
+ openapi_types.each_pair do |key, type|
152
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
153
+ transformed_hash["#{key}"] = nil
154
+ elsif type =~ /\AArray<(.*)>/i
155
+ # check to ensure the input is an array given that the attribute
156
+ # is documented as an array but the input is not
157
+ if attributes[attribute_map[key]].is_a?(Array)
158
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
159
+ end
160
+ elsif !attributes[attribute_map[key]].nil?
161
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
162
+ end
163
+ end
164
+ new(transformed_hash)
165
+ end
166
+
167
+ # Returns the object in the form of hash
168
+ # @return [Hash] Returns the object in the form of hash
169
+ def to_hash
170
+ hash = {}
171
+ self.class.attribute_map.each_pair do |attr, param|
172
+ value = self.send(attr)
173
+ if value.nil?
174
+ is_nullable = self.class.openapi_nullable.include?(attr)
175
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
176
+ end
177
+
178
+ hash[param] = _to_hash(value)
179
+ end
180
+ hash
181
+ end
182
+
183
+ end
184
+
185
+ end
@@ -0,0 +1,196 @@
1
+ =begin
2
+ #VPNDetection API
3
+
4
+ #The VPNDetection API: classify any IP address, and download the databases behind the answers. See https://docs.vpndetection.io for guides and https://github.com/vpndetection-io for the official client libraries.
5
+
6
+ The version of the OpenAPI document: 2026.09.15
7
+ Contact: support@vpndetection.io
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.25.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module VPNDetection
17
+ class BatchLookupResponse < ApiModelBase
18
+ # One answer per input string that was classified, keyed by the string as you sent it; the `ip` inside is the normalized form. Each value is exactly what `GET /{ip}` answers for your plan.
19
+ attr_accessor :results
20
+
21
+ # One entry per input string that could not be classified, keyed the same way. Empty when every entry was answered.
22
+ attr_accessor :errors
23
+
24
+ # Attribute mapping from ruby-style variable name to JSON key.
25
+ def self.attribute_map
26
+ {
27
+ :'results' => :'results',
28
+ :'errors' => :'errors'
29
+ }
30
+ end
31
+
32
+ # Returns attribute mapping this model knows about
33
+ def self.acceptable_attribute_map
34
+ attribute_map
35
+ end
36
+
37
+ # Returns all the JSON keys this model knows about
38
+ def self.acceptable_attributes
39
+ acceptable_attribute_map.values
40
+ end
41
+
42
+ # Attribute type mapping.
43
+ def self.openapi_types
44
+ {
45
+ :'results' => :'Hash<String, LookupResponse>',
46
+ :'errors' => :'Hash<String, BatchLookupError>'
47
+ }
48
+ end
49
+
50
+ # List of attributes with nullable: true
51
+ def self.openapi_nullable
52
+ Set.new([
53
+ ])
54
+ end
55
+
56
+ # Initializes the object
57
+ # @param [Hash] attributes Model attributes in the form of hash
58
+ def initialize(attributes = {})
59
+ if (!attributes.is_a?(Hash))
60
+ fail ArgumentError, "The input argument (attributes) must be a hash in `VPNDetection::BatchLookupResponse` initialize method"
61
+ end
62
+
63
+ # check to see if the attribute exists and convert string to symbol for hash key
64
+ acceptable_attribute_map = self.class.acceptable_attribute_map
65
+ attributes = attributes.each_with_object({}) { |(k, v), h|
66
+ if (!acceptable_attribute_map.key?(k.to_sym))
67
+ fail ArgumentError, "`#{k}` is not a valid attribute in `VPNDetection::BatchLookupResponse`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
68
+ end
69
+ h[k.to_sym] = v
70
+ }
71
+
72
+ if attributes.key?(:'results')
73
+ if (value = attributes[:'results']).is_a?(Hash)
74
+ self.results = value
75
+ end
76
+ else
77
+ self.results = nil
78
+ end
79
+
80
+ if attributes.key?(:'errors')
81
+ if (value = attributes[:'errors']).is_a?(Hash)
82
+ self.errors = value
83
+ end
84
+ else
85
+ self.errors = nil
86
+ end
87
+ end
88
+
89
+ # Show invalid properties with the reasons. Usually used together with valid?
90
+ # @return Array for valid properties with the reasons
91
+ def list_invalid_properties
92
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
93
+ invalid_properties = Array.new
94
+ if @results.nil?
95
+ invalid_properties.push('invalid value for "results", results cannot be nil.')
96
+ end
97
+
98
+ if @errors.nil?
99
+ invalid_properties.push('invalid value for "errors", errors cannot be nil.')
100
+ end
101
+
102
+ invalid_properties
103
+ end
104
+
105
+ # Check to see if the all the properties in the model are valid
106
+ # @return true if the model is valid
107
+ def valid?
108
+ warn '[DEPRECATED] the `valid?` method is obsolete'
109
+ return false if @results.nil?
110
+ return false if @errors.nil?
111
+ true
112
+ end
113
+
114
+ # Custom attribute writer method with validation
115
+ # @param [Object] results Value to be assigned
116
+ def results=(results)
117
+ if results.nil?
118
+ fail ArgumentError, 'results cannot be nil'
119
+ end
120
+
121
+ @results = results
122
+ end
123
+
124
+ # Custom attribute writer method with validation
125
+ # @param [Object] errors Value to be assigned
126
+ def errors=(errors)
127
+ if errors.nil?
128
+ fail ArgumentError, 'errors cannot be nil'
129
+ end
130
+
131
+ @errors = errors
132
+ end
133
+
134
+ # Checks equality by comparing each attribute.
135
+ # @param [Object] Object to be compared
136
+ def ==(o)
137
+ return true if self.equal?(o)
138
+ self.class == o.class &&
139
+ results == o.results &&
140
+ errors == o.errors
141
+ end
142
+
143
+ # @see the `==` method
144
+ # @param [Object] Object to be compared
145
+ def eql?(o)
146
+ self == o
147
+ end
148
+
149
+ # Calculates hash code according to all attributes.
150
+ # @return [Integer] Hash code
151
+ def hash
152
+ [results, errors].hash
153
+ end
154
+
155
+ # Builds the object from hash
156
+ # @param [Hash] attributes Model attributes in the form of hash
157
+ # @return [Object] Returns the model itself
158
+ def self.build_from_hash(attributes)
159
+ return nil unless attributes.is_a?(Hash)
160
+ attributes = attributes.transform_keys(&:to_sym)
161
+ transformed_hash = {}
162
+ openapi_types.each_pair do |key, type|
163
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
164
+ transformed_hash["#{key}"] = nil
165
+ elsif type =~ /\AArray<(.*)>/i
166
+ # check to ensure the input is an array given that the attribute
167
+ # is documented as an array but the input is not
168
+ if attributes[attribute_map[key]].is_a?(Array)
169
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
170
+ end
171
+ elsif !attributes[attribute_map[key]].nil?
172
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
173
+ end
174
+ end
175
+ new(transformed_hash)
176
+ end
177
+
178
+ # Returns the object in the form of hash
179
+ # @return [Hash] Returns the object in the form of hash
180
+ def to_hash
181
+ hash = {}
182
+ self.class.attribute_map.each_pair do |attr, param|
183
+ value = self.send(attr)
184
+ if value.nil?
185
+ is_nullable = self.class.openapi_nullable.include?(attr)
186
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
187
+ end
188
+
189
+ hash[param] = _to_hash(value)
190
+ end
191
+ hash
192
+ end
193
+
194
+ end
195
+
196
+ end
@@ -15,6 +15,7 @@ module VPNDetection
15
15
  LOOKUP_PATH = '/{ip}'
16
16
  MYIP_PATH = '/myip'
17
17
  ENTITLEMENT_PATH = '/api/v1/entitlement'
18
+ BATCH_PATH = '/batch'
18
19
 
19
20
  # The generated Configuration applies EVERY security scheme the spec lists,
20
21
  # so a keyless client would send `Authorization: Bearer `, an empty
@@ -107,6 +108,16 @@ module VPNDetection
107
108
  )
108
109
  end
109
110
 
111
+ # The one request with a body: the batch.
112
+ def batch_request(ips)
113
+ build_request(
114
+ :POST, BATCH_PATH,
115
+ header_params: { 'Accept' => 'application/json', 'Content-Type' => 'application/json' },
116
+ body: { ips: ips },
117
+ auth_names: %w[bearerAuth apiKeyHeader apiKeyQuery],
118
+ )
119
+ end
120
+
110
121
  def self.entitlement_result(response)
111
122
  raise Error.from_transport(response) if transport_failure?(response)
112
123
  raise Error.from_status(response.code, response.headers, response.body) unless response.success?
@@ -121,6 +132,18 @@ module VPNDetection
121
132
  Result.new(parse_object(response))
122
133
  end
123
134
 
135
+ # The two maps of a batch answer, each present even when empty.
136
+ def self.batch_body(response)
137
+ raise Error.from_transport(response) if transport_failure?(response)
138
+ raise Error.from_status(response.code, response.headers, response.body) unless response.success?
139
+
140
+ body = parse_object(response)
141
+ {
142
+ 'results' => body['results'].is_a?(Hash) ? body['results'] : {},
143
+ 'errors' => body['errors'].is_a?(Hash) ? body['errors'] : {},
144
+ }
145
+ end
146
+
124
147
  def self.transport_failure?(response)
125
148
  response.timed_out? || response.code.to_i.zero?
126
149
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VPNDetection
4
- VERSION = '5.0.0'
4
+ VERSION = '5.1.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vpndetection
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mslm Dev
@@ -78,6 +78,9 @@ files:
78
78
  - lib/vpndetection/models/account_user.rb
79
79
  - lib/vpndetection/models/apikey_detail.rb
80
80
  - lib/vpndetection/models/apikey_list.rb
81
+ - lib/vpndetection/models/batch_lookup_error.rb
82
+ - lib/vpndetection/models/batch_lookup_request.rb
83
+ - lib/vpndetection/models/batch_lookup_response.rb
81
84
  - lib/vpndetection/models/class_detail.rb
82
85
  - lib/vpndetection/models/database.rb
83
86
  - lib/vpndetection/models/database_checksums_response.rb