Files
umbrix/lib/features/proxy/model/ip_info_entity.dart

137 lines
3.6 KiB
Dart
Raw Permalink Normal View History

2024-02-08 20:21:06 +03:30
import 'package:dart_mappable/dart_mappable.dart';
part 'ip_info_entity.mapper.dart';
@MappableClass()
class IpInfo with IpInfoMappable {
const IpInfo({
required this.ip,
required this.countryCode,
2024-02-21 22:25:20 +01:00
this.region,
this.city,
2024-02-08 20:21:06 +03:30
this.timezone,
this.asn,
this.org,
});
final String ip;
final String countryCode;
2024-02-21 22:25:20 +01:00
final String? region;
final String? city;
2024-02-08 20:21:06 +03:30
final String? timezone;
final String? asn;
final String? org;
static IpInfo fromIpInfoIoJson(Map<String, dynamic> json) {
return switch (json) {
{
"ip": final String ip,
"country": final String country,
2024-02-21 22:25:20 +01:00
// "region": final String region, //sometime is not available
// "city": final String city,//sometime is not available
2024-02-08 20:21:06 +03:30
"timezone": final String timezone,
"org": final String org,
} =>
IpInfo(
ip: ip,
countryCode: country,
2024-02-21 22:25:20 +01:00
// region: region,
// city: city,
2024-02-08 20:21:06 +03:30
timezone: timezone,
org: org,
),
_ => throw const FormatException("invalid json"),
};
}
static IpInfo fromIpApiCoJson(Map<String, dynamic> json) {
return switch (json) {
{
"ip": final String ip,
"country_code": final String countryCode,
2024-02-21 22:25:20 +01:00
// "region": final String region, //sometime is not available
// "city": final String city,//sometime is not available
2024-02-08 20:21:06 +03:30
"timezone": final String timezone,
"asn": final String asn,
"org": final String org,
} =>
IpInfo(
ip: ip,
countryCode: countryCode,
2024-02-21 22:25:20 +01:00
// region: region,
// city: city,
2024-02-08 20:21:06 +03:30
timezone: timezone,
asn: asn,
org: org,
),
_ => throw const FormatException("invalid json"),
};
}
static IpInfo fromIpSbJson(Map<String, dynamic> json) {
return switch (json) {
{
"ip": final String ip,
"country_code": final String countryCode,
2024-02-21 22:25:20 +01:00
// "region": final String region,
// "city": final String city,
"timezone": final String timezone,
"asn": final int asn,
"asn_organization": final String org,
} =>
IpInfo(
ip: ip,
countryCode: countryCode,
2024-02-21 22:25:20 +01:00
// region: region,
// city: city,
timezone: timezone,
asn: '$asn',
org: org,
),
_ => throw const FormatException("invalid json"),
};
}
2024-02-23 00:24:04 +01:00
static IpInfo fromIpwhoIsJson(Map<String, dynamic> json) {
return switch (json) {
{
"ip": final String ip,
"country_code": final String countryCode,
// "region": final String region,
// "city": final String city,
// "timezone": final String timezone,
// "asn": final int asn,
"connection": final Map<String, dynamic> connection,
} =>
IpInfo(
ip: ip,
countryCode: countryCode,
// region: region,
// city: city,
// timezone: timezone,
asn: '$connection["asn"]',
org: '$connection["org"]',
),
_ => throw const FormatException("invalid json"),
};
}
static IpInfo fromGeolocationDbComJson(Map<String, dynamic> json) {
return switch (json) {
{
"ip": final String ip,
"country_code": final String countryCode,
2024-02-21 22:25:20 +01:00
// "state": final String region,
"city": final String city
} =>
IpInfo(
ip: ip,
countryCode: countryCode,
2024-02-21 22:25:20 +01:00
// region: region,
city: city,
),
_ => throw const FormatException("invalid json"),
};
}
2024-02-08 20:21:06 +03:30
}