watch_ip_sdk 0.1.2 copy "watch_ip_sdk: ^0.1.2" to clipboard
watch_ip_sdk: ^0.1.2 copied to clipboard

Official Dart/Flutter SDK for the Watch-IP visitor geolocation API (GET /v1/geo).

example/watch_ip_sdk_example.dart

// ignore_for_file: avoid_print
import 'package:watch_ip_sdk/watch_ip_sdk.dart';

Future<void> main() async {
  // The API key is a publishable key meant to ship in client-side code — see
  // https://watch-ip.com/docs for the origin-locking model this relies on.
  final client = WatchIP('wip_pub_xxxxxxxx');

  try {
    final geo = await client.getGeo();
    print('${geo.country} ${geo.city} ${geo.timezone}');

    if (geo.security?.isVpn == true || geo.security?.isTor == true) {
      print('Visitor is connecting through a VPN or Tor.');
    }
  } on WatchIPError catch (e) {
    // e.g. "origin_not_allowed" 403 "This origin is not authorized for this API key."
    print(
        'Watch-IP request failed: ${e.code} (status ${e.status}): ${e.message}');
  }

  // Or, for a one-off call without holding onto a client instance:
  final geo = await getGeo('wip_pub_xxxxxxxx', include: ['hostname']);
  print(geo.hostname);
}
2
likes
160
points
46
downloads

Documentation

Documentation
API reference

Publisher

verified publisherdigitload.ca

Weekly Downloads

Official Dart/Flutter SDK for the Watch-IP visitor geolocation API (GET /v1/geo).

Homepage
Repository (GitHub)

License

MIT (license)

Dependencies

http

More

Packages that depend on watch_ip_sdk