diff --git a/lib/src/photos.dart b/lib/src/photos.dart index 71606d8..d9c3f10 100644 --- a/lib/src/photos.dart +++ b/lib/src/photos.dart @@ -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 download(String id) { - final url = baseUrl.resolve('$id/download'); + Request download(String id, {Uri? location}) { + final url = baseUrl + .resolve('$id/download') + .replace(queryParameters: location?.queryParameters ?? const {}); return Request( client: client, diff --git a/test/photos_test.dart b/test/photos_test.dart index a5aeebd..8fe48de 100644 --- a/test/photos_test.dart +++ b/test/photos_test.dart @@ -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'}, + ), + ); + }); }); }