Skip to content

Commit

Permalink
Add missing phone number types to metadata models and update metada (#69
Browse files Browse the repository at this point in the history
)

Co-authored-by: Gianluca Canese <[email protected]>
  • Loading branch information
cottonman132 and Gianluca Canese authored May 28, 2024
1 parent 931fd5a commit 5f4c86f
Show file tree
Hide file tree
Showing 9 changed files with 5,336 additions and 8 deletions.
1,715 changes: 1,715 additions & 0 deletions lib/src/metadata/generated/metadata_examples_by_iso_code.dart

Large diffs are not rendered by default.

1,715 changes: 1,715 additions & 0 deletions lib/src/metadata/generated/metadata_lengths_by_iso_code.dart

Large diffs are not rendered by default.

1,763 changes: 1,763 additions & 0 deletions lib/src/metadata/generated/metadata_patterns_by_iso_code.dart

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions lib/src/metadata/models/phone_metadata_examples.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,39 @@ class PhoneMetadataExamples {
final String mobile;
final String fixedLine;
final String voip;
final String tollFree;
final String premiumRate;
final String sharedCost;
final String personalNumber;
final String uan;
final String pager;
final String voiceMail;

const PhoneMetadataExamples({
required this.mobile,
required this.fixedLine,
required this.voip,
required this.tollFree,
required this.premiumRate,
required this.sharedCost,
required this.personalNumber,
required this.uan,
required this.pager,
required this.voiceMail,
});

Map<String, dynamic> toMap() {
return {
'mobile': mobile,
'fixedLine': fixedLine,
'voip': voip,
'tollFree': tollFree,
'premiumRate': premiumRate,
'sharedCost': sharedCost,
'personalNumber': personalNumber,
'uan': uan,
'pager': pager,
'voiceMail': voiceMail,
};
}

Expand All @@ -22,6 +43,13 @@ class PhoneMetadataExamples {
mobile: map['mobile'] ?? '',
fixedLine: map['fixedLine'] ?? '',
voip: map['voip'] ?? '',
tollFree: map['tollFree'] ?? '',
premiumRate: map['premiumRate'] ?? '',
sharedCost: map['sharedCost'] ?? '',
personalNumber: map['personalNumber'] ?? '',
uan: map['uan'] ?? '',
pager: map['pager'] ?? '',
voiceMail: map['voiceMail'] ?? '',
);
}
}
32 changes: 30 additions & 2 deletions lib/src/metadata/models/phone_metadata_lengths.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,26 @@ class PhoneMetadataLengths {
final List<int> mobile;
final List<int> fixedLine;
final List<int> voip;
final List<int> tollFree;
final List<int> premiumRate;
final List<int> sharedCost;
final List<int> personalNumber;
final List<int> uan;
final List<int> pager;
final List<int> voiceMail;

const PhoneMetadataLengths({
required this.general,
required this.mobile,
required this.fixedLine,
required this.voip,
required this.tollFree,
required this.premiumRate,
required this.sharedCost,
required this.personalNumber,
required this.uan,
required this.pager,
required this.voiceMail,
});

Map<String, dynamic> toMap() {
Expand All @@ -19,6 +33,13 @@ class PhoneMetadataLengths {
'mobile': mobile,
'fixedLine': fixedLine,
'voip': voip,
'tollFree': tollFree,
'premiumRate': premiumRate,
'sharedCost': sharedCost,
'personalNumber': personalNumber,
'uan': uan,
'pager': pager,
'voiceMail': voiceMail,
};
}

Expand All @@ -27,7 +48,14 @@ class PhoneMetadataLengths {
general: List<int>.from(map['general']),
mobile: List<int>.from(map['mobile']),
fixedLine: List<int>.from(map['fixedLine']),
voip: List<int>.from(map['voip']),
voip: List<int>.from(map['voip'] ?? []),
tollFree: List<int>.from(map['tollFree'] ?? []),
premiumRate: List<int>.from(map['premiumRate'] ?? []),
sharedCost: List<int>.from(map['sharedCost'] ?? []),
personalNumber: List<int>.from(map['personalNumber'] ?? []),
uan: List<int>.from(map['uan'] ?? []),
pager: List<int>.from(map['pager'] ?? []),
voiceMail: List<int>.from(map['voiceMail'] ?? []),
);
}

Expand All @@ -38,5 +66,5 @@ class PhoneMetadataLengths {

@override
String toString() =>
'PhoneMetadataLengths(general: $general, mobile: $mobile, fixedLine: $fixedLine, voip: $voip)';
'PhoneMetadataLengths(general: $general, mobile: $mobile, fixedLine: $fixedLine, voip: $voip, tollFree: $tollFree, premiumRate: $premiumRate, shareCost: $sharedCost, personalNumber: $personalNumber, uan: $uan, pager: $pager, voiceMail: $voiceMail)';
}
32 changes: 30 additions & 2 deletions lib/src/metadata/models/phone_metadata_patterns.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ class PhoneMetadataPatterns {
final String mobile;
final String fixedLine;
final String voip;
final String tollFree;
final String premiumRate;
final String sharedCost;
final String personalNumber;
final String uan;
final String pager;
final String voiceMail;

const PhoneMetadataPatterns({
this.nationalPrefixForParsing,
Expand All @@ -16,6 +23,13 @@ class PhoneMetadataPatterns {
required this.mobile,
required this.fixedLine,
required this.voip,
required this.tollFree,
required this.premiumRate,
required this.sharedCost,
required this.personalNumber,
required this.uan,
required this.pager,
required this.voiceMail,
});

Map<String, dynamic> toMap() {
Expand All @@ -26,6 +40,13 @@ class PhoneMetadataPatterns {
'mobile': mobile,
'fixedLine': fixedLine,
'voip': voip,
'tollFree': tollFree,
'premiumRate': premiumRate,
'sharedCost': sharedCost,
'personalNumber': personalNumber,
'uan': uan,
'pager': pager,
'voiceMail': voiceMail,
};
}

Expand All @@ -36,7 +57,14 @@ class PhoneMetadataPatterns {
general: map['general'],
mobile: map['mobile'],
fixedLine: map['fixedLine'],
voip: map['voip'],
voip: map['voip'] ?? '',
tollFree: map['tollFree'] ?? '',
premiumRate: map['premiumRate'] ?? '',
sharedCost: map['sharedCost'] ?? '',
personalNumber: map['personalNumber'] ?? '',
uan: map['uan'] ?? '',
pager: map['pager'] ?? '',
voiceMail: map['voiceMail'] ?? '',
);
}

Expand All @@ -47,6 +75,6 @@ class PhoneMetadataPatterns {

@override
String toString() {
return 'PhoneMetadataPatterns(nationalPrefixForParsing: $nationalPrefixForParsing, nationalPrefixTransformRule: $nationalPrefixTransformRule, general: $general, mobile: $mobile, fixedLine: $fixedLine, voip: $voip)';
return 'PhoneMetadataPatterns(nationalPrefixForParsing: $nationalPrefixForParsing, nationalPrefixTransformRule: $nationalPrefixTransformRule, general: $general, mobile: $mobile, fixedLine: $fixedLine, voip: $voip, tollFree: $tollFree, premiumRate: $premiumRate, sharedCost: $sharedCost, personalNumber: $personalNumber, uan: $uan, pager: $pager, voiceMail: $voiceMail)';
}
}
36 changes: 33 additions & 3 deletions resources/data_sources/convert_metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ Future convertPhoneNumberMetadata() async {

Map convertTerritory(Map<String, dynamic> territory) {
final voip = territory['voip'];
final tollFree = territory['tollFree'];
final premiumRate = territory['premiumRate'];
final sharedCost = territory['sharedCost'];
final personalNumber = territory['personalNumber'];
final uan = territory['uan'];
final pager = territory['pager'];
final voiceMail = territory['voiceMail'];
return {
'isoCode': territory['id'],
'countryCode': territory['countryCode'],
Expand All @@ -44,7 +51,15 @@ Map convertTerritory(Map<String, dynamic> territory) {
// a read on wikipedia
'mobile':
getPossibleLengths(territory['mobile'] ?? territory['fixedLine']),
'voip': voip == null ? const [] : getPossibleLengths(voip),
if (voip != null) 'voip': getPossibleLengths(voip),
if (tollFree != null) 'tollFree': getPossibleLengths(tollFree),
if (premiumRate != null) 'premiumRate': getPossibleLengths(premiumRate),
if (sharedCost != null) 'sharedCost': getPossibleLengths(sharedCost),
if (personalNumber != null)
'personalNumber': getPossibleLengths(personalNumber),
if (uan != null) 'uan': getPossibleLengths(uan),
if (pager != null) 'pager': getPossibleLengths(pager),
if (voiceMail != null) 'voiceMail': getPossibleLengths(voiceMail),
},
'patterns': {
'nationalPrefixForParsing': territory['nationalPrefixForParsing'],
Expand All @@ -53,14 +68,29 @@ Map convertTerritory(Map<String, dynamic> territory) {
'fixedLine': getPattern(territory['fixedLine']),
// see comment on lengths
'mobile': getPattern(territory['mobile'] ?? territory['fixedLine']),
'voip': voip == null ? '' : getPattern(voip),
if (voip != null) 'voip': getPattern(voip),
if (tollFree != null) 'tollFree': getPattern(tollFree),
if (premiumRate != null) 'premiumRate': getPattern(premiumRate),
if (sharedCost != null) 'sharedCost': getPattern(sharedCost),
if (personalNumber != null) 'personalNumber': getPattern(personalNumber),
if (uan != null) 'uan': getPattern(uan),
if (pager != null) 'pager': getPattern(pager),
if (voiceMail != null) 'voiceMail': getPattern(voiceMail),
},
'examples': {
'fixedLine': territory['fixedLine']['exampleNumber'],
// see comment on lengths
'mobile':
(territory['mobile'] ?? territory['fixedLine'])['exampleNumber'],
'voip': voip == null ? null : voip['exampleNumber'],
if (voip != null) 'voip': voip['exampleNumber'],
if (tollFree != null) 'tollFree': tollFree['exampleNumber'],
if (premiumRate != null) 'premiumRate': premiumRate['exampleNumber'],
if (sharedCost != null) 'sharedCost': sharedCost['exampleNumber'],
if (personalNumber != null)
'personalNumber': personalNumber['exampleNumber'],
if (uan != null) 'uan': uan['exampleNumber'],
if (pager != null) 'pager': pager['exampleNumber'],
if (voiceMail != null) 'voiceMail': voiceMail['exampleNumber'],
},
'formats': getFormats(territory['availableFormats']?['numberFormat']),
};
Expand Down
2 changes: 1 addition & 1 deletion resources/data_sources/parsed_phone_number_metadata.json

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions resources/utils/phone_metadata_encoder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ String encodePatterns(PhoneMetadataPatterns metadata) {
mobile: ${_enc(metadata.mobile)},
fixedLine: ${_enc(metadata.fixedLine)},
voip: ${_enc(metadata.voip)},
tollFree: ${_enc(metadata.tollFree)},
premiumRate: ${_enc(metadata.premiumRate)},
sharedCost: ${_enc(metadata.sharedCost)},
personalNumber: ${_enc(metadata.personalNumber)},
uan: ${_enc(metadata.uan)},
pager: ${_enc(metadata.pager)},
voiceMail: ${_enc(metadata.voiceMail)},
)''';
}

Expand All @@ -34,6 +41,13 @@ String encodeLengths(PhoneMetadataLengths lengths) {
mobile: ${_enc(lengths.mobile)},
fixedLine: ${_enc(lengths.fixedLine)},
voip: ${_enc(lengths.voip)},
tollFree: ${_enc(lengths.tollFree)},
premiumRate: ${_enc(lengths.premiumRate)},
sharedCost: ${_enc(lengths.sharedCost)},
personalNumber: ${_enc(lengths.personalNumber)},
uan: ${_enc(lengths.uan)},
pager: ${_enc(lengths.pager)},
voiceMail: ${_enc(lengths.voiceMail)},
)''';
}

Expand All @@ -52,6 +66,13 @@ String encodeExamples(PhoneMetadataExamples examples) {
fixedLine: ${_enc(examples.fixedLine)},
mobile: ${_enc(examples.mobile)},
voip: ${_enc(examples.voip)},
tollFree: ${_enc(examples.tollFree)},
premiumRate: ${_enc(examples.premiumRate)},
sharedCost: ${_enc(examples.sharedCost)},
personalNumber: ${_enc(examples.personalNumber)},
uan: ${_enc(examples.uan)},
pager: ${_enc(examples.pager)},
voiceMail: ${_enc(examples.voiceMail)},
)''';
}

Expand Down

0 comments on commit 5f4c86f

Please sign in to comment.