vpndetection 4.0.0 → 4.0.1

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: a5e55f291802dac250f1170cbc48751d463f5fb2a0c182a69301fe1627c245a5
4
- data.tar.gz: c8dc05902e2c94bc9a843897717684883bdc9429e36682c9c20b5486862da66a
3
+ metadata.gz: 164314052bfd32f74acb272ff59c077ab1a841395c9818954ea83f6b167464ce
4
+ data.tar.gz: e41ccca025ec996d64861e26ba7fc6c3bbcca85628d9c402dedc35f372f96f6d
5
5
  SHA512:
6
- metadata.gz: '0186489fad83fb671a47344cf3a5c63dbfaa05cab0b905c8dbeaa4c70c7305f36c3062828f747532b92be13f185659aa4fb282f6a4245557fc1b0328d757d42c'
7
- data.tar.gz: e2cec75355df5c8d328939857e6249c22980bf8e4d90210297aa4b78ceb3e4c7491a53f37dfa41657b982c046a900ee379ff99cc8f10cf1ad8a68f07b31fd7e5
6
+ metadata.gz: 7b65573bf40eed189922a26a7131225bf1ba805a671404dd506a23d948e4ca98b2b4bf774dbeb3bcffdc1b7821fad819c3d9d19e75dbcf8ab46470c4a8a2f26d
7
+ data.tar.gz: c9685a07643394cd7eef10034b740fb119bf1d16d89be927baf80f8db342e99fb0aa5ba073614196ba31d32e84c4e3ddebdf594e9d919afac193e38c78326e1b
@@ -67,6 +67,47 @@ module VPNDetection
67
67
  result
68
68
  end
69
69
 
70
+ # Classify the address this client is calling from.
71
+ #
72
+ # The same answer {#lookup} would give for that address, at the same cost
73
+ # against your allowance. The address is the one our edge observed, so a
74
+ # call made through a proxy or a VPN reports the exit it left through -
75
+ # usually the point of asking.
76
+ #
77
+ # Deliberately NOT cached. The cache is keyed by address, and which address
78
+ # this is IS the question: a machine that moves between networks would
79
+ # otherwise be told where it used to be.
80
+ def my_ip(retries: nil)
81
+ Retries.with_retries(retries || @retries) do
82
+ Transport.lookup_result(@transport.myip_request.run)
83
+ end
84
+ end
85
+
86
+ # What this client's key is entitled to, and how much of it has been used.
87
+ #
88
+ # Named for what it answers rather than `me`, which sits one letter from
89
+ # {#my_ip} and means something quite different: one is which address you are
90
+ # calling FROM, the other is which account you are calling AS.
91
+ #
92
+ # Unlike a lookup there is no useful unauthenticated answer, so a client
93
+ # built without an API key gets an unauthorized error rather than a partial
94
+ # one.
95
+ #
96
+ # Usage counts against the ALLOWANCE WINDOW - the anniversary of the
97
+ # subscription, not the calendar month and not the billing period - and it
98
+ # is the same number a lookup is gated on. It can lag by a few seconds,
99
+ # because requests are counted in memory and flushed in aggregate.
100
+ #
101
+ # Deliberately NOT cached: the whole point is what has been spent, and a
102
+ # cached answer is a wrong one within seconds of the next request.
103
+ #
104
+ # @return [AccountMe]
105
+ def my_account(retries: nil)
106
+ Retries.with_retries(retries || @retries) do
107
+ Transport.account_result(@transport.account_request.run)
108
+ end
109
+ end
110
+
70
111
  # Classify many addresses in parallel.
71
112
  #
72
113
  # Keyed by address rather than positional, so duplicates in the input
@@ -274,10 +274,6 @@ module VPNDetection
274
274
  {
275
275
  url: "https://api.vpndetection.io",
276
276
  description: "Production",
277
- },
278
- {
279
- url: "https://api-staging.vpndetection.io",
280
- description: "Staging",
281
277
  }
282
278
  ]
283
279
  end
@@ -13,6 +13,8 @@ module VPNDetection
13
13
  # requests to queue them on a hydra and cannot go through the generated
14
14
  # method, which runs each request as it builds it.
15
15
  LOOKUP_PATH = '/{ip}'
16
+ MYIP_PATH = '/myip'
17
+ ACCOUNT_ME_PATH = '/api/v1/account/me'
16
18
 
17
19
  # The generated Configuration applies EVERY security scheme the spec lists,
18
20
  # so a keyless client would send `Authorization: Bearer `, an empty
@@ -89,6 +91,29 @@ module VPNDetection
89
91
  )
90
92
  end
91
93
 
94
+ def myip_request
95
+ build_request(
96
+ :GET, MYIP_PATH,
97
+ header_params: { 'Accept' => 'application/json' },
98
+ auth_names: %w[bearerAuth apiKeyHeader apiKeyQuery],
99
+ )
100
+ end
101
+
102
+ def account_request
103
+ build_request(
104
+ :GET, ACCOUNT_ME_PATH,
105
+ header_params: { 'Accept' => 'application/json' },
106
+ auth_names: %w[bearerAuth apiKeyHeader apiKeyQuery],
107
+ )
108
+ end
109
+
110
+ def self.account_result(response)
111
+ raise Error.from_transport(response) if transport_failure?(response)
112
+ raise Error.from_status(response.code, response.headers, response.body) unless response.success?
113
+
114
+ AccountMe.build_from_hash(parse_object(response))
115
+ end
116
+
92
117
  def self.lookup_result(response)
93
118
  raise Error.from_transport(response) if transport_failure?(response)
94
119
  raise Error.from_status(response.code, response.headers, response.body) unless response.success?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VPNDetection
4
- VERSION = '4.0.0'
4
+ VERSION = '4.0.1'
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: 4.0.0
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mslm Dev