Skip to content

Commit 25ea064

Browse files
authored
Add support for download counts (#58)
1 parent a917968 commit 25ea064

5 files changed

+25
-0
lines changed

lib/src/models/package_score_model.dart

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class PackageScore with PackageScoreMappable {
88
final int? maxPoints;
99
final int likeCount;
1010
final double? popularityScore;
11+
final int downloadCount30Days;
1112
final List<String> tags;
1213
final DateTime lastUpdated;
1314

@@ -16,6 +17,7 @@ class PackageScore with PackageScoreMappable {
1617
required this.maxPoints,
1718
required this.likeCount,
1819
required this.popularityScore,
20+
required this.downloadCount30Days,
1921
required this.tags,
2022
required this.lastUpdated,
2123
});

lib/src/models/package_score_model.mapper.dart

+11
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class PackageScoreMapper extends ClassMapperBase<PackageScore> {
3232
static double? _$popularityScore(PackageScore v) => v.popularityScore;
3333
static const Field<PackageScore, double> _f$popularityScore =
3434
Field('popularityScore', _$popularityScore);
35+
static int _$downloadCount30Days(PackageScore v) => v.downloadCount30Days;
36+
static const Field<PackageScore, int> _f$downloadCount30Days =
37+
Field('downloadCount30Days', _$downloadCount30Days);
3538
static List<String> _$tags(PackageScore v) => v.tags;
3639
static const Field<PackageScore, List<String>> _f$tags =
3740
Field('tags', _$tags);
@@ -45,6 +48,7 @@ class PackageScoreMapper extends ClassMapperBase<PackageScore> {
4548
#maxPoints: _f$maxPoints,
4649
#likeCount: _f$likeCount,
4750
#popularityScore: _f$popularityScore,
51+
#downloadCount30Days: _f$downloadCount30Days,
4852
#tags: _f$tags,
4953
#lastUpdated: _f$lastUpdated,
5054
};
@@ -55,6 +59,7 @@ class PackageScoreMapper extends ClassMapperBase<PackageScore> {
5559
maxPoints: data.dec(_f$maxPoints),
5660
likeCount: data.dec(_f$likeCount),
5761
popularityScore: data.dec(_f$popularityScore),
62+
downloadCount30Days: data.dec(_f$downloadCount30Days),
5863
tags: data.dec(_f$tags),
5964
lastUpdated: data.dec(_f$lastUpdated));
6065
}
@@ -117,6 +122,7 @@ abstract class PackageScoreCopyWith<$R, $In extends PackageScore, $Out>
117122
int? maxPoints,
118123
int? likeCount,
119124
double? popularityScore,
125+
int? downloadCount30Days,
120126
List<String>? tags,
121127
DateTime? lastUpdated});
122128
PackageScoreCopyWith<$R2, $In, $Out2> $chain<$R2, $Out2>(Then<$Out2, $R2> t);
@@ -140,13 +146,16 @@ class _PackageScoreCopyWithImpl<$R, $Out>
140146
Object? maxPoints = $none,
141147
int? likeCount,
142148
Object? popularityScore = $none,
149+
int? downloadCount30Days,
143150
List<String>? tags,
144151
DateTime? lastUpdated}) =>
145152
$apply(FieldCopyWithData({
146153
if (grantedPoints != $none) #grantedPoints: grantedPoints,
147154
if (maxPoints != $none) #maxPoints: maxPoints,
148155
if (likeCount != null) #likeCount: likeCount,
149156
if (popularityScore != $none) #popularityScore: popularityScore,
157+
if (downloadCount30Days != null)
158+
#downloadCount30Days: downloadCount30Days,
150159
if (tags != null) #tags: tags,
151160
if (lastUpdated != null) #lastUpdated: lastUpdated
152161
}));
@@ -156,6 +165,8 @@ class _PackageScoreCopyWithImpl<$R, $Out>
156165
maxPoints: data.get(#maxPoints, or: $value.maxPoints),
157166
likeCount: data.get(#likeCount, or: $value.likeCount),
158167
popularityScore: data.get(#popularityScore, or: $value.popularityScore),
168+
downloadCount30Days:
169+
data.get(#downloadCount30Days, or: $value.downloadCount30Days),
159170
tags: data.get(#tags, or: $value.tags),
160171
lastUpdated: data.get(#lastUpdated, or: $value.lastUpdated));
161172

lib/src/models/search_order.dart

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ enum SearchOrder {
2121
/// Search order should be in decreasing popularity score.
2222
popularity,
2323

24+
/// Search order should be in decreasing download count.
25+
downloads,
26+
2427
/// Search order should be in decreasing like count.
2528
like,
2629

lib/src/models/search_order.mapper.dart

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class SearchOrderMapper extends EnumMapper<SearchOrder> {
3535
return SearchOrder.updated;
3636
case 'popularity':
3737
return SearchOrder.popularity;
38+
case 'downloads':
39+
return SearchOrder.downloads;
3840
case 'like':
3941
return SearchOrder.like;
4042
case 'points':
@@ -57,6 +59,8 @@ class SearchOrderMapper extends EnumMapper<SearchOrder> {
5759
return 'updated';
5860
case SearchOrder.popularity:
5961
return 'popularity';
62+
case SearchOrder.downloads:
63+
return 'downloads';
6064
case SearchOrder.like:
6165
return 'like';
6266
case SearchOrder.points:

test/pubdev_api_test.dart

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ void main() {
5454
expect(payload.grantedPoints, isNotNull);
5555
expect(payload.likeCount, greaterThan(50));
5656
expect(payload.maxPoints, greaterThan(100));
57+
expect(payload.downloadCount30Days, greaterThan(100));
5758

5859
// Test for packageName2
5960
final payload2 = await _client.packageScore(packageName2);
@@ -62,6 +63,7 @@ void main() {
6263
expect(payload2.grantedPoints, isNotNull);
6364
expect(payload2.likeCount, greaterThan(50));
6465
expect(payload2.maxPoints, greaterThan(100));
66+
expect(payload2.downloadCount30Days, greaterThan(100));
6567
});
6668

6769
test('Get package metrics', () async {
@@ -164,6 +166,7 @@ void main() {
164166
test('Sort search results for packages', () async {
165167
final updated = await _client.search('', sort: SearchOrder.updated);
166168
final popularity = await _client.search('', sort: SearchOrder.popularity);
169+
final downloads = await _client.search('', sort: SearchOrder.downloads);
167170
final points = await _client.search('', sort: SearchOrder.points);
168171
final created = await _client.search('', sort: SearchOrder.created);
169172
final text = await _client.search('', sort: SearchOrder.text);
@@ -173,6 +176,7 @@ void main() {
173176

174177
expect(updated, isNot(popularity));
175178
expect(popularity, isNot(points));
179+
expect(downloads, isNot(popularity));
176180
expect(points, isNot(updated));
177181
expect(updated, isNot(created));
178182
expect(created, isNot(text));
@@ -183,6 +187,7 @@ void main() {
183187

184188
expect(SearchOrder.points.value, 'points');
185189
expect(SearchOrder.popularity.value, 'popularity');
190+
expect(SearchOrder.downloads.value, 'downloads');
186191
expect(SearchOrder.created.value, 'created');
187192
expect(SearchOrder.text.value, 'text');
188193
expect(SearchOrder.top.value, 'top');

0 commit comments

Comments
 (0)