1
+ """This class takes a base URL as an argument when it's initialized,
2
+ which is the endpoint for the RESTFUL API that we'll be interacting with.
3
+ The create(), read(), update(), and delete() methods each correspond to
4
+ the CRUD operations that can be performed on the API """
5
+
6
+ import json
7
+ from ..common import Parameter
8
+ from urllib .parse import quote
9
+ from .._errors import ArgumentException
10
+
11
+ class DeliveryToken (Parameter ):
12
+ """
13
+ This class takes a base URL as an argument when it's initialized,
14
+ which is the endpoint for the RESTFUL API that
15
+ we'll be interacting with. The create(), read(), update(), and delete()
16
+ methods each correspond to the CRUD
17
+ operations that can be performed on the API """
18
+
19
+ def __init__ (self , client , delivery_token_uid : str ):
20
+ self .client = client
21
+ self .delivery_token_uid = delivery_token_uid
22
+ super ().__init__ (self .client )
23
+
24
+ self .path = "stacks/delivery_tokens"
25
+
26
+ def find (self ):
27
+ """
28
+ The "Get all delivery tokens" request returns the details of all the delivery tokens created in a stack.
29
+ :return: Json, with delivery_token details.
30
+
31
+ -------------------------------
32
+ [Example:]
33
+
34
+ >>> from contentstack_management import contentstack
35
+ >>> client = contentstack.client(authtoken='your_authtoken')
36
+ >>> result = client.stack("api_key").delivery_token().find().json()
37
+
38
+ -------------------------------
39
+ """
40
+ return self .client .get (self .path , headers = self .client .headers )
41
+
42
+ def fetch (self ):
43
+ """
44
+ The "Get a single delivery token" request returns the details of all the delivery tokens created in a stack.
45
+ :return: Json, with delivery_token details.
46
+ -------------------------------
47
+ [Example:]
48
+
49
+ >>> from contentstack_management import contentstack
50
+ >>> client = contentstack.client(authtoken='your_authtoken')
51
+ >>> result = client.stack('api_key').delivery_token('delivery_token_uid').fetch().json()
52
+
53
+ -------------------------------
54
+ """
55
+ self .validate_uid ()
56
+ url = f"{ self .path } /{ self .delivery_token_uid } "
57
+ return self .client .get (url , headers = self .client .headers )
58
+
59
+
60
+ def create (self , data : dict ):
61
+ """
62
+ The Create delivery token request creates a delivery token in the stack.
63
+
64
+ :param data: The `data` parameter is the payload that you want to send in the request body. It
65
+ should be a dictionary or a JSON serializable object that you want to send as the request body
66
+ :return: Json, with delivery_token details.
67
+
68
+ -------------------------------
69
+ [Example:]
70
+ >>> data ={
71
+ >>> "token":{
72
+ >>> "name":"Test",
73
+ >>> "description":"This is a demo token.",
74
+ >>> "scope":[
75
+ >>> {
76
+ >>> "module":"environment",
77
+ >>> "environments":[
78
+ >>> "production"
79
+ >>> ],
80
+ >>> "acl":{
81
+ >>> "read":true
82
+ >>> }
83
+ >>> },
84
+ >>> {
85
+ >>> "module":"branch",
86
+ >>> "branches":[
87
+ >>> "main",
88
+ >>> "development"
89
+ >>> ],
90
+ >>> "acl":{
91
+ >>> "read":true
92
+ >>> }
93
+ >>> },
94
+ >>> {
95
+ >>> "module":"branch_alias",
96
+ >>> "branch_aliases":[
97
+ >>> "deploy",
98
+ >>> "release"
99
+ >>> ],
100
+ >>> "acl":{
101
+ >>> "read":true
102
+ >>> }
103
+ >>> }
104
+ >>> ]
105
+ >>> }
106
+ >>> }
107
+ >>> from contentstack_management import contentstack
108
+ >>> client = contentstack.client(authtoken='your_authtoken')
109
+ >>> result = client.stack('api_key').delivery_token().create(data).json()
110
+
111
+ -------------------------------
112
+ """
113
+
114
+ data = json .dumps (data )
115
+ return self .client .post (self .path , headers = self .client .headers , data = data )
116
+
117
+ def update (self , data : dict ):
118
+ """
119
+ The "Update delivery token" request lets you update the details of a delivery token.
120
+
121
+ :param data: The `data` parameter is the data that you want to update. It should be a dictionary
122
+ or an object that can be serialized to JSON
123
+ :return: Json, with updated delivery_token details.
124
+ -------------------------------
125
+ [Example:]
126
+ >>> data = {
127
+ >>> "token":{
128
+ >>> "name":"Test",
129
+ >>> "description":"This is a updated token.",
130
+ >>> "scope":[
131
+ >>> {
132
+ >>> "module":"environment",
133
+ >>> "environments":[
134
+ >>> "production"
135
+ >>> ],
136
+ >>> "acl":{
137
+ >>> "read":true
138
+ >>> }
139
+ >>> },
140
+ >>> {
141
+ >>> "module":"branch",
142
+ >>> "branches":[
143
+ >>> "main",
144
+ >>> "development"
145
+ >>> ],
146
+ >>> "acl":{
147
+ >>> "read":true
148
+ >>> }
149
+ >>> },
150
+ >>> {
151
+ >>> "module":"branch_alias",
152
+ >>> "branch_aliases":[
153
+ >>> "deploy"
154
+ >>> ],
155
+ >>> "acl":{
156
+ >>> "read":true
157
+ >>> }
158
+ >>> }
159
+ >>> ]
160
+ >>> }
161
+ >>> }
162
+ >>> from contentstack_management import contentstack
163
+ >>> client = contentstack.client(authtoken='your_authtoken')
164
+ >>> result = client.stack('api_key').delivery_token("delivery_token_uid").update(data).json()
165
+
166
+ -------------------------------
167
+ """
168
+ self .validate_uid ()
169
+ url = f"{ self .path } /{ self .delivery_token_uid } "
170
+ data = json .dumps (data )
171
+ return self .client .put (url , headers = self .client .headers , data = data )
172
+
173
+
174
+ def delete (self ):
175
+ """
176
+ The "Delete delivery token" request deletes a specific delivery token.
177
+
178
+ :return: The delete() method returns the status code and message as a response.
179
+
180
+ -------------------------------
181
+ [Example:]
182
+
183
+ >>> from contentstack_management import contentstack
184
+ >>> client = contentstack.client(authtoken='your_authtoken')
185
+ >>> result = client.stack('api_key').delivery_token('delivery_token_uid').delete().json()
186
+
187
+ -------------------------------
188
+ """
189
+ self .validate_uid ()
190
+ url = f"{ self .path } /{ self .delivery_token_uid } "
191
+ return self .client .delete (url , headers = self .client .headers )
192
+
193
+ def validate_uid (self ):
194
+ if self .delivery_token_uid is None or '' :
195
+ raise ArgumentException ("Delivery Token Uid is required" )
0 commit comments