-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathStack.cs
More file actions
1015 lines (911 loc) · 42.5 KB
/
Stack.cs
File metadata and controls
1015 lines (911 loc) · 42.5 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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Contentstack.Management.Core.Queryable;
using Contentstack.Management.Core.Services.Stack;
using Contentstack.Management.Core.Utils;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Models.Token;
namespace Contentstack.Management.Core.Models
{
public class Stack
{
internal ContentstackClient client;
public string APIKey { get; private set; }
public string ManagementToken { get; private set; }
public string BranchUid { get; private set; }
#region Constructor
public Stack(ContentstackClient contentstackClient, string apiKey = null, string managementToken = null, string branchUid = null)
{
client = contentstackClient;
APIKey = apiKey;
ManagementToken = managementToken;
BranchUid = branchUid;
}
#endregion
#region Public
/// <summary>
/// The Get all stacks call fetches the list of all stacks owned by and shared with a particular user account.
/// </summary>
/// <param name="parameters">URI query parameters</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack();
/// ContentstackResponse contentstackResponse = stack.GetAll();
/// </code></pre>
/// </example>
/// <returns>The <see cref="ContentstackResponse"/></returns>
public ContentstackResponse GetAll(ParameterCollection parameters = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyNotEmpty();
var service = new FetchStackService(client.serializer, this, parameters);
return client.InvokeSync(service);
}
/// <summary>
/// The Get all stacks call fetches the list of all stacks owned by and shared with a particular user account.
/// </summary>
/// <param name="collection">URI query parameters</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack();
/// ContentstackResponse contentstackResponse = await stack.GetAllAsync();
/// </code></pre>
/// </example>
/// <returns>The Task</returns>
public Task<ContentstackResponse> GetAllAsync(ParameterCollection parameters = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyNotEmpty();
var service = new FetchStackService(client.serializer, this, parameters);
return client.InvokeAsync<FetchStackService, ContentstackResponse>(service);
}
/// <summary>
/// The Get a single stack call fetches comprehensive details of a specific stack.
/// </summary>
/// <param name="parameters">URI query parameters</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.Fetch();
/// </code></pre>
/// </example>
/// <returns>The <see cref="ContentstackResponse"/></returns>
public ContentstackResponse Fetch(ParameterCollection parameters = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
var service = new FetchStackService(client.serializer, this, parameters);
return client.InvokeSync(service);
}
/// <summary>
/// The Get a single stack call fetches comprehensive details of a specific stack.
/// </summary>
/// <param name="parameters">URI query parameters</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = await stack.FetchAsync();
/// </code></pre>
/// </example>
/// <returns>The Task</returns>
public Task<ContentstackResponse> FetchAsync(ParameterCollection parameters = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
var service = new FetchStackService(client.serializer, this, parameters);
return client.InvokeAsync<FetchStackService, ContentstackResponse>(service);
}
/// <summary>
/// The Transfer stack ownership to other users call sends the specified user an email invitation for accepting the ownership of a particular stack.
/// </summary>
/// <param name="email">The email id of user for transfer.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.TransferOwnership("<EMAIL>");
/// </code></pre>
/// </example>
/// <returns>The <see cref="ContentstackResponse"/></returns>
public ContentstackResponse TransferOwnership(string email)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
var service = new StackOwnershipService(client.serializer, this, email);
return client.InvokeSync(service);
}
/// <summary>
/// The Transfer stack ownership to other users call sends the specified user an email invitation for accepting the ownership of a particular stack.
/// </summary>
/// <param name="email">The email id of user for transfer.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = await stack.TransferOwnershipAsync("<EMAIL>");
/// </code></pre>
/// </example>
/// <returns>The Task</returns>
public Task<ContentstackResponse> TransferOwnershipAsync(string email)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
var service = new StackOwnershipService(client.serializer, this, email);
return client.InvokeAsync<StackOwnershipService, ContentstackResponse>(service);
}
/// <summary>
/// The Create stack call creates a new stack in your Contentstack account.
/// </summary>
/// <param name="name">The name for Stack.</param>
/// <param name="masterLocale">The Master Locale for Stack</param>
/// <param name="organisationUid">The Organization Uid in which you want to create Stack.</param>
/// <param name="description">The description for the Stack.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack();
/// ContentstackResponse contentstackResponse = stack.Create("<STACK_NAME>", "<LOCALE>", "<ORG_UID>", "<DESCRIPTION>");
/// </code></pre>
/// </example>
/// <returns>The <see cref="ContentstackResponse"/></returns>
public ContentstackResponse Create(string name, string masterLocale, string organisationUid, string description = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyNotEmpty();
ThrowInvalideName(name);
ThrowInvalideLocale(masterLocale);
ThrowInvalideOrganizationUid(organisationUid);
var service = new StackCreateUpdateService(client.serializer, this, name, masterLocale, description, organizationUid: organisationUid);
return client.InvokeSync(service);
}
/// <summary>
/// The Create stack call creates a new stack in your Contentstack account.
/// </summary>
/// <param name="name">The name for Stack.</param>
/// <param name="masterLocale">The Master Locale for Stack</param>
/// <param name="organisationUid">The Organization Uid in which you want to create Stack.</param>
/// <param name="description">The description for the Stack.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack();
/// ContentstackResponse contentstackResponse = await stack.CreateAsync("<STACK_NAME>", "<LOCALE>", "<ORG_UID>", "<DESCRIPTION>");
/// </code></pre>
/// </example>
/// <returns>The Task</returns>
public Task<ContentstackResponse> CreateAsync(string name, string masterLocale, string organisationUid, string description = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyNotEmpty();
ThrowInvalideName(name);
ThrowInvalideLocale(masterLocale);
ThrowInvalideOrganizationUid(organisationUid);
var service = new StackCreateUpdateService(client.serializer, this, name, masterLocale, description, organizationUid: organisationUid);
return client.InvokeAsync<StackCreateUpdateService, ContentstackResponse>(service);
}
/// <summary>
/// TThe Update stack call lets you update the name and description of an existing stack.
/// </summary>
/// <param name="name">The name for Stack.</param>
/// <param name="masterLocale">The Master Locale for Stack</param>
/// <param name="organisationUid">The Organization Uid in which you want to create Stack.</param>
/// <param name="description">The description for the Stack.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.Update("<STACK_NAME>", "<DESCRIPTION>");
/// </code></pre>
/// </example>
/// <returns>The <see cref="ContentstackResponse"/></returns>
public ContentstackResponse Update(string name, string description = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
ThrowInvalideName(name);
var service = new StackCreateUpdateService(client.serializer, this, name, description: description);
return client.InvokeSync(service);
}
/// <summary>
/// TThe Update stack call lets you update the name and description of an existing stack.
/// </summary>
/// <param name="name">The name for Stack.</param>
/// <param name="masterLocale">The Master Locale for Stack</param>
/// <param name="organisationUid">The Organization Uid in which you want to create Stack.</param>
/// <param name="description">The description for the Stack.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = await stack.UpdateAsync("<STACK_NAME>", "<DESCRIPTION>");
/// </code></pre>
/// </example>
/// <returns>The Task</returns>
public Task<ContentstackResponse> UpdateAsync(string name, string description = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
ThrowInvalideName(name);
var service = new StackCreateUpdateService(client.serializer, this, name, description: description);
return client.InvokeAsync<StackCreateUpdateService, ContentstackResponse>(service);
}
/// <summary>
/// The Update User Role API Request updates the roles of an existing user account.
/// </summary>
/// <param name="usersRole">List of users uid and roles to assign users.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// UserInvitation invitation = new UserInvitation()
/// {
/// Uid = "<USER_ID>",
/// Roles = new System.Collections.Generic.List<string>() { "<ROLE_UID>" }
/// };
/// ContentstackResponse contentstackResponse = stack.UpdateUserRole(new List<UserInvitation>() {
/// invitation
/// });
/// </code></pre>
/// </example>
/// <returns>The <see cref="ContentstackResponse"/></returns>
public ContentstackResponse UpdateUserRole(List<UserInvitation> usersRole)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
var service = new UpdateUserRoleService(client.serializer, this, usersRole);
return client.InvokeSync(service);
}
/// <summary>
/// The Update User Role API Request updates the roles of an existing user account.
/// </summary>
/// <param name="usersRole"></param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// UserInvitation invitation = new UserInvitation()
/// {
/// Uid = "<USER_ID>",
/// Roles = new System.Collections.Generic.List<string>() { "<ROLE_UID>" }
/// };
/// ContentstackResponse contentstackResponse = await stack.UpdateUserRoleAsync(new List<UserInvitation>() {
/// invitation
/// });
/// </code></pre>
/// </example>
/// <returns>The Task</returns>
public Task<ContentstackResponse> UpdateUserRoleAsync(List<UserInvitation> usersRole)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
var service = new UpdateUserRoleService(client.serializer, this, usersRole);
return client.InvokeAsync<UpdateUserRoleService, ContentstackResponse>(service);
}
/// <summary>
/// The Get stack settings call retrieves the configuration settings of an existing stack.
/// </summary>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.Settings();
/// </code></pre>
/// </example>
/// <returns>The <see cref="ContentstackResponse"/></returns>
public ContentstackResponse Settings()
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
var service = new StackSettingsService(client.serializer, this);
return client.InvokeSync(service);
}
/// <summary>
/// The Get stack settings call retrieves the configuration settings of an existing stack.
/// </summary>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = await stack.SettingsAsync();
/// </code></pre>
/// </example>
/// <returns>The Task</returns>
public Task<ContentstackResponse> SettingsAsync()
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
var service = new StackSettingsService(client.serializer, this);
return client.InvokeAsync<StackSettingsService, ContentstackResponse>(service);
}
/// <summary>
/// The Reset stack settings call resets your stack to default settings, and additionally, lets you add parameters to or modify the settings of an existing stack.
/// </summary>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.Settings();
/// </code></pre>
/// </example>
/// <returns>The <see cref="ContentstackResponse"/></returns>
public ContentstackResponse ResetSettings()
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
var service = new StackSettingsService(client.serializer, this, "POST", new StackSettings()
{
StackVariables = new Dictionary<string, object>(),
DiscreteVariables = new Dictionary<string, object>(),
Rte = new Dictionary<string, object>()
});
return client.InvokeSync(service);
}
/// <summary>
/// The Reset stack settings call resets your stack to default settings, and additionally, lets you add parameters to or modify the settings of an existing stack.
/// </summary>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = await stack.SettingsAsync();
/// </code></pre>
/// </example>
/// <returns>The Task</returns>
public Task<ContentstackResponse> ResetSettingsAsync()
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
var service = new StackSettingsService(client.serializer, this, "POST", new StackSettings()
{
StackVariables = new Dictionary<string, object>(),
DiscreteVariables = new Dictionary<string, object>(),
Rte = new Dictionary<string, object>()
});
return client.InvokeAsync<StackSettingsService, ContentstackResponse>(service);
}
/// <summary>
/// The Add stack settings request lets you add additional settings for your existing stack.
/// </summary>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.Settings("<STACK_SETTINGS>");
/// </code></pre>
/// </example>
/// <returns>The <see cref="ContentstackResponse"/></returns>
public ContentstackResponse AddSettings(StackSettings settings)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
if (settings == null)
{
throw new ArgumentNullException("settings", CSConstants.StackSettingsRequired);
}
var service = new StackSettingsService(client.serializer, this, "POST", settings);
return client.InvokeSync(service);
}
/// <summary>
/// The Add stack settings request lets you add additional settings for your existing stack.
/// </summary>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = await stack.SettingsAsync("<STACK_SETTINGS>");
/// </code></pre>
/// </example>
/// <returns>The Task</returns>
public Task<ContentstackResponse> AddSettingsAsync(StackSettings settings)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
if (settings == null)
{
throw new ArgumentNullException("settings", CSConstants.StackSettingsRequired);
}
var service = new StackSettingsService(client.serializer, this, "POST", settings);
return client.InvokeAsync<StackSettingsService, ContentstackResponse>(service);
}
/// <summary>
/// The Share a stack call shares a stack with the specified user to collaborate on the stack.
/// </summary>
/// <param name="invitations"></param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// UserInvitation invitation = new UserInvitation()
/// {
/// Email = "<EMAIL>",
/// Roles = new System.Collections.Generic.List<string>() { "<ROLE_UID>" }
/// };
/// ContentstackResponse contentstackResponse = stack.Share(invitation);
/// </code></pre>
/// </example>
/// <returns>The <see cref="ContentstackResponse"/></returns>
public ContentstackResponse Share(List<UserInvitation> invitations)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
if (invitations == null)
{
throw new ArgumentNullException("invitations", CSConstants.InvitationsRequired);
}
var service = new StackShareService(client.serializer, this);
service.AddUsers(invitations);
return client.InvokeSync(service);
}
/// <summary>
/// The Share a stack call shares a stack with the specified user to collaborate on the stack.
/// </summary>
/// <param name="invitations"></param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// UserInvitation invitation = new UserInvitation()
/// {
/// Email = "<EMAIL>",
/// Roles = new System.Collections.Generic.List<string>() { "<ROLE_UID>" }
/// };
/// ContentstackResponse contentstackResponse = await stack.ShareAsync(invitation);
/// </code></pre>
/// </example>
/// <returns>The Task</returns>
public Task<ContentstackResponse> ShareAsync(List<UserInvitation> invitations)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
if (invitations == null)
{
throw new ArgumentNullException("invitations", CSConstants.InvitationsRequired);
}
var service = new StackShareService(client.serializer, this);
service.AddUsers(invitations);
return client.InvokeAsync<StackShareService, ContentstackResponse>(service);
}
/// <summary>
/// The Unshare a stack call unshares a stack with a user and removes the user account from the list of collaborators.
/// </summary>
/// <param name="email"></param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.UnShare(("<EMAIL>");
/// </code></pre>
/// </example>
/// <returns>The <see cref="ContentstackResponse"/></returns>
public ContentstackResponse UnShare(string email)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
if (email == null)
{
throw new ArgumentNullException("email", CSConstants.EmailRequired);
}
var service = new StackShareService(client.serializer, this);
service.RemoveUsers(email);
return client.InvokeSync(service);
}
/// <summary>
/// The Unshare a stack call unshares a stack with a user and removes the user account from the list of collaborators.
/// </summary>
/// <param name="email"></param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = await stack.UnShareAsync("<EMAIL>");
/// </code></pre>
/// </example>
/// <returns>The Task</returns>
public Task<ContentstackResponse> UnShareAsync(string email)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
if (email == null)
{
throw new ArgumentNullException("email", CSConstants.EmailRequired);
}
var service = new StackShareService(client.serializer, this);
service.RemoveUsers(email);
return client.InvokeAsync<StackShareService, ContentstackResponse>(service);
}
/// <summary>
/// Contentstack has a sophisticated multilingual capability. It allows you to create and publish entries in any language.
/// </summary>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.Locale("<LOCALE_CODE>").Fetch();
/// </code></pre>
/// </example>
/// <param name="code">Locale code fot language</param>
/// <returns>The <see cref="Models.Locale"/></returns>
public Locale Locale(string code = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new Locale(this, code);
}
/// <summary>
/// <see cref="Models.ContentType" /> defines the structure or schema of a page or a section of your web or mobile property.
/// To create content for your application, you are required to first create a content type, and then create entries using the content type.
/// </summary>
/// <param name="uid"> Optional content type uid.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.ContentType("<CONTENT_TYPE_UID>").Fetch();
/// </code></pre>
/// </example>
/// <returns>The <see cref="Models.ContentType"/></returns>
public ContentType ContentType(string uid = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new ContentType(this, uid);
}
/// <summary>
/// <see cref="Models.Asset"/> efer to all the media files (images, videos, PDFs, audio files, and so on) uploaded in your Contentstack repository for future use.
/// </summary>
/// <param name="uid">Optional asset uid.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.Asset("<ASSET_UID>").Fetch();
/// </code></pre>
/// </example>
/// <returns>The <see cref="Models.Asset"/></returns>
public Asset Asset(string uid = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new Asset(this, uid);
}
/// <summary>
/// <see cref="Models.GlobalField" /> defines the structure or schema of a page or a section of your web or mobile property. To create global Fields for your application, you are required to first create a global field. Read more about <a href='https://www.contentstack.com/docs/guide/global-fields'>Global Fields</a>.
/// </summary>
/// <param name="uid">Optional, global field uid.</param>
/// <param name="apiVersion">Optional, API version for nested global field support.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// ContentstackResponse contentstackResponse = client.Stack("<API_KEY>").GlobalField("<GLOBAL_FIELD_UID>").Fetch();
/// </code></pre>
/// </example>
/// <returns>The <see cref="Models.GlobalField" /></returns>
public GlobalField GlobalField(string uid = null, string apiVersion = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new GlobalField(this, uid, apiVersion);
}
/// <summary>
/// <see cref="Models.Extension" /> let you create custom fields and custom widgets that lets you customize Contentstack's default UI and behavior.
/// </summary>
/// <param name="uid">Optional, extension uid.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.Extension("<EXTENSION_UID>").Fetch();
/// </code></pre>
/// </example>
/// <returns>The <see cref="Models.Extension" /></returns>
public Extension Extension(string uid = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new Extension(this, uid);
}
/// <summary>
/// <see cref="Models.Label" /> allow you to group a collection of content within a stack. Using labels you can group content types that need to work together.
/// </summary>
/// <param name="uid">Optional, label uid.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.Label("<LABEL_UID>").Fetch();
/// </code></pre>
/// </example>
/// <returns>The <see cref="Models.Label" /></returns>
public Label Label(string uid = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new Label(this, uid);
}
/// <summary>
/// <see cref="Models.Taxonomy" /> allows you to organize and categorize content using a hierarchical structure of terms.
/// </summary>
/// <param name="uid">Optional, taxonomy uid.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse response = stack.Taxonomy("<TAXONOMY_UID>").Fetch();
/// ContentstackResponse list = stack.Taxonomy().Query().Find();
/// </code></pre>
/// </example>
/// <returns>The <see cref="Models.Taxonomy" /></returns>
public Taxonomy Taxonomy(string uid = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new Taxonomy(this, uid);
}
/// <summary>
/// A publishing <see cref="Models.Environment" /> corresponds to one or more deployment servers or a content delivery destination where the entries need to be published.
/// </summary>
/// <param name="uid">Optional, environment uid.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.Environment("<ENVIRONMENT_UID>").Fetch();
/// </code></pre>
/// </example>
/// <returns>The <see cref="Models.Environment" /></returns>
public Environment Environment(string uid = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new Environment(this, uid);
}
/// <summary>
/// You can use <see cref="Models.Token.DeliveryToken" /> to authenticate Content Delivery API (CDA) requests and retrieve the published content of an environment.
/// </summary>
/// <param name="uid">Optional, delivery token uid.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.DeliveryToken("<TOKEN_UID>").Fetch();
/// </code></pre>
/// </example>
/// <returns>The <see cref="Models.Token.DeliveryToken" /></returns>
public DeliveryToken DeliveryToken(string uid = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new DeliveryToken(this, uid);
}
/// <summary>
/// You can use <see cref="Models.Token.ManagementToken" /> to authenticate Content Management API (CMA) requests over your stack content.
/// </summary>
/// <param name="uid">Optional, management token uid.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.ManagementTokens("<TOKEN_UID>").Fetch();
/// </code></pre>
/// </example>
/// <returns>The <see cref="Models.Token.ManagementToken" /></returns>
public ManagementToken ManagementTokens(string uid = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new ManagementToken(this, uid);
}
/// <summary>
/// A <see cref="Models.Role" /> collection of permissions that will be applicable to all the users who are assigned this role.
/// </summary>
/// <param name="uid">Optional, role uid.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.Role("<ROLE_UID>").Fetch();
/// </code></pre>
/// </example>
/// <returns>The <see cref="Models.Release" /></returns>
public Role Role(string uid = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new Role(this, uid);
}
/// <summary>
/// A <see cref="Models.Release" /> is a set of entries and assets that needs to be deployed (published or unpublished) all at once to a particular environment.
/// </summary>
/// <param name="uid">Optional, release uid.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.Release("<RELEASE_UID>").Fetch();
/// </code></pre>
/// </example>
/// <returns>The <see cref="Models.Release" /></returns>
public Release Release(string uid = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new Release(this, uid);
}
/// <summary>
/// A <see cref="Models.Workflow" /> is a tool that allows you to streamline the process of content creation and publishing, and lets you manage the content lifecycle of your project smoothly.
/// </summary>
/// <param name="uid">Optional, workflow uid.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.Workflow("<WORKFLOW_UID>").Fetch();
/// </code></pre>
/// </example>
/// <returns>The <see cref="Models.Workflow" /></returns>
public Workflow Workflow(string uid = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new Workflow(this, uid);
}
/// <summary>
/// A <see cref="Models.PublishQueue" /> displays the historical and current details of activities such as publish, unpublish, or delete that can be performed on entries and/or assets.
/// It also shows details of Release deployments. These details include time, entry, content type, version, language, user, environment, and status.
/// </summary>
/// <param name="uid">Optional, publish queue uid.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.PublishQueue("<PUBLISH_QUEUE_UID>").Fetch();
/// </code></pre>
/// </example>
/// <returns>The <see cref="Models.PublishQueue" /></returns>
public PublishQueue PublishQueue(string uid = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new PublishQueue(this, uid);
}
/// <summary>
/// A <see cref="Models.Webhook" /> a mechanism that sends real-time information to any third-party app or service to keep your application in sync with your Contentstack account.
/// </summary>
/// <param name="uid">Optional, webhook uid uid.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.Webhook("<WEBHOOK_UID>").Fetch();
/// </code></pre>
/// </example>
/// <returns>The <see cref="Models.AuditLog" /></returns>
public Webhook Webhook(string uid = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new Webhook(this, uid);
}
/// <summary>
/// A <see cref="Models.AuditLog" /> displays a record of all the activities performed in a stack and helps you keep a track of all published items, updates, deletes, and current status of the existing content.
/// </summary>
/// <param name="uid">Optional, audit log uid.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.AuditLog("<AUDIT_LOG_UID>").Fetch();
/// </code></pre>
/// </example>
/// <returns>The <see cref="Models.AuditLog" /></returns>
public AuditLog AuditLog(string uid = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new AuditLog(this, uid);
}
/// <summary>
/// A <see cref="Models.VariantGroup" /> allows you to manage variant groups and their associated content types.
/// Variant groups help you organize related variants for better management.
/// </summary>
/// <param name="uid">Optional, variant group uid.</param>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
/// ContentstackResponse contentstackResponse = stack.VariantGroup().Find();
/// </code></pre>
/// </example>
/// <returns>The <see cref="Models.VariantGroup" /></returns>
public VariantGroup VariantGroup(string uid = null)
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new VariantGroup(this, uid);
}
/// <summary>
/// Gets the bulk operation instance for performing bulk operations on entries and assets.
/// </summary>
/// <example>
/// <pre><code>
/// ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");
/// Stack stack = client.Stack("<API_KEY>");
///
/// var publishDetails = new BulkPublishDetails
/// {
/// Entries = new List<BulkPublishEntry>
/// {
/// new BulkPublishEntry { Uid = "entry_uid", ContentTypeUid = "content_type_uid", Locale = "en-us" }
/// },
/// Locales = new List<string> { "en-us" },
/// Environments = new List<string> { "environment_uid" }
/// };
///
/// ContentstackResponse response = stack.BulkOperation().Publish(publishDetails);
/// </code></pre>
/// </example>
/// <returns>The <see cref="Models.BulkOperation"/></returns>
public BulkOperation BulkOperation()
{
ThrowIfNotLoggedIn();
ThrowIfAPIKeyEmpty();
return new BulkOperation(this);
}
#endregion
#region Throw Error
internal void ThrowIfAPIKeyNotEmpty()
{
if (!string.IsNullOrEmpty(this.APIKey))
{
throw new InvalidOperationException(CSConstants.InvalidAPIKey);
}
}
internal void ThrowIfAPIKeyEmpty()
{
if (string.IsNullOrEmpty(this.APIKey))
{
throw new InvalidOperationException(CSConstants.MissingAPIKey);
}
}
internal void ThrowInvalideName(string name)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentNullException("name", CSConstants.StackNameInvalid);
}
}
internal void ThrowInvalideLocale(string locale)
{
if (string.IsNullOrEmpty(locale))
{
throw new ArgumentNullException("locale", CSConstants.LocaleInvalid);
}
}
internal void ThrowInvalideOrganizationUid(string uid)
{
if (string.IsNullOrEmpty(uid))
{
throw new ArgumentNullException("uid", CSConstants.OrganizationUIDInvalid);
}
}
internal void ThrowIfNotLoggedIn()