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 +4 -4
- data/lib/vpndetection/client.rb +41 -0
- data/lib/vpndetection/configuration.rb +0 -4
- data/lib/vpndetection/transport.rb +25 -0
- data/lib/vpndetection/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 164314052bfd32f74acb272ff59c077ab1a841395c9818954ea83f6b167464ce
|
|
4
|
+
data.tar.gz: e41ccca025ec996d64861e26ba7fc6c3bbcca85628d9c402dedc35f372f96f6d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7b65573bf40eed189922a26a7131225bf1ba805a671404dd506a23d948e4ca98b2b4bf774dbeb3bcffdc1b7821fad819c3d9d19e75dbcf8ab46470c4a8a2f26d
|
|
7
|
+
data.tar.gz: c9685a07643394cd7eef10034b740fb119bf1d16d89be927baf80f8db342e99fb0aa5ba073614196ba31d32e84c4e3ddebdf594e9d919afac193e38c78326e1b
|
data/lib/vpndetection/client.rb
CHANGED
|
@@ -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
|
|
@@ -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?
|
data/lib/vpndetection/version.rb
CHANGED