-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTaxonomy.cs
More file actions
203 lines (184 loc) · 7.81 KB
/
Taxonomy.cs
File metadata and controls
203 lines (184 loc) · 7.81 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
using System;
using System.Threading.Tasks;
using Contentstack.Management.Core.Queryable;
using Contentstack.Management.Core.Services.Models;
namespace Contentstack.Management.Core.Models
{
/// <summary>
/// Taxonomy allows you to organize and categorize content using a hierarchical structure of terms.
/// </summary>
public class Taxonomy : BaseModel<TaxonomyModel>
{
internal Taxonomy(Stack stack, string uid = null)
: base(stack, "taxonomy", uid)
{
resourcePath = uid == null ? "/taxonomies" : $"/taxonomies/{uid}";
}
/// <summary>
/// Query taxonomies. Fetches all taxonomies with optional filters.
/// </summary>
/// <example>
/// <code>
/// ContentstackResponse response = stack.Taxonomy().Query().Find();
/// </code>
/// </example>
public Query Query()
{
ThrowIfUidNotEmpty();
return new Query(stack, resourcePath);
}
/// <summary>
/// Create a taxonomy.
/// </summary>
public override ContentstackResponse Create(TaxonomyModel model, ParameterCollection collection = null)
{
return base.Create(model, collection);
}
/// <summary>
/// Create a taxonomy asynchronously.
/// </summary>
public override Task<ContentstackResponse> CreateAsync(TaxonomyModel model, ParameterCollection collection = null)
{
return base.CreateAsync(model, collection);
}
/// <summary>
/// Update an existing taxonomy.
/// </summary>
public override ContentstackResponse Update(TaxonomyModel model, ParameterCollection collection = null)
{
return base.Update(model, collection);
}
/// <summary>
/// Update an existing taxonomy asynchronously.
/// </summary>
public override Task<ContentstackResponse> UpdateAsync(TaxonomyModel model, ParameterCollection collection = null)
{
return base.UpdateAsync(model, collection);
}
/// <summary>
/// Fetch a single taxonomy.
/// </summary>
public override ContentstackResponse Fetch(ParameterCollection collection = null)
{
return base.Fetch(collection);
}
/// <summary>
/// Fetch a single taxonomy asynchronously.
/// </summary>
public override Task<ContentstackResponse> FetchAsync(ParameterCollection collection = null)
{
return base.FetchAsync(collection);
}
/// <summary>
/// Delete a taxonomy.
/// </summary>
public override ContentstackResponse Delete(ParameterCollection collection = null)
{
return base.Delete(collection);
}
/// <summary>
/// Delete a taxonomy asynchronously.
/// </summary>
public override Task<ContentstackResponse> DeleteAsync(ParameterCollection collection = null)
{
return base.DeleteAsync(collection);
}
/// <summary>
/// Export taxonomy. GET {resourcePath}/export with optional query parameters.
/// </summary>
public ContentstackResponse Export(ParameterCollection collection = null)
{
stack.ThrowIfNotLoggedIn();
ThrowIfUidEmpty();
var service = new FetchDeleteService(stack.client.serializer, stack, resourcePath + "/export", "GET", collection);
return stack.client.InvokeSync(service);
}
/// <summary>
/// Export taxonomy asynchronously.
/// </summary>
public Task<ContentstackResponse> ExportAsync(ParameterCollection collection = null)
{
stack.ThrowIfNotLoggedIn();
ThrowIfUidEmpty();
var service = new FetchDeleteService(stack.client.serializer, stack, resourcePath + "/export", "GET", collection);
return stack.client.InvokeAsync<FetchDeleteService, ContentstackResponse>(service);
}
/// <summary>
/// Get taxonomy locales. GET {resourcePath}/locales.
/// </summary>
public ContentstackResponse Locales(ParameterCollection collection = null)
{
stack.ThrowIfNotLoggedIn();
ThrowIfUidEmpty();
var service = new FetchDeleteService(stack.client.serializer, stack, resourcePath + "/locales", "GET", collection);
return stack.client.InvokeSync(service);
}
/// <summary>
/// Get taxonomy locales asynchronously.
/// </summary>
public Task<ContentstackResponse> LocalesAsync(ParameterCollection collection = null)
{
stack.ThrowIfNotLoggedIn();
ThrowIfUidEmpty();
var service = new FetchDeleteService(stack.client.serializer, stack, resourcePath + "/locales", "GET", collection);
return stack.client.InvokeAsync<FetchDeleteService, ContentstackResponse>(service);
}
/// <summary>
/// Localize taxonomy. POST to resourcePath with body { taxonomy: model } and query params (e.g. locale).
/// </summary>
public ContentstackResponse Localize(TaxonomyModel model, ParameterCollection collection = null)
{
stack.ThrowIfNotLoggedIn();
ThrowIfUidEmpty();
var service = new CreateUpdateService<TaxonomyModel>(stack.client.serializer, stack, resourcePath, model, "taxonomy", "POST", collection);
return stack.client.InvokeSync(service);
}
/// <summary>
/// Localize taxonomy asynchronously.
/// </summary>
public Task<ContentstackResponse> LocalizeAsync(TaxonomyModel model, ParameterCollection collection = null)
{
stack.ThrowIfNotLoggedIn();
ThrowIfUidEmpty();
var service = new CreateUpdateService<TaxonomyModel>(stack.client.serializer, stack, resourcePath, model, "taxonomy", "POST", collection);
return stack.client.InvokeAsync<CreateUpdateService<TaxonomyModel>, ContentstackResponse>(service);
}
/// <summary>
/// Import taxonomy. POST /taxonomies/import with multipart form (taxonomy file).
/// </summary>
public ContentstackResponse Import(TaxonomyImportModel model, ParameterCollection collection = null)
{
stack.ThrowIfNotLoggedIn();
ThrowIfUidNotEmpty();
var path = resourcePath + "/import";
var service = new UploadService(stack.client.serializer, stack, path, model, "POST", collection);
return stack.client.InvokeSync(service);
}
/// <summary>
/// Import taxonomy asynchronously.
/// </summary>
public Task<ContentstackResponse> ImportAsync(TaxonomyImportModel model, ParameterCollection collection = null)
{
stack.ThrowIfNotLoggedIn();
ThrowIfUidNotEmpty();
var path = resourcePath + "/import";
var service = new UploadService(stack.client.serializer, stack, path, model, "POST", collection);
return stack.client.InvokeAsync<UploadService, ContentstackResponse>(service);
}
/// <summary>
/// Get Terms instance for this taxonomy. When termUid is provided, returns a single-term context; otherwise collection for query/create.
/// </summary>
/// <param name="termUid">Optional term UID. If null, returns Terms for querying all terms or creating.</param>
/// <example>
/// <code>
/// stack.Taxonomy("taxonomy_uid").Terms().Query().Find();
/// stack.Taxonomy("taxonomy_uid").Terms("term_uid").Fetch();
/// </code>
/// </example>
public Term Terms(string termUid = null)
{
ThrowIfUidEmpty();
return new Term(stack, Uid, termUid);
}
}
}