getProxyFromCountry method
Gets a proxy from a specific country
Implementation
Future<Proxy?> getProxyFromCountry(String countryCode) async {
if (_validatedProxies.isEmpty) {
try {
await getValidatedProxies();
} catch (e) {
// If we can't get validated proxies, return null
return null;
}
}
// Find a proxy from the specified country
final matchingProxies =
_validatedProxies
.where(
(p) => p.countryCode?.toLowerCase() == countryCode.toLowerCase(),
)
.toList();
if (matchingProxies.isEmpty) {
return null;
}
// Use the rotation strategy to select from the matching proxies
final tempStrategy = RotationStrategyFactory.createStrategy(
type: _strategyType,
proxies: matchingProxies,
);
final proxy = tempStrategy.getNextProxy();
// Track proxy usage
if (proxy != null && _analyticsService != null) {
await _analyticsService.recordRequest(proxy, true, null, 'usage');
}
return proxy;
}