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/contenttype_query.dart'; 6 : 7 : /// 8 : /// Content type lets you define the structure or blueprint 9 : /// of a page or a section of your digital property. 10 : /// It is a form-like page that gives Content Managers 11 : /// an interface to input and upload content. 12 : /// * Read more about [ContentTypes](https://www.contentstack.com/docs/developers/apis/content-delivery-api/#content-types). 13 : /// 14 : class ContentType { 15 : final String _contentTypeUid; 16 : final HttpClient _client; 17 : String urlPath; 18 : final Map<String, String> _queryParameter = <String, String>{}; 19 4 : 20 20 : ContentType([this._contentTypeUid, this._client]) { 21 12 : _queryParameter['environment'] = _client.stackHeaders['environment']; 22 24 : if (_contentTypeUid != null && _contentTypeUid.isNotEmpty) { 23 : urlPath = '/${_client.stack.apiVersion}/content_types/$_contentTypeUid'; 24 : } 25 : } 26 : 27 : /// 28 : /// This function provide option to get single entry as well as 29 : /// all the entries. [entryUid] is Optional, If [entryUid] 30 : /// 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 35 : /// all the entries of a particular content type. 36 : /// It also returns the content of each entry in JSON format. 37 : /// You can also specify the environment 38 : /// and locale of which you wish to get the entries. 39 : /// /// Read more about entries: 40 : /// https://www.contentstack.com/docs/developers/apis/content-delivery-api/#all-entries 41 : /// 42 : /// ```dart 43 : /// final stack = contentstack.Stack('apiKey','deliveryToken','environment'); 44 : /// final contentType = stack.contentType('content_type_uid'); 45 : /// final entry = contentType.entry(entryUid: 'entry_uid'); 46 : /// 47 : /// ``` 48 2 : /// 49 6 : Entry entry({String entryUid}) { 50 : return Entry(entryUid, _client, _contentTypeUid); 51 : } 52 : 53 : /// 54 : /// This call returns information of a specific content type. 55 : /// It returns the content type schema, but does not include its entries. 56 : /// [queryParams] query parameters 57 : /// 58 : /// Example: 59 : /// 60 : /// ```dart 61 : /// final contentType = stack.contentType("content_type_uid"); 62 : /// final Map<String, dynamic> queryParameter = <String,dynamic>{}; 63 : /// queryParameter["include_snippet_schema"] = true; 64 : /// queryParameter["limit"] = 3; 65 1 : /// final response = contentType.fetch(queryParameter); 66 2 : /// print(response); 67 : /// ``` 68 : /// 69 : Future<T> fetch<T, K>([Map<String, dynamic> queryParams]) { 70 : if (urlPath == null) { 71 : throw Exception('content_type_uid is missing'); 72 : } 73 : if (queryParams != null && queryParams.isNotEmpty) { 74 : _queryParameter.addAll(queryParams); 75 : } 76 : final uri = Uri.https(_client.stack.endpoint, urlPath, _queryParameter); 77 : return _client.sendRequest<T, K>(uri); 78 : } 79 : 80 : /// 81 : /// Query on ContentType 82 : /// This call returns comprehensive information of all the content types 83 : /// available in a particular stack in your account 84 : /// 85 2 : /// Example: 86 2 : /// 87 1 : /// ```dart 88 : /// final contentTypeQuery = stack.contentType().query(); 89 2 : /// final response = contentTypeQuery.find(); 90 4 : /// print(response); 91 : /// ``` 92 12 : /// 93 4 : ContentTypeQuery query() { 94 : return ContentTypeQuery(_client); 95 : } 96 : }