Line data Source code
1 : import 'dart:async'; 2 : import 'package:contentstack/client.dart'; 3 : 4 : /// Assets refer to all the media files (images, videos, PDFs, audio files, and so on) 5 : /// uploaded in your Contentstack repository for future use. These files can be 6 : /// attached and used in multiple entries. Learn more about Assets. 7 : /// https://www.contentstack.com/docs/content-managers/work-with-assets 8 : /// 9 : /// Single Asset 10 : /// This call fetches the latest version of a specific asset of a 11 : /// particular stack. 12 : /// Read more about asset: 13 : /// https://www.contentstack.com/docs/developers/apis/content-delivery-api/#get-a-single-asset 14 : /// 15 : /// * Tip: 16 : /// If no version is mentioned, this request will retrieve the latest published 17 : /// version of the asset. To retrieve a specific version, make use of the 18 : /// version parameter and keep the environment parameter blank. 19 : /// 20 : class Asset { 21 : final HttpClient _client; 22 : final String _uid; 23 : String _urlPath; 24 : final Map<String, String> assetParameter = <String, String>{}; 25 : 26 : /// * [_uid] assetUid: 27 : /// Enter the unique ID of the asset of which you wish to retrieve 28 : /// the details. {Example: blt19c34e5374418484} 29 1 : Asset(this._uid, [this._client]) { 30 5 : assetParameter['environment'] = _client.stackHeaders['environment']; 31 5 : _urlPath = '/${_client.stack.apiVersion}/assets'; 32 : } 33 : 34 : /// 35 : /// Enter the name of the [environment] if you wish to retrieve 36 : /// the assets published in a particular environment. 37 : /// [environment] required 38 : /// 39 1 : void environment(String environment) { 40 2 : assetParameter['environment'] = environment; 41 : } 42 : 43 : 44 : /// 45 : /// Specify the version number of the asset that you wish to retrieve. 46 : /// If the version is not specified, the details of the latest version will be retrieved. 47 : /// To retrieve a specific version, keep the environment parameter blank. 48 : /// [version] required 49 : /// 50 1 : void version(int version) { 51 3 : assetParameter['version'] = version.toString(); 52 : } 53 : 54 : /// 55 : /// include the dimensions (height and width) of the image in the response. 56 : /// Supported image types: JPG, GIF, PNG, WebP, BMP, TIFF, SVG, and PSD. 57 : /// 58 1 : void includeDimension() { 59 2 : assetParameter['include_dimension'] = 'true'; 60 : } 61 : 62 : 63 : /// It fetch single asset data on the basis of the asset uid. 64 1 : Future<T> fetch<T, K>() { 65 3 : if (_uid == null || _uid.isEmpty) {throw Exception('Provide asset uid to fetch single entry');} 66 8 : final uri = Uri.https(_client.stack.endpoint, '$_urlPath/$_uid', assetParameter); 67 2 : return _client.sendRequest<T, K>(uri); 68 : } 69 : 70 : }