-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathReleaseItem.cs
More file actions
267 lines (239 loc) · 12.6 KB
/
ReleaseItem.cs
File metadata and controls
267 lines (239 loc) · 12.6 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Contentstack.Management.Core.Queryable;
using Contentstack.Management.Core.Services.Models;
using Contentstack.Management.Core.Utils;
namespace Contentstack.Management.Core.Models
{
public class ReleaseItem {
internal Stack stack;
internal string resourcePath;
internal string releaseUID;
internal ReleaseItem(Stack stack, string releaseUID)
{
this.stack = stack;
this.releaseUID = releaseUID;
resourcePath = $"/releases/{releaseUID}/items";
}
/// <summary>
/// The Get all request retrieves a list of all items (entries and assets) that are part of a specific Release.
/// </summary>
/// <param name="parameters">URI query parameters</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// ContentstackResponse contentstackResponse = client.Stack().Relase("<RELEASE_UID>").Item().GetAll();
/// </code></pre>
/// </example>
/// <returns>The <see cref="ContentstackResponse"/></returns>
public ContentstackResponse GetAll(ParameterCollection parameters = null)
{
stack.ThrowIfNotLoggedIn();
ThrowIfUidEmpty();
var service = new FetchDeleteService(stack.client.serializer, this.stack, resourcePath, collection: parameters);
return stack.client.InvokeSync(service);
}
/// <summary>
/// The Get all request retrieves a list of all items (entries and assets) that are part of a specific Release.
/// </summary>
/// <param name="collection">URI query parameters</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// ContentstackResponse contentstackResponse = await client.Stack().Relase("<RELEASE_UID>").Item().GetAllAsync();
/// </code></pre>
/// </example>
/// <returns>The Task</returns>
public Task<ContentstackResponse> GetAllAsync(ParameterCollection parameters = null)
{
stack.ThrowIfNotLoggedIn();
ThrowIfUidEmpty();
var service = new FetchDeleteService(stack.client.serializer, this.stack, resourcePath, collection: parameters);
return stack.client.InvokeAsync<FetchDeleteService, ContentstackResponse>(service);
}
/// <summary>
/// The Create request allows you to add an item (entry or asset) to a Release.
/// To add entries/assets to a Release, you need to provide the UIDs of the entries/assets in ‘items’ in the request body.
/// </summary>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// ReleaseItemModel model = new ReleaseItemModel();
/// ContentstackResponse contentstackResponse = client.Stack("<API_KEY>").Relase("<RELEASE_UID>").Item().Create(model);
/// </code></pre>
/// </example>
/// <param name="model">ReleaseItem Model for creating ReleaseItem.</param>
/// <returns>The <see cref="ContentstackResponse"/>.</returns>
public ContentstackResponse Create(ReleaseItemModel model, ParameterCollection collection = null)
{
stack.ThrowIfNotLoggedIn();
ThrowIfUidEmpty();
var service = new CreateUpdateService<ReleaseItemModel>(stack.client.serializer, stack, resourcePath, model, "item", collection: collection);
return stack.client.InvokeSync(service);
}
/// <summary>
/// The Create request allows you to add an item (entry or asset) to a Release.
/// To add entries/assets to a Release, you need to provide the UIDs of the entries/assets in ‘items’ in the request body.
/// </summary>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// ReleaseItemModel model = new ReleaseItemModel();
/// ContentstackResponse contentstackResponse = await client.Stack("<API_KEY>").Relase("<RELEASE_UID>").Item().CreateAsync(model);
/// </code></pre>
/// </example>
/// <param name="model">ReleaseItem Model for creating ReleaseItem.</param>
/// <returns>The Task.</returns>
public Task<ContentstackResponse> CreateAsync(ReleaseItemModel model, ParameterCollection collection = null)
{
ThrowIfUidEmpty();
stack.ThrowIfNotLoggedIn();
var service = new CreateUpdateService<ReleaseItemModel>(stack.client.serializer, stack, resourcePath, model, "item", collection: collection);
return stack.client.InvokeAsync<CreateUpdateService<ReleaseItemModel>, ContentstackResponse>(service);
}
/// <summary>
/// The Create request allows you to add multiple items (entries and/or assets) to a Release.
/// To add entries/assets to a Release, you need to provide the UIDs of the entries/assets in ‘items’ in the request body.
/// </summary>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// ReleaseItemModel model = new ReleaseItemModel();
/// List<ReleaseItemModel> models = new List<ReleaseItemModel>()
/// {
/// model,
/// };
/// ContentstackResponse contentstackResponse = client.Stack("<API_KEY>").Relase("<RELEASE_UID>").Item().CreateMultiple(models);
/// </code></pre>
/// </example>
/// <param name="model">ReleaseItem Model for creating ReleaseItem.</param>
/// <returns>The <see cref="ContentstackResponse"/>.</returns>
public ContentstackResponse CreateMultiple(List<ReleaseItemModel> models, ParameterCollection collection = null)
{
stack.ThrowIfNotLoggedIn();
ThrowIfUidEmpty();
var service = new CreateUpdateService<List<ReleaseItemModel>>(stack.client.serializer, stack, resourcePath, models, "items", collection: collection);
return stack.client.InvokeSync(service);
}
/// <summary>
/// The Create request allows you to add multiple items (entries and/or assets) to a Release.
/// To add entries/assets to a Release, you need to provide the UIDs of the entries/assets in ‘items’ in the request body.
/// </summary>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// ContentstackResponse contentstackResponse = await client.Stack("<API_KEY>").Relase("<RELEASE_UID>").Item().CreateMultipleAsync(models);
/// ReleaseItemModel model = new ReleaseItemModel();
/// List<ReleaseItemModel> models = new List<ReleaseItemModel>()
/// {
/// model,
/// };
/// </code></pre>
/// </example>
/// <param name="model">ReleaseItem Model for creating ReleaseItem.</param>
/// <returns>The Task.</returns>
public Task<ContentstackResponse> CreateMultipleAsync(List<ReleaseItemModel> model, ParameterCollection collection = null)
{
ThrowIfUidEmpty();
stack.ThrowIfNotLoggedIn();
var service = new CreateUpdateService<List<ReleaseItemModel>>(stack.client.serializer, stack, resourcePath, model, "items", collection: collection);
return stack.client.InvokeAsync<CreateUpdateService<List<ReleaseItemModel>>, ContentstackResponse>(service);
}
/// <summary>
/// The Update Release items to their latest versions request let you update all the release items (entries and assets) to their latest versions before deployment.
/// </summary>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// List<string> items = new List<string>(){
/// "<$all>"
/// }
/// ContentstackResponse contentstackResponse = client.Stack("<API_KEY>").Release("<RELEASE_UID>").Item().UpdateReleaseItem(items);
/// </code></pre>
/// </example>
/// <param name="items">Release items to update or "$all" for updating all release items</param>
/// <returns>The <see cref="ContentstackResponse"/>.</returns>
public ContentstackResponse UpdateReleaseItem(List<string> items)
{
stack.ThrowIfNotLoggedIn();
ThrowIfUidEmpty();
var service = new CreateUpdateService<List<string>>(stack.client.serializer, stack, $"/releases/{releaseUID}/update_items", items, "items", "PUT");
return stack.client.InvokeSync(service);
}
/// <summary>
/// The Update Release items to their latest versions request let you update all the release items (entries and assets) to their latest versions before deployment.
/// </summary>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// List<string> items = new List<string>(){
/// "<$all>"
/// }
/// ContentstackResponse contentstackResponse = await client.Stack("<API_KEY>").Release("<RELEASE_UID>").Item().UpdateReleaseItemAsync(items);
/// </code></pre>
/// </example>
/// <param name="items">Release items to update or "$all" for updating all release items</param>
/// <returns>The Task.</returns>
public Task<ContentstackResponse> UpdateReleaseItemAsync(List<string> items)
{
stack.ThrowIfNotLoggedIn();
ThrowIfUidEmpty();
var service = new CreateUpdateService<List<string>>(stack.client.serializer, stack, $"/releases/{releaseUID}/update_items", items, "items", "PUT");
return stack.client.InvokeAsync<CreateUpdateService<List<string>>, ContentstackResponse>(service);
}
/// <summary>
/// The Delete request deletes one or more items (entries and/or assets) from a specific Release.
/// </summary>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// ReleaseItemModel model = new ReleaseItemModel();
/// List<ReleaseItemModel> models = new List<ReleaseItemModel>()
/// {
/// model,
/// };
/// ContentstackResponse contentstackResponse = client.Stack("<API_KEY>").Relase("<RELEASE_UID>").Item("<RELEASE_ITEM_UID>").Delete(models);
/// </code></pre>
/// </example>
/// <returns>The <see cref="ContentstackResponse"/>.</returns>
public ContentstackResponse Delete(List<ReleaseItemModel> models, ParameterCollection collection = null)
{
stack.ThrowIfNotLoggedIn();
ThrowIfUidEmpty();
var service = new DeleteService<List<ReleaseItemModel>>(stack.client.serializer, stack, resourcePath, "items", models, collection);
return stack.client.InvokeSync(service);
}
/// <summary>
/// The Delete request deletes one or more items (entries and/or assets) from a specific Release.
/// </summary>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// ReleaseItemModel model = new ReleaseItemModel();
/// List<ReleaseItemModel> models = new List<ReleaseItemModel>()
/// {
/// model,
/// };
/// ContentstackResponse contentstackResponse = await client.Stack("<API_KEY>").Relase("<RELEASE_UID>").Item("<RELEASE_ITEM_UID>").DeleteAsync(models);
/// </code></pre>
/// </example>
/// <returns>The Task.</returns>
public Task<ContentstackResponse> DeleteAsync(List<ReleaseItemModel> models, ParameterCollection collection = null)
{
stack.ThrowIfNotLoggedIn();
ThrowIfUidEmpty();
var service = new DeleteService<List<ReleaseItemModel>>(stack.client.serializer, stack, resourcePath, "items", models, collection);
return stack.client.InvokeAsync<DeleteService<List<ReleaseItemModel>>, ContentstackResponse>(service);
}
#region Throw Error
internal void ThrowIfUidEmpty()
{
if (string.IsNullOrEmpty(this.releaseUID))
{
throw new InvalidOperationException(CSConstants.ReleaseItemUIDRequired);
}
}
#endregion
}
}