Skip to content
Merged

Next #34

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
91a4390
Added users and organisations api methods
sunil-lakshman May 22, 2023
4c7f587
added requirements.txt file
sunil-lakshman May 23, 2023
6944e1c
loaded install, changlog , codeowners and release.yml file
sunil-lakshman May 23, 2023
a35426f
Organized package structure
sunil-lakshman May 24, 2023
4b0777e
Merge branch 'next' into feat/cs-38768-stack-implementation
sunil-lakshman May 24, 2023
1c4eb48
Developed stack Implementation
sunil-lakshman May 26, 2023
1d14bce
Code Optimized
sunil-lakshman May 29, 2023
24d3927
Added Mock test and Api Test cases
sunil-lakshman Jun 5, 2023
44880e1
Added test cases and coverage packages
sunil-lakshman Jun 7, 2023
55eaf55
Added API documentation and added stacks test cases
sunil-lakshman Jun 12, 2023
faf700d
Added coverage reports generartion in github action
sunil-lakshman Jul 6, 2023
d224cc3
Added global fields class
sunil-lakshman Jul 6, 2023
7c5d513
- General code improvements
ishaileshmishra Jul 6, 2023
d84e1ef
Merge pull request #8 from contentstack/fix/general-improvements
ishaileshmishra Jul 6, 2023
c1b1c80
Feat/cs 40287 workflow class implemetation (#14)
sunil-lakshman Sep 8, 2023
8a16b18
Feat/cs 41199 label class implementation (#25)
sunil-lakshman Sep 15, 2023
a2fb234
Merge branch 'main' into next
sunil-lakshman Sep 15, 2023
9793243
Feat/cs 41332 terms class implemetation (#27)
sunil-lakshman Sep 21, 2023
4aa0424
Merge branch 'main' into next
sunil-lakshman Sep 21, 2023
68b6b25
Added bulk operations class implementation (#29)
sunil-lakshman Sep 27, 2023
25e541a
Merge branch 'next' of https://github.com/contentstack/contentstack-m…
sunil-lakshman Sep 27, 2023
e628ae2
Added release and release item class implementation (#31)
sunil-lakshman Sep 28, 2023
a63683b
Merge branch 'main' into next
sunil-lakshman Sep 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,18 @@ fileignoreconfig:
- filename: tests/unit/bulk_operations/test_bulk_operations_unit.py
checksum: 1cfaea5cacaef44f2154bd25150d599e6e7be541477b3cef2e909ab16ef86636
version: ""
fileignoreconfig:
- filename: tests/mock/releases/test_releases_mock.py
checksum: b519703e910b645882404ba508e5b64132b24130f204f1d4791d4faad824e93b
- filename: tests/api/release_items/test_release_items_api.py
checksum: 5258ca032ee32626fafd9fd7af27c1399a2773319a33bd89761fabc579b15977
- filename: tests/api/releases/test_releases_api.py
checksum: 6250feb132ce2ddd1ca3607cb04bc30f47ffc8f7bcf495e5b09a03cd99eae8b5
- filename: tests/mock/release_items/test_release_items_mock.py
checksum: 98def0f6650518882a8cbcc3b2ea8fe243795d08c7059d1885ba73f37d7c4aa3
- filename: tests/unit/release_items/test_release_items_unit.py
checksum: 0bf883a9918b0669266d1a736538d2492e0287e152424d1164a258afa31ddc72
- filename: tests/unit/releases/test_release_unit.py
checksum: ffef2e354ac901eafd0f0aa8a95394892ec23b9d8b807de3e096a28536a75126
version: ""

6 changes: 5 additions & 1 deletion contentstack_management/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from .labels.label import Label
from .terms.terms import Terms
from .bulk_operations.bulk_operation import BulkOperation
from .releases.release import Releases
from .release_items.release_item import ReleaseItems


__all__ = (
Expand Down Expand Up @@ -53,7 +55,9 @@
"Taxonomy",
"Label",
"Terms",
"BulkOperation"
"BulkOperation",
"Releases",
"ReleaseItems"
)

__title__ = 'contentstack-management-python'
Expand Down
4 changes: 2 additions & 2 deletions contentstack_management/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def post(self, path, data=None, json_data=None, headers=None, params=None, files
# headers = headers or {}
return self._call_request('POST', url, headers=headers, params=params, data=data, json_data=json_data, files=files)

def delete(self, path, headers=None, params=None):
def delete(self, path, headers=None, params=None, data=None):
"""
The function sends a DELETE request to a specified URL with optional headers and parameters.

Expand All @@ -150,4 +150,4 @@ def delete(self, path, headers=None, params=None):

url = f"{self.endpoint}{path}"
# headers = headers or {}
return self._call_request('DELETE', url, headers=headers, params=params)
return self._call_request('DELETE', url, headers=headers, params=params, data = data)
1 change: 1 addition & 0 deletions contentstack_management/release_items/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from contentstack_management import contentstack
214 changes: 214 additions & 0 deletions contentstack_management/release_items/release_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
"""This class takes a base URL as an argument when it's initialized,
which is the endpoint for the RESTFUL API that we'll be interacting with.
The create(), read(), update(), and delete() methods each correspond to
the CRUD operations that can be performed on the API """

import json
from ..common import Parameter
from urllib.parse import quote
from .._errors import ArgumentException

class ReleaseItems(Parameter):
"""
This class takes a base URL as an argument when it's initialized,
which is the endpoint for the RESTFUL API that
we'll be interacting with. The create(), read(), update(), and delete()
methods each correspond to the CRUD
operations that can be performed on the API """

def __init__(self, client, release_uid: str):
self.client = client
self.release_uid = release_uid
super().__init__(self.client)
self.path = f"releases/{self.release_uid}"

def find(self):
"""
The "Get all items in a Release request" retrieves a list of all items (entries and assets) that are part of a specific Release.
:return: Json, with releases details.

-------------------------------
[Example:]

>>> from contentstack_management import contentstack
>>> client = contentstack.client(authtoken='your_authtoken')
>>> result = client.stack("api_key").releases("release_uid").item().find()

-------------------------------
"""
url = f"{self.path}/items"
return self.client.get(url, headers = self.client.headers)


def create(self, data: dict):
"""
The "Add a single item to a Release" request allows you to add an item (entry or asset) to a Release.

:param data: The `data` parameter is a dictionary that contains the data to be sent in the
request body. It will be converted to a JSON string using the `json.dumps()` function before
being sent in the request
:type data: dict
:return: The code is returning the result of the `post` method call on the `self.client` object.

-------------------------------
[Example:]
>>> data ={
>>> "item": {
>>> "version": 1,
>>> "uid": "entry_or_asset_uid",
>>> "content_type_uid": "your_content_type_uid",
>>> "action": "publish",
>>> "locale": "en-us"
>>> }
>>> }
>>> from contentstack_management import contentstack
>>> client = contentstack.client(authtoken='your_authtoken')
>>> result = client.stack('api_key').releases('release_uid').item().create(data)
-------------------------------
"""

data = json.dumps(data)
url = f"{self.path}/item"
return self.client.post(url, headers = self.client.headers, data=data)

def create_multiple(self, data: dict):
"""
The "Add multiple items to a Release" request allows you to add multiple items (entries and/or assets) to a Release.

:param data: The `data` parameter is a dictionary that contains the data to be sent in the
request body. It will be converted to a JSON string using the `json.dumps()` function before
being sent in the request
:type data: dict
:return: The code is returning the result of the `post` method call on the `self.client` object.

-------------------------------
[Example:]
>>> data ={
>>> "items": [{
>>> "uid": "entry_or_asset_uid1",
>>> "version": 1,
>>> "locale": "en-us",
>>> "content_type_uid": "demo1",
>>> "action": "publish"
>>> }, {
>>> "uid": "entry_or_asset_uid2",
>>> "version": 4,
>>> "locale": "fr-fr",
>>> "content_type_uid": "demo2",
>>> "action": "publish"
>>> }]
>>> }
>>> from contentstack_management import contentstack
>>> client = contentstack.client(authtoken='your_authtoken')
>>> result = client.stack('api_key').releases('release_uid').item().create_multiple(data)
-------------------------------
"""

data = json.dumps(data)
url = f"{self.path}/items"
return self.client.post(url, headers = self.client.headers, data=data)

def update(self, data: dict):
"""
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

:param data: A dictionary containing the data to be updated
:type data: dict
:param item_uid: The `item_uid` parameter is a string that represents the unique identifier of
the item you want to update
:type item_uid: str
:return: the result of the `self.client.put()` method, which is the response from making a PUT
request to the specified URL with the provided data and headers.

-------------------------------
[Example:]
>>> data ={
>>> "items":[
>>> "$all"
>>> ]
>>> }
>>> from contentstack_management import contentstack
>>> client = contentstack.client(authtoken='your_authtoken')
>>> result = client.stack('api_key').releases("release_uid").item().update(data)

-------------------------------
"""

self.validate_release_uid()
url = f"{self.path}/update_items"
data = json.dumps(data)
return self.client.put(url, headers = self.client.headers, data=data)


def delete(self, data: dict):
"""
The "Remove an item from a Release" request removes one or more items (entries and/or assets) from a specific Release.

:param item_uid: The `item_uid` parameter is a string that represents the unique identifier of
the item you want to delete
:type item_uid: str
:return: the result of the delete request made to the specified URL.

-------------------------------
[Example:]
>>> data = {
>>> "items": [{
>>> "uid": "items_uid",
>>> "version": 1,
>>> "locale": "ja-jp",
>>> "content_type_uid": "category",
>>> "action": "publish"
>>> }]
>>> }
>>> from contentstack_management import contentstack
>>> client = contentstack.client(authtoken='your_authtoken')
>>> result = result = client.stack('api_key').releases('release_uid').item().delete(data)

-------------------------------
"""

self.validate_release_uid()
url = f"{self.path}/items"
data = json.dumps(data)
return self.client.delete(url, headers = self.client.headers, data=data)

def delete_multiple(self, data: dict):
"""
The "Remove an item from a Release" request removes one or more items (entries and/or assets) from a specific Release.

:param item_uid: The `item_uid` parameter is a string that represents the unique identifier of
the item you want to delete
:type item_uid: str
:return: the result of the delete request made to the specified URL.

-------------------------------
[Example:]
>>> data = {
>>> "items": [{
>>> "uid": "item_uid",
>>> "locale": "en-us",
>>> "version": 1,
>>> "content_type_uid": "your_content_type_uid",
>>> "action": "publish_or_unpublish"
>>> }]
>>> }
>>> from contentstack_management import contentstack
>>> client = contentstack.client(authtoken='your_authtoken')
>>> result = result = client.stack('api_key').releases('release_uid').item().delete_multiple(data)

-------------------------------
"""
self.validate_release_uid()
url = f"{self.path}/items"
Parameter.add_param(self, "all", True)
data = json.dumps(data)
return self.client.delete(url, headers = self.client.headers, data=data)

def validate_release_uid(self):
if self.release_uid is None or '':
raise ArgumentException('Releases Uid is required')





1 change: 1 addition & 0 deletions contentstack_management/releases/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from contentstack_management import contentstack
Loading