contentstack-management 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of contentstack-management might be problematic. Click here for more details.

Files changed (50) hide show
  1. contentstack_management-0.0.1/LICENSE +21 -0
  2. contentstack_management-0.0.1/PKG-INFO +124 -0
  3. contentstack_management-0.0.1/README.md +106 -0
  4. contentstack_management-0.0.1/contentstack_management/__init__.py +58 -0
  5. contentstack_management-0.0.1/contentstack_management/_api_client.py +153 -0
  6. contentstack_management-0.0.1/contentstack_management/_constant.py +58 -0
  7. contentstack_management-0.0.1/contentstack_management/_errors.py +10 -0
  8. contentstack_management-0.0.1/contentstack_management/aliases/__init__.py +1 -0
  9. contentstack_management-0.0.1/contentstack_management/aliases/aliases.py +91 -0
  10. contentstack_management-0.0.1/contentstack_management/assets/__init__.py +1 -0
  11. contentstack_management-0.0.1/contentstack_management/assets/assets.py +637 -0
  12. contentstack_management-0.0.1/contentstack_management/auditlogs/__init__.py +1 -0
  13. contentstack_management-0.0.1/contentstack_management/auditlogs/auditlog.py +65 -0
  14. contentstack_management-0.0.1/contentstack_management/branches/__init__.py +1 -0
  15. contentstack_management-0.0.1/contentstack_management/branches/branches.py +106 -0
  16. contentstack_management-0.0.1/contentstack_management/common.py +16 -0
  17. contentstack_management-0.0.1/contentstack_management/content_types/__init__.py +1 -0
  18. contentstack_management-0.0.1/contentstack_management/content_types/content_type.py +347 -0
  19. contentstack_management-0.0.1/contentstack_management/contentstack.py +87 -0
  20. contentstack_management-0.0.1/contentstack_management/entries/__init__.py +1 -0
  21. contentstack_management-0.0.1/contentstack_management/entries/entry.py +433 -0
  22. contentstack_management-0.0.1/contentstack_management/environments/__init__.py +0 -0
  23. contentstack_management-0.0.1/contentstack_management/environments/environment.py +139 -0
  24. contentstack_management-0.0.1/contentstack_management/global_fields/__init__.py +1 -0
  25. contentstack_management-0.0.1/contentstack_management/global_fields/global_fields.py +151 -0
  26. contentstack_management-0.0.1/contentstack_management/metadata/__init__.py +1 -0
  27. contentstack_management-0.0.1/contentstack_management/metadata/metadata.py +224 -0
  28. contentstack_management-0.0.1/contentstack_management/organizations/__init__.py +7 -0
  29. contentstack_management-0.0.1/contentstack_management/organizations/organization.py +159 -0
  30. contentstack_management-0.0.1/contentstack_management/roles/__init__.py +1 -0
  31. contentstack_management-0.0.1/contentstack_management/roles/roles.py +296 -0
  32. contentstack_management-0.0.1/contentstack_management/stack/__init__.py +0 -0
  33. contentstack_management-0.0.1/contentstack_management/stack/stack.py +342 -0
  34. contentstack_management-0.0.1/contentstack_management/user_session/__init__.py +1 -0
  35. contentstack_management-0.0.1/contentstack_management/user_session/user_session.py +85 -0
  36. contentstack_management-0.0.1/contentstack_management/users/__init__.py +1 -0
  37. contentstack_management-0.0.1/contentstack_management/users/user.py +146 -0
  38. contentstack_management-0.0.1/contentstack_management/webhooks/__init__.py +1 -0
  39. contentstack_management-0.0.1/contentstack_management/webhooks/webhook.py +325 -0
  40. contentstack_management-0.0.1/contentstack_management/workflows/__init__.py +0 -0
  41. contentstack_management-0.0.1/contentstack_management/workflows/workflows.py +604 -0
  42. contentstack_management-0.0.1/contentstack_management.egg-info/PKG-INFO +124 -0
  43. contentstack_management-0.0.1/contentstack_management.egg-info/SOURCES.txt +48 -0
  44. contentstack_management-0.0.1/contentstack_management.egg-info/dependency_links.txt +1 -0
  45. contentstack_management-0.0.1/contentstack_management.egg-info/requires.txt +7 -0
  46. contentstack_management-0.0.1/contentstack_management.egg-info/top_level.txt +6 -0
  47. contentstack_management-0.0.1/pyproject.toml +18 -0
  48. contentstack_management-0.0.1/setup.cfg +4 -0
  49. contentstack_management-0.0.1/setup.py +31 -0
  50. contentstack_management-0.0.1/tests/test_contentstack.py +53 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2012 - 2023 Contentstack. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,124 @@
1
+ Metadata-Version: 2.1
2
+ Name: contentstack_management
3
+ Version: 0.0.1
4
+ Summary: Contentstack API Client Library for Python
5
+ Home-page: https://github.com/contentstack/contentstack-management-python
6
+ Author: Sunil
7
+ Author-email: sunil <sunil.lakshman@contentstack.com>
8
+ License: MIT
9
+ Project-URL: Homepage, https://github.com/contentstack/contentstack-management-python
10
+ Project-URL: Bug Tracker, https://github.com/contentstack/contentstack-management-python/issues
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown
16
+ Provides-Extra: dev
17
+ License-File: LICENSE
18
+
19
+ [![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)](https://www.contentstack.com/)
20
+
21
+ ## Contentstack Management Python SDK
22
+
23
+ Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. All you have to do is build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/).
24
+
25
+ This SDK uses the [Content Management API](https://www.contentstack.com/docs/developers/apis/content-management-api/) (CMA). The CMA is used to manage the content of your Contentstack account. This includes creating, updating, deleting, and fetching content of your account. To use the CMA, you will need to authenticate your users with a [Management Token](https://www.contentstack.com/docs/developers/create-tokens/about-management-tokens) or an [Authtoken](https://www.contentstack.com/docs/developers/apis/content-management-api/#how-to-get-authtoken). Read more about it in [Authentication](https://www.contentstack.com/docs/developers/apis/content-management-api/#authentication).
26
+
27
+ Note: By using CMA, you can execute GET requests for fetching content. However, we strongly recommend that you always use the [Content Delivery API](https://www.contentstack.com/docs/developers/apis/content-delivery-api/) to deliver content to your web or mobile properties.
28
+
29
+ ### Prerequisite
30
+
31
+ You will need python 3 installed on your machine. You can install it
32
+ from [here](https://www.python.org/ftp/python/3.7.4/python-3.7.4-macosx10.9.pkg).
33
+
34
+ ### Installation
35
+ #### Install contentstack pip
36
+
37
+ ```python
38
+ pip install contentstack_management
39
+ ```
40
+ To import the SDK, use the following command:
41
+ ```python
42
+ from contentstack_management import contentstack
43
+
44
+ client = contentstack.ContentstackClient()
45
+ ```
46
+
47
+ ### Authentication
48
+ To use this SDK, you need to authenticate your users by using the Authtoken, credentials, or Management Token (stack-level token).
49
+ ### Authtoken
50
+
51
+ An **Authtoken** is a read-write token used to make authorized CMA requests, and it is a **user-specific** token.
52
+ ```python
53
+ client = contentstack.ContentstackClient(authtoken= 'authtoken')
54
+ ```
55
+ ### Login
56
+ To Login to Contentstack by using credentials, you can use the following lines of code:
57
+ ```python
58
+ client.login(email="email", password="password")
59
+
60
+ ```
61
+
62
+ ### Management Token
63
+ **Management Tokens** are **stack-level** tokens, with no users attached to them.
64
+
65
+ ```python
66
+ result = client.stack(api_key = 'api_key', management_token= 'management_token' ).content_type('content_type_uid')
67
+ .fetch().json()
68
+ print(result)
69
+ ```
70
+ ### Contentstack Management Python SDK: 5-minute Quickstart
71
+ #### Initializing Your SDK:
72
+ To use the Python CMA SDK, you need to first initialize it. To do this, use the following code:
73
+
74
+ ```python
75
+ from contentstack_management import contentstack
76
+
77
+ client = contentstack.ContentstackClient(authtoken= 'authtoken')
78
+ ```
79
+ #### Fetch Stack Detail
80
+ Use the following lines of code to fetch your stack detail using this SDK:
81
+ ```python
82
+ result = client.stack(api_key= 'api_key').fetch().json()
83
+ print(result)
84
+ ```
85
+
86
+ #### Create Entry
87
+ To create an entry in a specific content type of a stack, use the following lines of code:
88
+
89
+ ```python
90
+ entry = {
91
+ title: 'Sample Entry',
92
+ url: '/sampleEntry'
93
+ }
94
+
95
+ result = client.stack(api_key= 'api_key').content_types('content_type_uid').entry().create(entry)
96
+ print(result.json())
97
+ ```
98
+
99
+ #### Create Asset
100
+ The following lines of code can be used to upload assets to your stack:
101
+
102
+ ```python
103
+ asset = {
104
+ upload: 'path/to/file',
105
+ title: 'Asset Title'
106
+ }
107
+ asset = client().stack(api_key='api_key').assets()
108
+ result = asset.upload(asset)
109
+ ```
110
+
111
+ ### Helpful Links
112
+
113
+ - [Contentstack Website](https://www.contentstack.com/)
114
+ - [Official Documentation](https://contentstack.com/docs)
115
+ - [Content Management API Docs](https://www.contentstack.com/docs/developers/apis/content-management-api)
116
+
117
+ ### The MIT License (MIT)
118
+ Copyright © 2012-2023 [Contentstack](https://www.contentstack.com/). All Rights Reserved
119
+
120
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
121
+
122
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
123
+
124
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,106 @@
1
+ [![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)](https://www.contentstack.com/)
2
+
3
+ ## Contentstack Management Python SDK
4
+
5
+ Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. All you have to do is build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/).
6
+
7
+ This SDK uses the [Content Management API](https://www.contentstack.com/docs/developers/apis/content-management-api/) (CMA). The CMA is used to manage the content of your Contentstack account. This includes creating, updating, deleting, and fetching content of your account. To use the CMA, you will need to authenticate your users with a [Management Token](https://www.contentstack.com/docs/developers/create-tokens/about-management-tokens) or an [Authtoken](https://www.contentstack.com/docs/developers/apis/content-management-api/#how-to-get-authtoken). Read more about it in [Authentication](https://www.contentstack.com/docs/developers/apis/content-management-api/#authentication).
8
+
9
+ Note: By using CMA, you can execute GET requests for fetching content. However, we strongly recommend that you always use the [Content Delivery API](https://www.contentstack.com/docs/developers/apis/content-delivery-api/) to deliver content to your web or mobile properties.
10
+
11
+ ### Prerequisite
12
+
13
+ You will need python 3 installed on your machine. You can install it
14
+ from [here](https://www.python.org/ftp/python/3.7.4/python-3.7.4-macosx10.9.pkg).
15
+
16
+ ### Installation
17
+ #### Install contentstack pip
18
+
19
+ ```python
20
+ pip install contentstack_management
21
+ ```
22
+ To import the SDK, use the following command:
23
+ ```python
24
+ from contentstack_management import contentstack
25
+
26
+ client = contentstack.ContentstackClient()
27
+ ```
28
+
29
+ ### Authentication
30
+ To use this SDK, you need to authenticate your users by using the Authtoken, credentials, or Management Token (stack-level token).
31
+ ### Authtoken
32
+
33
+ An **Authtoken** is a read-write token used to make authorized CMA requests, and it is a **user-specific** token.
34
+ ```python
35
+ client = contentstack.ContentstackClient(authtoken= 'authtoken')
36
+ ```
37
+ ### Login
38
+ To Login to Contentstack by using credentials, you can use the following lines of code:
39
+ ```python
40
+ client.login(email="email", password="password")
41
+
42
+ ```
43
+
44
+ ### Management Token
45
+ **Management Tokens** are **stack-level** tokens, with no users attached to them.
46
+
47
+ ```python
48
+ result = client.stack(api_key = 'api_key', management_token= 'management_token' ).content_type('content_type_uid')
49
+ .fetch().json()
50
+ print(result)
51
+ ```
52
+ ### Contentstack Management Python SDK: 5-minute Quickstart
53
+ #### Initializing Your SDK:
54
+ To use the Python CMA SDK, you need to first initialize it. To do this, use the following code:
55
+
56
+ ```python
57
+ from contentstack_management import contentstack
58
+
59
+ client = contentstack.ContentstackClient(authtoken= 'authtoken')
60
+ ```
61
+ #### Fetch Stack Detail
62
+ Use the following lines of code to fetch your stack detail using this SDK:
63
+ ```python
64
+ result = client.stack(api_key= 'api_key').fetch().json()
65
+ print(result)
66
+ ```
67
+
68
+ #### Create Entry
69
+ To create an entry in a specific content type of a stack, use the following lines of code:
70
+
71
+ ```python
72
+ entry = {
73
+ title: 'Sample Entry',
74
+ url: '/sampleEntry'
75
+ }
76
+
77
+ result = client.stack(api_key= 'api_key').content_types('content_type_uid').entry().create(entry)
78
+ print(result.json())
79
+ ```
80
+
81
+ #### Create Asset
82
+ The following lines of code can be used to upload assets to your stack:
83
+
84
+ ```python
85
+ asset = {
86
+ upload: 'path/to/file',
87
+ title: 'Asset Title'
88
+ }
89
+ asset = client().stack(api_key='api_key').assets()
90
+ result = asset.upload(asset)
91
+ ```
92
+
93
+ ### Helpful Links
94
+
95
+ - [Contentstack Website](https://www.contentstack.com/)
96
+ - [Official Documentation](https://contentstack.com/docs)
97
+ - [Content Management API Docs](https://www.contentstack.com/docs/developers/apis/content-management-api)
98
+
99
+ ### The MIT License (MIT)
100
+ Copyright © 2012-2023 [Contentstack](https://www.contentstack.com/). All Rights Reserved
101
+
102
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
103
+
104
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
105
+
106
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ """The __init__.py file that contains modules that need to import"""
2
+
3
+ from .organizations.organization import Organization
4
+ from .stack.stack import Stack
5
+ from .user_session.user_session import UserSession
6
+ from .users.user import User
7
+ from .aliases.aliases import Alias
8
+ from .assets.assets import Assets
9
+ from .branches.branches import Branch
10
+ from .content_types.content_type import ContentType
11
+ from .global_fields.global_fields import GlobalFields
12
+ from .webhooks.webhook import Webhook
13
+ from .workflows.workflows import Workflows
14
+ from .metadata.metadata import Metadata
15
+ from .roles.roles import Roles
16
+ from .auditlogs.auditlog import Auditlog
17
+ from .environments.environment import Environment
18
+ from .entries.entry import Entry
19
+ from .contentstack import ContentstackClient, ContentstackRegion
20
+ from ._api_client import _APIClient
21
+ from .common import Parameter
22
+ from ._errors import ArgumentException
23
+
24
+ __all__ = (
25
+ "ContentstackClient",
26
+ "ContentstackRegion",
27
+ "_APIClient",
28
+ "Parameter",
29
+ "ArgumentException",
30
+ "Organization",
31
+ "Stack",
32
+ "UserSession",
33
+ "User",
34
+ "Alias",
35
+ "Assets",
36
+ "Branch",
37
+ "ContentType",
38
+ "GlobalFields",
39
+ "Webhook",
40
+ "Workflows",
41
+ "Metadata",
42
+ "Roles",
43
+ "Auditlog",
44
+ "Environment",
45
+ "Entry",
46
+ )
47
+
48
+ __title__ = 'contentstack-management-python'
49
+ __author__ = 'ishaileshmishra'
50
+ __status__ = 'debug'
51
+ __region__ = 'na'
52
+ __version__ = '0.0.1'
53
+ __host__ = 'api.contentstack.io'
54
+ __protocol__ = 'https://'
55
+ __api_version__ = 'v3'
56
+ __endpoint__ = 'https://api.contentstack.io/v3/'
57
+ __email__ = 'mobile@contentstack.com'
58
+ __issues__ = 'support@contentstack.com'
@@ -0,0 +1,153 @@
1
+ import requests
2
+
3
+
4
+ class _APIClient:
5
+ def __init__(self, endpoint, headers, timeout=30, max_retries: int = 5):
6
+ """
7
+ The function is a constructor that initializes the endpoint, headers, timeout, and max_retries
8
+ attributes of an object.
9
+
10
+ :param endpoint: The `endpoint` parameter is the URL or address of the API endpoint that you
11
+ want to connect to. It is the destination where you will send your requests and receive
12
+ responses from
13
+ :param headers: The `headers` parameter is used to pass any additional headers that need to be
14
+ included in the HTTP request. Headers are used to provide additional information about the
15
+ request, such as authentication credentials or content type
16
+ :param timeout: The `timeout` parameter specifies the maximum amount of time (in seconds) that
17
+ the request should wait for a response before timing out, defaults to 30 (optional)
18
+ :param max_retries: The `max_retries` parameter is an integer that specifies the maximum number
19
+ of times a request should be retried if it fails. If a request fails, the code will attempt to
20
+ retry the request up to `max_retries` times before giving up, defaults to 5
21
+ :type max_retries: int (optional)
22
+ """
23
+
24
+ self.endpoint = endpoint
25
+ self.headers = headers
26
+ self.timeout = timeout
27
+ self.max_retries = max_retries
28
+ pass
29
+
30
+ def _call_request(self, method, url, headers: dict = None, params=None, data=None, json_data=None, files=None):
31
+ """
32
+ The function `_call_request` sends an HTTP request using the specified method, URL, headers,
33
+ parameters, data, and JSON data, and returns the response as a JSON object.
34
+
35
+ :param method: The HTTP method to be used for the request (e.g., GET, POST, PUT, DELETE, etc.)
36
+ :param url: The `url` parameter is a string that represents the URL of the API endpoint that you
37
+ want to make a request to
38
+ :param headers: The `headers` parameter is a dictionary that contains the HTTP headers to be
39
+ included in the request. These headers provide additional information about the request, such as
40
+ the content type or authentication credentials
41
+ :type headers: dict
42
+ :param params: The `params` parameter is used to pass query parameters in the URL. These
43
+ parameters are used to filter or modify the response from the server. For example, if you are
44
+ making a request to an API that returns a list of users, you can use the `params` parameter to
45
+ specify the number
46
+ :param data: The `data` parameter is used to send data in the body of the request. It is
47
+ typically used for sending form data or other types of data that are not in JSON format
48
+ :param json_data: The `json_data` parameter is used to send a JSON payload in the request. It is
49
+ typically used when making a POST or PUT request to send data to the server in JSON format. The
50
+ `json_data` parameter should be a dictionary that will be converted to JSON before sending the
51
+ request
52
+ :return: the JSON response from the HTTP request.
53
+ """
54
+
55
+ # headers.update(self.headers)
56
+ response = requests.request(
57
+ method, url, headers=headers, params=params, data=data, json=json_data, files=files)
58
+ # response.raise_for_status()
59
+ return response
60
+
61
+ def get(self, path, params=None, headers=None):
62
+ """
63
+ The function sends a GET request to a specified URL with optional parameters and headers.
64
+
65
+ :param path: The path parameter is a string that represents the endpoint or path of the API that
66
+ you want to make a GET request to. For example, if you want to make a GET request to the
67
+ "/users" endpoint, you would pass "/users" as the path parameter
68
+ :param params: The `params` parameter is used to pass query parameters in the URL. These
69
+ parameters are used to filter or modify the data being requested from the server. For example,
70
+ if you want to retrieve only the data for a specific user, you can pass the user ID as a query
71
+ parameter
72
+ :param headers: The `headers` parameter is a dictionary that contains any additional headers
73
+ that you want to include in the HTTP request. These headers can be used to provide additional
74
+ information to the server, such as authentication credentials or content type. If no headers are
75
+ provided, the `headers` parameter will default to `None
76
+ :return: The method is returning the result of the `_call_request` method.
77
+ """
78
+
79
+ url = f"{self.endpoint}{path}"
80
+ # self.headers = headers or {}
81
+ return self._call_request('GET', url, headers=headers, params=params)
82
+
83
+ def put(self, path, data=None, params=None, json_data=None, headers=None, files=None):
84
+ """
85
+ The function sends a PUT request to a specified URL with optional data, parameters, JSON data,
86
+ and headers.
87
+
88
+ :param path: The path parameter is the endpoint or URL path where the PUT request will be sent
89
+ to. It specifies the location of the resource that needs to be updated or modified
90
+ :param data: The `data` parameter is used to pass the request body data in the form of a string.
91
+ It is typically used for sending data in formats like JSON or XML
92
+ :param params: The `params` parameter is used to pass query parameters in the URL. These
93
+ parameters are used to filter or modify the data being requested from the server
94
+ :param json_data: The `json_data` parameter is used to pass JSON data in the request body. It is
95
+ typically used when making a PUT request to update or modify a resource on the server. The JSON
96
+ data should be a dictionary or a JSON serializable object
97
+ :param headers: The `headers` parameter is used to specify any additional headers that should be
98
+ included in the HTTP request. Headers are used to provide additional information about the
99
+ request, such as the content type or authentication credentials
100
+ :return: the result of calling the `_call_request` method with the specified parameters.
101
+ """
102
+
103
+ url = f"{self.endpoint}{path}"
104
+ # headers = headers or {}
105
+ return self._call_request('PUT', url, headers=headers, params=params, data=data, json_data=json_data, files=files)
106
+
107
+ def post(self, path, data=None, json_data=None, headers=None, params=None, files=None):
108
+ """
109
+ The function sends a POST request to a specified URL with optional data, headers, and
110
+ parameters.
111
+
112
+ :param path: The path parameter is the endpoint or URL path where the POST request will be sent
113
+ to. It is appended to the base URL or endpoint of the API
114
+ :param data: The `data` parameter is used to pass data in the request body. It can be a
115
+ dictionary, bytes, or a file-like object. This parameter is typically used for sending form data
116
+ or other types of data that are not in JSON format
117
+ :param json_data: The `json_data` parameter is used to pass JSON data in the request body. It is
118
+ typically used when sending data to an API that expects JSON data
119
+ :param headers: The `headers` parameter is used to specify any additional headers that should be
120
+ included in the HTTP request. Headers are used to provide additional information about the
121
+ request, such as the content type or authentication credentials
122
+ :param params: The `params` parameter is used to pass query parameters in the URL. Query
123
+ parameters are used to filter or sort the data being requested from the server. They are
124
+ appended to the URL after a question mark (?) and separated by ampersands (&). For example, if
125
+ you have a `params`
126
+ :return: The method is returning the result of the `_call_request` method.
127
+ """
128
+
129
+ url = f"{self.endpoint}{path}"
130
+ # headers = headers or {}
131
+ return self._call_request('POST', url, headers=headers, params=params, data=data, json_data=json_data, files=files)
132
+
133
+ def delete(self, path, headers=None, params=None):
134
+ """
135
+ The function sends a DELETE request to a specified URL with optional headers and parameters.
136
+
137
+ :param path: The `path` parameter is a string that represents the path of the resource you want
138
+ to delete. It is appended to the base URL to form the complete URL for the DELETE request
139
+ :param headers: The `headers` parameter is a dictionary that contains any additional headers
140
+ that you want to include in the DELETE request. These headers can be used to provide additional
141
+ information or authentication credentials to the server. If no headers are provided, the value
142
+ of `headers` will be set to `None`
143
+ :param params: The `params` parameter is used to pass query parameters in the URL. Query
144
+ parameters are used to filter or modify the data being requested. They are appended to the URL
145
+ after a question mark (?) and separated by ampersands (&). For example, if you want to filter
146
+ the data by a specific
147
+ :return: The method is returning the result of the `_call_request` method, which is the response
148
+ from the DELETE request made to the specified URL.
149
+ """
150
+
151
+ url = f"{self.endpoint}{path}"
152
+ # headers = headers or {}
153
+ return self._call_request('DELETE', url, headers=headers, params=params)
@@ -0,0 +1,58 @@
1
+ import platform
2
+ import sys
3
+
4
+
5
+ def _default_user_agent():
6
+ """
7
+ The function `_default_user_agent()` returns a dictionary containing information about the user
8
+ agent, including the SDK, app, platform, and operating system.
9
+ :return: a dictionary containing information about the user agent.
10
+ """
11
+
12
+ header = {
13
+ 'sdk': {
14
+ 'name': 'contentstack-management.python',
15
+ 'version': sys.version_info
16
+ },
17
+ 'app': {
18
+ 'name': 'contentstack-management.python',
19
+ 'version': '1.0.0'
20
+ },
21
+ 'platform': {
22
+ 'name': 'python',
23
+ 'version': platform.python_version()
24
+ }
25
+ }
26
+
27
+ os_name = platform.system()
28
+ if os_name == 'Darwin':
29
+ os_name = 'macOS'
30
+ elif not os_name or os_name == 'Java':
31
+ os_name = None
32
+ elif os_name not in ['macOS', 'Windows']:
33
+ os_name = 'Linux'
34
+
35
+ header['os'] = {
36
+ 'name': os_name,
37
+ 'version': platform.release() if os_name else None
38
+ }
39
+
40
+ return header
41
+
42
+
43
+ def _request_headers():
44
+ """
45
+ The function `_request_headers` returns a dictionary of headers for an HTTP request.
46
+ :return: a dictionary containing the headers for a HTTP request.
47
+ """
48
+
49
+ headers = {
50
+ 'X-User-Agent': _default_user_agent(),
51
+ 'Content-Type':
52
+ 'application/json',
53
+ }
54
+ return headers
55
+
56
+
57
+ if __name__ == '__main__':
58
+ print(_request_headers().__str__())
@@ -0,0 +1,10 @@
1
+ class ArgumentException(Exception):
2
+
3
+ pass
4
+ def __init__(self, f, *args):
5
+ super().__init__(args)
6
+ self.f = f
7
+
8
+ def __str__(self):
9
+ return self.f
10
+
@@ -0,0 +1 @@
1
+ from contentstack_management import contentstack
@@ -0,0 +1,91 @@
1
+ """An alias acts as a pointer to a particular branch. You can specify the alias ID in your
2
+ frontend code to pull content from the target branch associated with an alias."""
3
+
4
+ import json
5
+ from ..common import Parameter
6
+ _path = 'stacks/branch_aliases'
7
+
8
+
9
+ class Alias(Parameter):
10
+ """An alias acts as a pointer to a particular branch. You can specify the alias ID in your
11
+ frontend code to pull content from the target branch associated with an alias."""
12
+
13
+ def __init__(self, client, alias_uid=None):
14
+ self.client = client
15
+ self.alias_uid = alias_uid
16
+ super().__init__(self.client)
17
+
18
+ def find(self):
19
+ r"""
20
+ The Get all aliases request returns comprehensive information of all the
21
+ aliases available in a particular stack in your account.
22
+ :params limit: {int} -- A limit on the number of objects to return.
23
+ :params skip: {int} -- The number of objects to skip before returning any.
24
+ :params include_count: {bool}
25
+ :return: Returns all the aliases
26
+ --------------------------------
27
+ [Example:]
28
+ >>> from contentstack_management import contentstack
29
+ >>> branch = contentstack.ContentstackClient().stack(api_key='api_key').branch_alias()
30
+ >>> response = branch.find()
31
+ --------------------------------
32
+ """
33
+ return self.client.get(_path, headers=self.client.headers, params=self.params)
34
+
35
+ def fetch(self):
36
+ r"""
37
+ The Get a single alias request returns information of a specific alias.
38
+
39
+ :return: Returns the aliase of the given UID
40
+
41
+ --------------------------------
42
+
43
+ [Example:]
44
+ >>> from contentstack_management import contentstack
45
+ >>> branch = contentstack.ContentstackClient().stack(api_key='api_key').branch_alias('branch_alias_uid')
46
+ >>> response = branch.fetch()
47
+ --------------------------------
48
+ """
49
+ if self.alias_uid is None or '':
50
+ raise Exception('alias_uid is required')
51
+ url = f"{_path}/{self.alias_uid}"
52
+ return self.client.get(url, headers=self.client.headers, params=self.params)
53
+
54
+ def assign(self, data):
55
+ r"""
56
+ The Assign an alias request creates a new alias in a particular stack of your organization.
57
+ This alias can point to any existing branch (target branch) of your stack.
58
+
59
+ :param data: {json} -- Data required in json format to assign an alias
60
+ :return: Returns an alias with the given data
61
+ --------------------------------
62
+
63
+ [Example:]
64
+ >>> from contentstack import contentstack
65
+ >>> body = {
66
+ >>> "branch_alias": {
67
+ >>> "target_branch": "test"
68
+ >>> }
69
+ >>> }
70
+ >>> branch = contentstack.ContentstackClient().stack(api_key='api_key').alias("alias_uid")
71
+ >>> response = branch.assign(data)
72
+ --------------------------------
73
+ """
74
+ url = f"{_path}/{self.alias_uid}"
75
+ body = json.dumps(data)
76
+ return self.client.put(url, headers=self.client.headers, data=body)
77
+
78
+ def delete(self):
79
+ r"""
80
+ The Delete BranchAlias call is used to delete an existing BranchAlias permanently from your Stack.
81
+ :params force: {bool}
82
+ :return: Returns status code and message
83
+ --------------------------------
84
+ [Example:]
85
+ >>> from contentstack_management import contentstack
86
+ >>> branch = contentstack.ContentstackClient().stack(api_key='api_key').branch(branch_uid="branch_uid")
87
+ >>> response = branch.delete()
88
+ --------------------------------
89
+ """
90
+ url = f"{_path}/{self.alias_uid}"
91
+ return self.client.delete(url, headers=self.client.headers, params=self.params)
@@ -0,0 +1 @@
1
+ from contentstack_management import contentstack