Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,12 @@ fileignoreconfig:
- filename: tests/unit/terms/test_terms_unit.py
checksum: 1723d11c8e22d67e28409c0868781c3e4ec7e1d8e97d63e718716d26e486c8ad
version: ""
fileignoreconfig:
- filename: tests/mock/bulk_operations/test_bulk_operations_mock.py
checksum: f672aa30ff2595147a1de4bcaff1d42a3bd2242b70c139f03d2bf4c3f86d9185
- filename: tests/api/bulk_operations/test_bulk_operations_api.py
checksum: 1cd949c89caaea5b4a7560627a2c745ceec292adbed382450b6a88444a0b667e
- filename: tests/unit/bulk_operations/test_bulk_operations_unit.py
checksum: 1cfaea5cacaef44f2154bd25150d599e6e7be541477b3cef2e909ab16ef86636
version: ""

4 changes: 4 additions & 0 deletions contentstack_management/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from .locale.locale import Locale
from .taxonomies.taxonomy import Taxonomy
from .labels.label import Label
from .terms.terms import Terms
from .bulk_operations.bulk_operation import BulkOperation


__all__ = (
Expand Down Expand Up @@ -50,6 +52,8 @@
"Locale",
"Taxonomy",
"Label",
"Terms",
"BulkOperation"
)

__title__ = 'contentstack-management-python'
Expand Down
1 change: 1 addition & 0 deletions contentstack_management/bulk_operations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from contentstack_management import contentstack
230 changes: 230 additions & 0 deletions contentstack_management/bulk_operations/bulk_operation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
"""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 BulkOperation(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):
self.client = client
super().__init__(self.client)
self.path = "bulk"


def publish(self, data: dict):
"""
The Publish entries and assets in bulk request allows you to publish multiple entries and assets at the same time.

:param data: The `data` parameter is a dictionary that contains the data to be published
:type data: dict
:return: The `publish` method is returning the result of the `post` request made by the
`client.post` method.
-------------------------------
[Example:]
>>> data = {
>>> "entries":[
>>> {
>>> "uid":"entry_uid",
>>> "content_type":"ct0",
>>> "version":"5",
>>> "locale":"en-us"
>>> },
>>> {
>>> "uid":"entry_uid",
>>> "content_type":"ct0",
>>> "version":"1",
>>> "locale":"en-us"
>>> },
>>> {
>>> "uid":"entry_uid",
>>> "content_type":"ct5",
>>> "version":"2",
>>> "locale":"en-us"
>>> }
>>> ],
>>> "locales":[
>>> "en-us"
>>> ],
>>> "environments":[
>>> "env1"
>>> ],
>>> "rules":{
>>> "approvals":"true/false"
>>> },
>>> "scheduled_at":"scheduled_time",
>>> "publish_with_reference":true
>>> }
>>> from contentstack_management import contentstack
>>> client = contentstack.client(authtoken='your_authtoken')
>>> result = client.stack('api_key').bulk_operation().publish(data).json()

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

def unpublish(self, data: dict):
"""
The Unpublish entries and assets in bulk request allows you to unpublish multiple entries and assets at the same time.

:param data: The `data` parameter is a dictionary that contains the information needed to
unpublish a resource. The specific keys and values in the dictionary will depend on the
requirements of the API you are using
:type data: dict
:return: The method is returning the result of the `post` request made to the specified URL.
-------------------------------
[Example:]
>>> data = {
>>> "entries": [
>>> {
>>> "content_type": "news",
>>> "uid": "entry_uid",
>>> "locale": "en-us"
>>> },
>>> {
>>> "content_type": "article",
>>> "uid": "entry_uid",
>>> "locale": "en-us"
>>> }
>>> ],
>>> "workflow": {
>>> "workflow_stage": {
>>> "comment": "String Comment",
>>> "due_date": "Thu Dec 01 2018",
>>> "notify": false,
>>> "uid": "workflow_uid",
>>> "assigned_to": [
>>> {
>>> "uid": "user_uid",
>>> "name": "user_name",
>>> "email": "user_email_ID"
>>> }
>>> ],
>>> "assigned_by_roles": [
>>> {
>>> "uid": "role_uid",
>>> "name": "Content Manager"
>>> }
>>> ]
>>> }
>>> },
>>> "locales": [
>>> "en-us"
>>> ],
>>> "environments": [
>>> "env_uid"
>>> ]
>>> }
>>> from contentstack_management import contentstack
>>> client = contentstack.client(authtoken='your_authtoken')
>>> result = client.stack('api_key').bulk_operation().unpublish(data).json()

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

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

def delete(self, data: dict):
"""
The Delete entries and assets in bulk request allows you to delete multiple entries and assets at the same time.

:param data: The `data` parameter is a dictionary that contains the information needed to delete
or unpublish a resource. The specific contents of the dictionary will depend on the requirements
of the API you are using
:type data: dict
:return: the result of the `post` request made to the specified URL.
-------------------------------
[Example:]
>>> data = {
>>> "entries":[{
>>> "content_type":"content_type_uid",
>>> "uid":"entry_uid",
>>> "locale":"locale"
>>> },{
>>> "content_type":"content_type_uid",
>>> "uid":"entry_uid",
>>> "locale":"entry_locale"
>>> }
>>> ],
>>> "assets": [{
>>> "uid": "uid"
>>> }]
>>> }
>>> from contentstack_management import contentstack
>>> client = contentstack.client(authtoken='your_authtoken')
>>> result = client.stack('api_key').bulk_operation().delete(data).json()

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

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

def update(self, data: dict):
"""
The above function updates the bulk_operation of an object by sending a POST request to the specified
URL with the provided data.

:param data: The `data` parameter is a dictionary that contains the information to be updated.
It is converted to a JSON string using the `json.dumps()` function before being sent in the
request
:type data: dict
:return: the result of the `post` request made to the specified URL with the provided headers
and data.
-------------------------------
[Example:]
>>> data = {
>>> "entries": [{
>>> "content_type": "content_type_uid1",
>>> "uid": "entry_uid",
>>> "locale": "en-us"
>>> }, {
>>> "content_type": "content_type_uid2",
>>> "uid": "entry_uid",
>>> "locale": "en-us"
>>> }],
>>> "workflow": {
>>> "workflow_stage": {
>>> "comment": "Workflow-related Comments",
>>> "due_date": "Thu Dec 01 2018",
>>> "notify": false,
>>> "uid": "workflow_stage_uid",
>>> "assigned_to": [{
>>> "uid": "user_uid",
>>> "name": "user_name",
>>> "email": "user_email_id"
>>> }],
>>> "assigned_by_roles": [{
>>> "uid": "role_uid",
>>> "name": "role_name"
>>> }]
>>> }
>>> }
>>> }
>>> from contentstack_management import contentstack
>>> client = contentstack.client(authtoken='your_authtoken')
>>> result = client.stack('api_key').bulk_operation().update(data).json()

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

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


4 changes: 4 additions & 0 deletions contentstack_management/stack/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ..locale.locale import Locale
from ..taxonomies.taxonomy import Taxonomy
from ..labels.label import Label
from ..bulk_operations.bulk_operation import BulkOperation



Expand Down Expand Up @@ -352,4 +353,7 @@ def taxonomy(self, taxonomy_uid: str = None):

def label(self, label_uid: str = None):
return Label(self.client, label_uid)

def bulk_operation(self):
return BulkOperation(self.client)

Loading