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 BulkOperation (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 ):
20+ self .client = client
21+ super ().__init__ (self .client )
22+ self .path = "bulk"
23+
24+
25+ def publish (self , data : dict ):
26+ """
27+ The Publish entries and assets in bulk request allows you to publish multiple entries and assets at the same time.
28+
29+ :param data: The `data` parameter is a dictionary that contains the data to be published
30+ :type data: dict
31+ :return: The `publish` method is returning the result of the `post` request made by the
32+ `client.post` method.
33+ -------------------------------
34+ [Example:]
35+ >>> data = {
36+ >>> "entries":[
37+ >>> {
38+ >>> "uid":"entry_uid",
39+ >>> "content_type":"ct0",
40+ >>> "version":"5",
41+ >>> "locale":"en-us"
42+ >>> },
43+ >>> {
44+ >>> "uid":"entry_uid",
45+ >>> "content_type":"ct0",
46+ >>> "version":"1",
47+ >>> "locale":"en-us"
48+ >>> },
49+ >>> {
50+ >>> "uid":"entry_uid",
51+ >>> "content_type":"ct5",
52+ >>> "version":"2",
53+ >>> "locale":"en-us"
54+ >>> }
55+ >>> ],
56+ >>> "locales":[
57+ >>> "en-us"
58+ >>> ],
59+ >>> "environments":[
60+ >>> "env1"
61+ >>> ],
62+ >>> "rules":{
63+ >>> "approvals":"true/false"
64+ >>> },
65+ >>> "scheduled_at":"scheduled_time",
66+ >>> "publish_with_reference":true
67+ >>> }
68+ >>> from contentstack_management import contentstack
69+ >>> client = contentstack.client(authtoken='your_authtoken')
70+ >>> result = client.stack('api_key').bulk_operation().publish(data).json()
71+
72+ -------------------------------
73+ """
74+ url = f"{ self .path } /publish"
75+ data = json .dumps (data )
76+ return self .client .post (url , headers = self .client .headers , data = data )
77+
78+ def unpublish (self , data : dict ):
79+ """
80+ The Unpublish entries and assets in bulk request allows you to unpublish multiple entries and assets at the same time.
81+
82+ :param data: The `data` parameter is a dictionary that contains the information needed to
83+ unpublish a resource. The specific keys and values in the dictionary will depend on the
84+ requirements of the API you are using
85+ :type data: dict
86+ :return: The method is returning the result of the `post` request made to the specified URL.
87+ -------------------------------
88+ [Example:]
89+ >>> data = {
90+ >>> "entries": [
91+ >>> {
92+ >>> "content_type": "news",
93+ >>> "uid": "entry_uid",
94+ >>> "locale": "en-us"
95+ >>> },
96+ >>> {
97+ >>> "content_type": "article",
98+ >>> "uid": "entry_uid",
99+ >>> "locale": "en-us"
100+ >>> }
101+ >>> ],
102+ >>> "workflow": {
103+ >>> "workflow_stage": {
104+ >>> "comment": "String Comment",
105+ >>> "due_date": "Thu Dec 01 2018",
106+ >>> "notify": false,
107+ >>> "uid": "workflow_uid",
108+ >>> "assigned_to": [
109+ >>> {
110+ >>> "uid": "user_uid",
111+ >>> "name": "user_name",
112+ >>> "email": "user_email_ID"
113+ >>> }
114+ >>> ],
115+ >>> "assigned_by_roles": [
116+ >>> {
117+ >>> "uid": "role_uid",
118+ >>> "name": "Content Manager"
119+ >>> }
120+ >>> ]
121+ >>> }
122+ >>> },
123+ >>> "locales": [
124+ >>> "en-us"
125+ >>> ],
126+ >>> "environments": [
127+ >>> "env_uid"
128+ >>> ]
129+ >>> }
130+ >>> from contentstack_management import contentstack
131+ >>> client = contentstack.client(authtoken='your_authtoken')
132+ >>> result = client.stack('api_key').bulk_operation().unpublish(data).json()
133+
134+ -------------------------------
135+ """
136+
137+ url = f"{ self .path } /unpublish"
138+ data = json .dumps (data )
139+ return self .client .post (url , headers = self .client .headers , data = data )
140+
141+ def delete (self , data : dict ):
142+ """
143+ The Delete entries and assets in bulk request allows you to delete multiple entries and assets at the same time.
144+
145+ :param data: The `data` parameter is a dictionary that contains the information needed to delete
146+ or unpublish a resource. The specific contents of the dictionary will depend on the requirements
147+ of the API you are using
148+ :type data: dict
149+ :return: the result of the `post` request made to the specified URL.
150+ -------------------------------
151+ [Example:]
152+ >>> data = {
153+ >>> "entries":[{
154+ >>> "content_type":"content_type_uid",
155+ >>> "uid":"entry_uid",
156+ >>> "locale":"locale"
157+ >>> },{
158+ >>> "content_type":"content_type_uid",
159+ >>> "uid":"entry_uid",
160+ >>> "locale":"entry_locale"
161+ >>> }
162+ >>> ],
163+ >>> "assets": [{
164+ >>> "uid": "uid"
165+ >>> }]
166+ >>> }
167+ >>> from contentstack_management import contentstack
168+ >>> client = contentstack.client(authtoken='your_authtoken')
169+ >>> result = client.stack('api_key').bulk_operation().delete(data).json()
170+
171+ -------------------------------
172+ """
173+
174+ url = f"{ self .path } /delete"
175+ data = json .dumps (data )
176+ return self .client .post (url , headers = self .client .headers , data = data )
177+
178+ def update (self , data : dict ):
179+ """
180+ The above function updates the bulk_operation of an object by sending a POST request to the specified
181+ URL with the provided data.
182+
183+ :param data: The `data` parameter is a dictionary that contains the information to be updated.
184+ It is converted to a JSON string using the `json.dumps()` function before being sent in the
185+ request
186+ :type data: dict
187+ :return: the result of the `post` request made to the specified URL with the provided headers
188+ and data.
189+ -------------------------------
190+ [Example:]
191+ >>> data = {
192+ >>> "entries": [{
193+ >>> "content_type": "content_type_uid1",
194+ >>> "uid": "entry_uid",
195+ >>> "locale": "en-us"
196+ >>> }, {
197+ >>> "content_type": "content_type_uid2",
198+ >>> "uid": "entry_uid",
199+ >>> "locale": "en-us"
200+ >>> }],
201+ >>> "workflow": {
202+ >>> "workflow_stage": {
203+ >>> "comment": "Workflow-related Comments",
204+ >>> "due_date": "Thu Dec 01 2018",
205+ >>> "notify": false,
206+ >>> "uid": "workflow_stage_uid",
207+ >>> "assigned_to": [{
208+ >>> "uid": "user_uid",
209+ >>> "name": "user_name",
210+ >>> "email": "user_email_id"
211+ >>> }],
212+ >>> "assigned_by_roles": [{
213+ >>> "uid": "role_uid",
214+ >>> "name": "role_name"
215+ >>> }]
216+ >>> }
217+ >>> }
218+ >>> }
219+ >>> from contentstack_management import contentstack
220+ >>> client = contentstack.client(authtoken='your_authtoken')
221+ >>> result = client.stack('api_key').bulk_operation().update(data).json()
222+
223+ -------------------------------
224+ """
225+
226+ url = f"{ self .path } /workflow"
227+ data = json .dumps (data )
228+ return self .client .post (url , headers = self .client .headers , data = data )
229+
230+
0 commit comments