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 ReleaseItems (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 , release_uid : str ):
20+ self .client = client
21+ self .release_uid = release_uid
22+ super ().__init__ (self .client )
23+ self .path = f"releases/{ self .release_uid } "
24+
25+ def find (self ):
26+ """
27+ The "Get all items in a Release request" retrieves a list of all items (entries and assets) that are part of a specific Release.
28+ :return: Json, with releases details.
29+
30+ -------------------------------
31+ [Example:]
32+
33+ >>> from contentstack_management import contentstack
34+ >>> client = contentstack.client(authtoken='your_authtoken')
35+ >>> result = client.stack("api_key").releases("release_uid").item().find()
36+
37+ -------------------------------
38+ """
39+ url = f"{ self .path } /items"
40+ return self .client .get (url , headers = self .client .headers )
41+
42+
43+ def create (self , data : dict ):
44+ """
45+ The "Add a single item to a Release" request allows you to add an item (entry or asset) to a Release.
46+
47+ :param data: The `data` parameter is a dictionary that contains the data to be sent in the
48+ request body. It will be converted to a JSON string using the `json.dumps()` function before
49+ being sent in the request
50+ :type data: dict
51+ :return: The code is returning the result of the `post` method call on the `self.client` object.
52+
53+ -------------------------------
54+ [Example:]
55+ >>> data ={
56+ >>> "item": {
57+ >>> "version": 1,
58+ >>> "uid": "entry_or_asset_uid",
59+ >>> "content_type_uid": "your_content_type_uid",
60+ >>> "action": "publish",
61+ >>> "locale": "en-us"
62+ >>> }
63+ >>> }
64+ >>> from contentstack_management import contentstack
65+ >>> client = contentstack.client(authtoken='your_authtoken')
66+ >>> result = client.stack('api_key').releases('release_uid').item().create(data)
67+ -------------------------------
68+ """
69+
70+ data = json .dumps (data )
71+ url = f"{ self .path } /item"
72+ return self .client .post (url , headers = self .client .headers , data = data )
73+
74+ def create_multiple (self , data : dict ):
75+ """
76+ The "Add multiple items to a Release" request allows you to add multiple items (entries and/or assets) to a Release.
77+
78+ :param data: The `data` parameter is a dictionary that contains the data to be sent in the
79+ request body. It will be converted to a JSON string using the `json.dumps()` function before
80+ being sent in the request
81+ :type data: dict
82+ :return: The code is returning the result of the `post` method call on the `self.client` object.
83+
84+ -------------------------------
85+ [Example:]
86+ >>> data ={
87+ >>> "items": [{
88+ >>> "uid": "entry_or_asset_uid1",
89+ >>> "version": 1,
90+ >>> "locale": "en-us",
91+ >>> "content_type_uid": "demo1",
92+ >>> "action": "publish"
93+ >>> }, {
94+ >>> "uid": "entry_or_asset_uid2",
95+ >>> "version": 4,
96+ >>> "locale": "fr-fr",
97+ >>> "content_type_uid": "demo2",
98+ >>> "action": "publish"
99+ >>> }]
100+ >>> }
101+ >>> from contentstack_management import contentstack
102+ >>> client = contentstack.client(authtoken='your_authtoken')
103+ >>> result = client.stack('api_key').releases('release_uid').item().create_multiple(data)
104+ -------------------------------
105+ """
106+
107+ data = json .dumps (data )
108+ url = f"{ self .path } /items"
109+ return self .client .post (url , headers = self .client .headers , data = data )
110+
111+ def update (self , data : dict ):
112+ """
113+ 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
114+
115+ :param data: A dictionary containing the data to be updated
116+ :type data: dict
117+ :param item_uid: The `item_uid` parameter is a string that represents the unique identifier of
118+ the item you want to update
119+ :type item_uid: str
120+ :return: the result of the `self.client.put()` method, which is the response from making a PUT
121+ request to the specified URL with the provided data and headers.
122+
123+ -------------------------------
124+ [Example:]
125+ >>> data ={
126+ >>> "items":[
127+ >>> "$all"
128+ >>> ]
129+ >>> }
130+ >>> from contentstack_management import contentstack
131+ >>> client = contentstack.client(authtoken='your_authtoken')
132+ >>> result = client.stack('api_key').releases("release_uid").item().update(data)
133+
134+ -------------------------------
135+ """
136+
137+ self .validate_release_uid ()
138+ url = f"{ self .path } /update_items"
139+ data = json .dumps (data )
140+ return self .client .put (url , headers = self .client .headers , data = data )
141+
142+
143+ def delete (self , data : dict ):
144+ """
145+ The "Remove an item from a Release" request removes one or more items (entries and/or assets) from a specific Release.
146+
147+ :param item_uid: The `item_uid` parameter is a string that represents the unique identifier of
148+ the item you want to delete
149+ :type item_uid: str
150+ :return: the result of the delete request made to the specified URL.
151+
152+ -------------------------------
153+ [Example:]
154+ >>> data = {
155+ >>> "items": [{
156+ >>> "uid": "items_uid",
157+ >>> "version": 1,
158+ >>> "locale": "ja-jp",
159+ >>> "content_type_uid": "category",
160+ >>> "action": "publish"
161+ >>> }]
162+ >>> }
163+ >>> from contentstack_management import contentstack
164+ >>> client = contentstack.client(authtoken='your_authtoken')
165+ >>> result = result = client.stack('api_key').releases('release_uid').item().delete(data)
166+
167+ -------------------------------
168+ """
169+
170+ self .validate_release_uid ()
171+ url = f"{ self .path } /items"
172+ data = json .dumps (data )
173+ return self .client .delete (url , headers = self .client .headers , data = data )
174+
175+ def delete_multiple (self , data : dict ):
176+ """
177+ The "Remove an item from a Release" request removes one or more items (entries and/or assets) from a specific Release.
178+
179+ :param item_uid: The `item_uid` parameter is a string that represents the unique identifier of
180+ the item you want to delete
181+ :type item_uid: str
182+ :return: the result of the delete request made to the specified URL.
183+
184+ -------------------------------
185+ [Example:]
186+ >>> data = {
187+ >>> "items": [{
188+ >>> "uid": "item_uid",
189+ >>> "locale": "en-us",
190+ >>> "version": 1,
191+ >>> "content_type_uid": "your_content_type_uid",
192+ >>> "action": "publish_or_unpublish"
193+ >>> }]
194+ >>> }
195+ >>> from contentstack_management import contentstack
196+ >>> client = contentstack.client(authtoken='your_authtoken')
197+ >>> result = result = client.stack('api_key').releases('release_uid').item().delete_multiple(data)
198+
199+ -------------------------------
200+ """
201+ self .validate_release_uid ()
202+ url = f"{ self .path } /items"
203+ Parameter .add_param (self , "all" , True )
204+ data = json .dumps (data )
205+ return self .client .delete (url , headers = self .client .headers , data = data )
206+
207+ def validate_release_uid (self ):
208+ if self .release_uid is None or '' :
209+ raise ArgumentException ('Releases Uid is required' )
210+
211+
212+
213+
214+
0 commit comments