-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implements the ability to grab the users IP Address. This is used for location tracking in the backend. We use the IP address to get a loose Geo Location.
- Loading branch information
1 parent
c8a08d1
commit ca7e23e
Showing
8 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'package:dio/dio.dart'; | ||
|
||
class IpAddress { | ||
final String? address; | ||
final DateTime lastUpdatedAt; | ||
|
||
const IpAddress({ | ||
this.address, | ||
required this.lastUpdatedAt, | ||
}); | ||
|
||
bool get isExpired { | ||
// Determine if the IP address is expired | ||
// If the lastUpdatedAt is greater than 1 hour, then it's expired | ||
return address == null || | ||
lastUpdatedAt.difference(DateTime.now()).inSeconds > 3600; | ||
} | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
identical(this, other) || | ||
other is IpAddress && | ||
runtimeType == other.runtimeType && | ||
address == other.address; | ||
|
||
@override | ||
int get hashCode => address.hashCode; | ||
|
||
@override | ||
String toString() { | ||
return "IpAddress(address: $address, lastUpdatedAt: $lastUpdatedAt)"; | ||
} | ||
|
||
static Future<IpAddress> fetchIpAddress() async { | ||
final response = await Dio().get("https://api.ipgeolocation.io/getip"); | ||
if (response.statusCode == null) { | ||
return IpAddress( | ||
address: null, | ||
lastUpdatedAt: DateTime.now(), | ||
); | ||
} | ||
if (response.statusCode! >= 200 && response.statusCode! < 300) { | ||
return IpAddress( | ||
address: response.data['ip'], | ||
lastUpdatedAt: DateTime.now(), | ||
); | ||
} | ||
return IpAddress( | ||
address: null, | ||
lastUpdatedAt: DateTime.now(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:appfit/appfit_event.dart'; | ||
import 'package:appfit/networking/event_digester.dart'; | ||
|
||
class EventDigesterStub implements EventDigester { | ||
@override | ||
final String apiKey = ''; | ||
|
||
@override | ||
final String? appVersion = null; | ||
|
||
@override | ||
final bool enableIpTracking = false; | ||
|
||
EventDigesterStub(); | ||
|
||
@override | ||
Future<void> digest(AppFitEvent event) async {} | ||
|
||
@override | ||
Future<void> batchDigest(List<AppFitEvent> events) async {} | ||
|
||
@override | ||
Future<void> identify(String? userId) async {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters