LCOV - code coverage report
Current view: top level - lib/src - asset_query.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 16 18 88.9 %
Date: 2021-05-07 19:45:01 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:async';
       2             : 
       3             : import 'package:contentstack/client.dart';
       4             : import 'package:contentstack/src/base_query.dart';
       5             : 
       6             : /// This call fetches the list of all the assets of a particular stack.
       7             : /// It also returns the content of each asset in JSON format.
       8             : /// You can also specify the environment of which you wish to get the assets.
       9             : /// Learn more about [Assets](https://www.contentstack.com/docs/developers/apis/content-delivery-api/#all-assets)
      10             : class AssetQuery extends BaseQuery {
      11             :   final HttpClient _client;
      12             :   String _urlPath;
      13           1 : 
      14           5 :   AssetQuery([this._client]) {
      15           5 :     queryParameter['environment'] = _client.stackHeaders['environment'];
      16             :     _urlPath = '/${_client.stack.apiVersion}/assets';
      17             :   }
      18             : 
      19             :   ///
      20             :   /// Enter the name of the [environment] if you wish to retrieve
      21             :   /// the assets published in a particular environment.
      22             :   /// [environment] required
      23             :   ///
      24             :   /// ```dart
      25             :   /// var stack = contentstack.Stack(apiKey, deliveryToken, environment);
      26             :   /// final asset = stack.assetQuery()..environment('development');
      27             :   /// await asset.find().then((response) {
      28             :   ///   print(response);
      29             :   /// }).catchError((error) {
      30             :   ///   print(error['error_code']);
      31             :   /// });
      32           1 :   ///
      33           2 :   void environment(String environment) {
      34             :     queryParameter['environment'] = environment;
      35             :   }
      36             : 
      37             :   /// find is applicable for getting all the available assets based on the query
      38             :   /// ```dart
      39             :   /// var stack = contentstack.Stack(apiKey, deliveryToken, environment);
      40             :   /// await stack.assetQuery().find().then((response) {
      41             :   ///   print(response);
      42             :   /// }).catchError((error) {
      43             :   ///   print(error['error_code']);
      44             :   /// });
      45             :   Future<T> find<T, K>() async {
      46             :     final uri = Uri.https(_client.stack.endpoint, _urlPath, queryParameter);
      47             :     return _client.sendRequest<T, K>(uri);
      48             :   }
      49             : 
      50             :   ///
      51             :   /// To retrieve the count of entries, we have two parameters:
      52           1 :   /// include_count (retrieves entries' details and their count)
      53           3 :   /// and count (retrieves only the count of entries).
      54             :   ///
      55             :   /// Example: If you wish to know the total number of entries in
      56             :   /// the a content type and also retrieve all the data.
      57             :   ///
      58             :   /// ```dart
      59             :   /// var stack = contentstack.Stack(apiKey, deliveryToken, environment);
      60             :   /// final asset = stack.assetQuery()..includeCount();
      61             :   /// await asset.find().then((response) {
      62             :   ///   print(response);
      63             :   /// }).catchError((error) {
      64             :   ///   print(error['error_code']);
      65             :   /// });
      66             :   void includeCount() {
      67             :     queryParameter['include_count'] = 'true';
      68           1 :   }
      69           2 : 
      70             :   ///
      71             :   /// include the dimensions (height and width) of the image in the response.
      72             :   /// Supported image types: JPG, GIF, PNG, WebP, BMP, TIFF, SVG, and PSD.
      73             :   ///
      74             :   /// ```dart
      75             :   /// var stack = contentstack.Stack(apiKey, deliveryToken, environment);
      76             :   /// final asset = stack.assetQuery()..includeDimension();
      77             :   /// await asset.find().then((response) {
      78             :   ///   print(response);
      79             :   /// }).catchError((error) {
      80             :   ///   print(error['error_code']);
      81             :   /// });
      82             :   void includeDimension() {
      83           1 :     queryParameter['include_dimension'] = 'true';
      84           2 :   }
      85             : 
      86             :   ///
      87             :   /// Retrieve the published content of the fallback locale if an entry is not
      88             :   /// localized in specified locale.
      89             :   ///
      90             :   /// ```dart
      91             :   /// var stack = contentstack.Stack(apiKey, deliveryToken, environment);
      92             :   /// final asset = stack.assetQuery()..includeFallback();
      93             :   /// await asset.find().then((response) {
      94             :   ///   print(response);
      95             :   /// }).catchError((error) {
      96             :   ///   print(error['error_code']);
      97             :   /// });
      98             :   void includeFallback() {
      99             :     queryParameter['include_fallback'] = true.toString();
     100             :   }
     101             : 
     102             :   ///
     103           1 :   /// includes the relative URLs of the assets in the response
     104           2 :   ///
     105             :   /// ```dart
     106             :   /// var stack = contentstack.Stack(apiKey, deliveryToken, environment);
     107             :   /// final asset = stack.assetQuery()..relativeUrls();
     108             :   /// await asset.find().then((response) {
     109             :   ///   print(response);
     110             :   /// }).catchError((error) {
     111             :   ///   print(error['error_code']);
     112             :   /// });
     113             :   void relativeUrls() {
     114             :     queryParameter['relative_urls'] = 'true';
     115             :   }
     116             : 
     117             :   ///
     118             :   /// Specify the version number of the asset that you wish to retrieve.
     119           0 :   /// If the version is not specified, the details of the latest
     120           0 :   /// version will be retrieved.
     121             :   /// To retrieve a specific version, keep the environment parameter blank.
     122             :   /// [version] required
     123             :   ///
     124             :   /// ```dart
     125             :   /// var stack = contentstack.Stack(apiKey, deliveryToken, environment);
     126             :   /// final asset = stack.assetQuery()..version(3);
     127             :   /// await asset.find().then((response) {
     128             :   ///   print(response);
     129             :   /// }).catchError((error) {
     130             :   ///   print(error['error_code']);
     131           1 :   /// });
     132           6 :   ///
     133           2 :   void version(int version) {
     134             :     queryParameter['version'] = version.toString();
     135             :   }
     136             : }

Generated by: LCOV version 1.15