LCOV - code coverage report
Current view: top level - lib/src - contenttype.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 15 15 100.0 %
Date: 2020-05-04 13:08:30 Functions: 0 0 -

          Line data    Source code
       1             : import 'dart:async';
       2             : import 'package:contentstack/client.dart';
       3             : import 'package:contentstack/contentstack.dart';
       4             : import 'package:contentstack/src/contenttype_query.dart';
       5             : 
       6             : ///
       7             : /// Content type defines the structure or schema of a page or a section of your
       8             : /// web or mobile property. To create content for your application, you are
       9             : /// required to first create a content type, and then create entries using the
      10             : /// content type.
      11             : ///
      12             : /// * Read more about Content Types.
      13             : /// https://www.contentstack.com/docs/developers/apis/content-delivery-api/#content-types
      14             : ///
      15             : class ContentType {
      16             :   final String _contentTypeUid;
      17             :   final HttpClient _client;
      18             :   String urlPath;
      19             :   final Map<String, String> _queryParameter = <String, String>{};
      20             : 
      21           1 :   ContentType([this._contentTypeUid, this._client]) {
      22           5 :     _queryParameter['environment'] = _client.stackHeaders['environment'];
      23           3 :     if (_contentTypeUid != null && _contentTypeUid.isNotEmpty) {
      24           6 :       urlPath = '/${_client.stack.apiVersion}/content_types/$_contentTypeUid';
      25             :     }
      26             :   }
      27             : 
      28             :   ///
      29             :   /// This function provide option to  get single entry as well as all the entries.
      30             :   /// [entryUid] is Optional, If [entryUid]  Provided it fetches related entry of a respected content type
      31             :   /// Read more about single entry:
      32             :   /// https://www.contentstack.com/docs/developers/apis/content-delivery-api/#single-entry
      33             : 
      34             :   /// if [entryUid] not provided ,Get all entries call fetches the list of all the entries of a particular content type.
      35             :   /// It also returns the content of each entry in JSON format. You can also specify the environment
      36             :   /// and locale of which you wish to get the entries.
      37             :   /// /// Read more about entries:
      38             :   /// https://www.contentstack.com/docs/developers/apis/content-delivery-api/#all-entries
      39             :   ///
      40             :   /// final entry = stack.contentType('content_type_uid').entry(entryUid: 'entry_uid');
      41             :   /// print(entry);
      42             :   ///
      43           1 :   Entry entry({String entryUid}) {
      44           3 :     return Entry(entryUid, _client, _contentTypeUid);
      45             :   }
      46             : 
      47             :   ///
      48             :   /// Query on ContentType
      49             :   /// This call returns comprehensive information of all the content types
      50             :   /// available in a particular stack in your account
      51             :   ///
      52             :   /// Example:
      53             :   /// final contentTypeQuery = stack.contentType().query();
      54             :   /// final response = contentTypeQuery.find();
      55             :   /// print(response);
      56             :   ///
      57           1 :   ContentTypeQuery query() {
      58           2 :     return ContentTypeQuery(_client);
      59             :   }
      60             : 
      61             :   ///
      62             :   /// This call returns information of a specific content type.
      63             :   /// It returns the content type schema, but does not include its entries.
      64             :   /// [queryParams] query parameters
      65             :   ///
      66             :   /// Example:
      67             :   /// final contentType = stack.contentType("content_type_uid");
      68             :   /// final Map<String, dynamic> queryParameter = <String,dynamic>{};
      69             :   /// queryParameter["include_snippet_schema"] = true;
      70             :   /// queryParameter["limit"] = 3;
      71             :   /// final response = contentType.fetch(queryParameter);
      72             :   /// print(response);
      73             :   ///
      74           1 :   Future<T> fetch<T, K>([Map<String, dynamic> queryParams]) {
      75           1 :     if (urlPath == null) {
      76           1 :       throw Exception('content_type_uid is missing');
      77             :     }
      78           1 :     if (queryParams != null && queryParams.isNotEmpty) {
      79           2 :       _queryParameter.addAll(queryParams);
      80             :     }
      81           6 :     final uri = Uri.https(_client.stack.endpoint, urlPath, _queryParameter);
      82           2 :     return _client.sendRequest<T, K>(uri);
      83             :   }
      84             : }

Generated by: LCOV version 1.14