LCOV - code coverage report
Current view: top level - lib/src - entry.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 11 12 91.7 %
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/contentstack.dart';
       5             : import 'package:contentstack/src/entry_queryable.dart';
       6             : 
       7             : /// An `Entry` is the actual piece of content created using one of
       8             : /// the defined `contenttypes`. Learn more about Entries.
       9             : /// Read more for details of [Entry](https://www.contentstack.com/docs/developers/apis/content-delivery-api/#entries)
      10             : class Entry extends EntryQueryable {
      11             :   final HttpClient _client;
      12             :   final String _contentTypeUid;
      13             :   String _path;
      14             :   final String _uid;
      15             : 
      16             :   ///
      17             :   /// An `Entry` is the actual piece of content created using one of
      18             :   /// the defined `contenttypes`. Learn more about Entries.
      19             :   /// Read more for details of [Entry](https://www.contentstack.com/docs/developers/apis/content-delivery-api/#entries)
      20           2 :   Entry([this._uid, this._client, this._contentTypeUid]) {
      21          10 :     parameter['environment'] = _client.stackHeaders['environment'];
      22           6 :     if (_contentTypeUid != null && _contentTypeUid.isNotEmpty) {
      23           2 :       _path =
      24          10 :           '/${_client.stack.apiVersion}/content_types/$_contentTypeUid/entries';
      25             :     }
      26             :   }
      27             : 
      28             :   /// The Get a `single entry` request fetches a particular
      29             :   /// entry of a content type.
      30             :   ///
      31           1 :   /// Example:
      32           3 :   ///
      33             :   /// ```dart
      34             :   /// import 'package:contentstack/contentstack.dart' as contentstack;
      35             :   /// final contentstack.Stack stack =
      36             :   /// contentstack.Stack('apiKey', 'deliveryToken', 'environment');
      37             :   /// entry = stack.contentType('contentType').entry(entryUid: 'entryUid');
      38             :   /// entry.includeReference('categories');
      39             :   ///      await entry.fetch().then((response) {
      40             :   ///        if(response is Error){
      41             :   ///          print(response.errorMessage);
      42             :   ///        }else{
      43             :   ///          print(response.toString());
      44             :   ///        }
      45             :   ///      }).catchError((onError) {
      46             :   ///        expect('invalid url requested', onError.message);
      47             :   ///      });
      48             :   /// ```
      49             :   ///
      50             :   Future<T> fetch<T, K>() async {
      51             :     if (_uid == null) {
      52             :       throw Exception('Provide entry uid to fetch single entry');
      53             :     }
      54             :     final uri = Uri.https(_client.stack.endpoint, '$_path/$_uid', parameter);
      55             :     return _client.sendRequest<T, K>(uri);
      56             :   }
      57           1 : 
      58           1 :   /// Applies query on entries
      59           0 :   Query query() {
      60             :     return Query(_client, _contentTypeUid);
      61           8 :   }
      62           2 : }

Generated by: LCOV version 1.15