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