Skip to content

Commit

Permalink
feat: add Photos.download(location) (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaugold authored Jan 2, 2024
1 parent d24b1be commit 2222cc3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/src/photos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,15 @@ class Photos {
/// properties instead) or to direct the user to the downloaded photo (use the
/// photo.urls.full instead), it is for tracking purposes only.
///
/// To follow the [guidelines](https://help.unsplash.com/en/articles/2511258-guideline-triggering-a-download)
/// you should pass the [Photo.links.downloadLocation] to [location], to
/// include all the necessary information.
///
/// See: [Unsplash docs](https://unsplash.com/documentation#track-a-photo-download)
Request<TrackPhotoDownload> download(String id) {
final url = baseUrl.resolve('$id/download');
Request<TrackPhotoDownload> download(String id, {Uri? location}) {
final url = baseUrl
.resolve('$id/download')
.replace(queryParameters: location?.queryParameters ?? const {});

return Request(
client: client,
Expand Down
14 changes: 14 additions & 0 deletions test/photos_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,19 @@ void main() {
),
);
});

test('download with location', () async {
final req = client.photos
.download('id', location: Uri(queryParameters: {'a': 'b'}));

expect(
req.httpRequest,
matchHttpRequest(
method: 'GET',
path: client.photos.baseUrl.resolve('id/download').path,
queryParameters: {'a': 'b'},
),
);
});
});
}

0 comments on commit 2222cc3

Please # to comment.