Skip to content

Commit 4b0777e

Browse files
Merge branch 'next' into feat/cs-38768-stack-implementation
2 parents a35426f + 6944e1c commit 4b0777e

File tree

17 files changed

+307
-2
lines changed

17 files changed

+307
-2
lines changed

.github/workflows/release.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# this file is *not* meant to cover or endorse the use of GitHub Actions, but rather to
2+
# help make automated releases for this project
3+
4+
name: Release
5+
6+
on:
7+
release:
8+
types: [created]
9+
10+
jobs:
11+
build-and-publish:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
- name: Set up Python
17+
uses: actions/setup-python@v1
18+
with:
19+
python-version: '3.x'
20+
- name: Install build dependencies
21+
run: python -m pip install -U setuptools wheel build
22+
- name: Build
23+
run: python -m build .
24+
- name: Publish
25+
uses: pypa/gh-action-pypi-publish@master
26+
with:
27+
password: ${{ secrets.pypi_password }}
28+
skip_existing: true

.talismanrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
fileignoreconfig:
2+
23
- filename: tests/config/default.yml.enc
34
checksum: f05423216fcfe17716c01932e7a87775a029ec4f1fb1314bfdf0697527e67038
45
- filename: tests/test_contentstack.py
@@ -9,4 +10,14 @@ fileignoreconfig:
910
checksum: 704f1cffd452d226e7447213fcb6a3fed7b01f0661aa27d4f7657b8a36eb3d28
1011
- filename: contentstack_management/core/client.py
1112
checksum: 7a1210ec269e05af414e7753758d8b261c157349e24df4fef047810fef8741c9
13+
- filename: tests/test_organizations.py
14+
checksum: a9ee8e15a00474ab16920da1a9cb7f96f9a0e40f945406506ed1e46030758025
15+
- filename: tests/test_users.py
16+
checksum: 55b60bc69e941184bf16697cec82f5e14369460259729bbbd62437e019e6ab60
17+
- filename: contentstack_management/core/client.py
18+
checksum: 1bec47304a29a7c482f530e3ac283e8ddd8fa96f99153833feac5a6513d726df
19+
- filename: .github/workflows/release.yml
20+
checksum: d2ea9ae192ae0f1b75ff2b68b6bcd9d40eb86d589fb2177535b93194d69a9e0e
21+
- filename: tests/test_user_session.py
22+
checksum: f5000644a471e6ac4ee5bfcb5cfc73762e53fa97980951063f787a83e97244f9
1223
version: ""

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# CHANGELOG
2+

CODEOWNERS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @contentstack/security-admin @contentstack/sdk-admin

INSTALL.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
To install the package simply run the below command on your terminal:
3+
4+
python setup.py install
5+
6+
Don't forget to file bugs and let me know about them.
7+
Also, don't hesitate to ask for new features. Happy coding.

contentstack_management/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""The __init__.py file that contains modules that need to import"""
22

3+
34
from contentstack_management import contentstack
45

56
__title__ = 'contentstack-cms'

contentstack_management/contentstack.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def user_agents(headers):
2929
name=contentstack_management.__package__,
3030
version=contentstack_management.__version__
3131
), 'os': str(__platform())})
32+
3233
package = f"contentstack-management-python/{contentstack_management.__version__}"
3334
return {'User-Agent': str(headers), "X-User-Agent": package, 'Content-Type': 'application/json' }
3435

contentstack_management/core/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ..organizations.organizations import Organization
1111
from ..users.user import User
1212
from ..stack.stack import Stack
13+
1314
from ..user_session.user_session import UserSession
1415

1516
class ApiClient:
@@ -96,7 +97,9 @@ def _call_request(self, method, url_path, headers=None, params=None, data=None,
9697

9798
if response.status_code >= 400:
9899
if self.errors:
100+
99101
return (response)
102+
100103
elif retries > 1:
101104
retries -= 1
102105
else:
@@ -113,6 +116,7 @@ def _call_request(self, method, url_path, headers=None, params=None, data=None,
113116
return None
114117

115118

119+
116120
def login(self, email=None, password=None):
117121
if email is None or email == '':
118122
raise PermissionError(
@@ -144,6 +148,7 @@ def login(self, email=None, password=None):
144148
return response
145149
return response.status_code
146150

151+
147152
def logout(self):
148153
url = "user-session"
149154
self.headers['authtoken'] = self.auth_token
@@ -166,4 +171,4 @@ def stack(self, api_key = None):
166171
'You are not permitted to the stack without valid api key')
167172
return Stack(self.endpoint, self.auth_token, self.headers,self.api_client, api_key)
168173

169-
174+
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 requests
7+
import json
8+
9+
10+
class HttpClient:
11+
"""
12+
This class takes a base URL as an argument when it's initialized,
13+
which is the endpoint for the RESTFUL API that
14+
we'll be interacting with. The create(), read(), update(), and delete()
15+
methods each correspond to the CRUD
16+
operations that can be performed on the API """
17+
18+
def __init__(self, endpoint):
19+
#init method
20+
self.url="user"
21+
self.endpoint = endpoint
22+
self.failure_retry = 0
23+
self.exceptions = True
24+
self.errors = True
25+
26+
27+
28+
def get(self, url, headers=None, params=None):
29+
"""
30+
Perform an HTTP GET request with the specified URL and parameters.
31+
32+
:param url: The URL to send the request to.
33+
:param headers: Optional dictionary of headers to include in the request.
34+
:param params: Optional dictionary of URL parameters to include in the request.
35+
:return: The response from the server.
36+
"""
37+
return self._call_request('GET', url, headers=headers, params=params)
38+
39+
def put(self, url, headers=None, params=None, data=None, json=None):
40+
"""
41+
Perform an HTTP PUT request with the specified URL and parameters.
42+
43+
:param url: The URL to send the request to.
44+
:param headers: Optional dictionary of headers to include in the request.
45+
:param params: Optional dictionary of URL parameters to include in the request.
46+
:param data: Optional dictionary, list of tuples, or bytes to include in the body of the request.
47+
:param json: Optional JSON data to include in the body of the request.
48+
:return: The response from the server.
49+
"""
50+
return self._call_request('PUT', url, headers=headers, params=params, data=data, json=json)
51+
52+
def post(self, url, headers=None, params=None, data=None, json=None):
53+
"""
54+
Perform an HTTP POST request with the specified URL and parameters.
55+
56+
:param url: The URL to send the request to.
57+
:param headers: Optional dictionary of headers to include in the request.
58+
:param params: Optional dictionary of URL parameters to include in the request.
59+
:param data: Optional dictionary, list of tuples, or bytes to include in the body of the request.
60+
:param json: Optional JSON data to include in the body of the request.
61+
:return: The response from the server.
62+
"""
63+
return self._call_request('POST', url, headers=headers, params=params, data=data, json=json)
64+
65+
def delete(self, url, headers=None, params=None):
66+
"""
67+
Perform an HTTP DELETE request with the specified URL and parameters.
68+
69+
:param url: The URL to send the request to.
70+
:param headers: Optional dictionary of headers to include in the request.
71+
:param params: Optional dictionary of URL parameters to include in the request.
72+
:return: The response from the server.
73+
"""
74+
return self._call_request('DELETE', url, headers=headers, params=params)
75+
76+
77+
78+
def _call_request(self, method, url_path, headers=None, params=None, data=None, json=None):
79+
url = f"{self.endpoint}/{url_path}"
80+
retries = self.failure_retry + 1
81+
82+
while retries > 0:
83+
try:
84+
response = requests.request(method, url, data=data, headers=headers, params=params, json=json)
85+
86+
if response.status_code >= 400:
87+
if self.errors:
88+
raise Exception(f"API returned an error: {response.text}")
89+
elif retries > 1:
90+
retries -= 1
91+
else:
92+
return None
93+
else:
94+
return response.json()
95+
96+
except Exception as e:
97+
if self.exceptions:
98+
raise e
99+
elif retries > 1:
100+
retries -= 1
101+
else:
102+
return None
103+
104+

contentstack_management/organizations/organizations.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import contentstack_management
44

5+
56
class Organization:
67
"""
78
This class takes a base URL as an argument when it's initialized,
@@ -23,15 +24,18 @@ def get(self):
2324
return self.api_client.get(url, headers = self.headers)
2425

2526

27+
2628
def get_organization(self, organization_uid):
2729
url = f"organizations/{organization_uid}"
2830
self.headers['authtoken'] = self.authtoken
2931
return self.api_client.get(url, headers = self.headers)
32+
3033

3134
def get_organization_roles(self, organization_uid):
3235
url = f"organizations/{organization_uid}/roles"
3336
self.headers['authtoken'] = self.authtoken
3437
return self.api_client.get(url, headers = self.headers)
38+
3539

3640
def organization_add_users(self, organization_uid):
3741
url = f"organizations/{organization_uid}/share"
@@ -42,13 +46,16 @@ def transfer_organizations_ownership(self, organization_uid, data):
4246
url = f"organizations/{organization_uid}/transfer-ownership"
4347
self.headers['authtoken'] = self.authtoken
4448
return self.api_client.post(url, headers = self.headers, data=data)
49+
4550

4651
def organization_stacks(self, organization_uid):
4752
url = f"organizations/{organization_uid}/stacks"
4853
self.headers['authtoken'] = self.authtoken
4954
return self.api_client.get(url, headers = self.headers)
55+
5056

5157
def organization_logs(self, organization_uid):
5258
url = f"organizations/{organization_uid}/logs"
5359
self.headers['authtoken'] = self.authtoken
54-
return self.api_client.get(url, headers = self.headers)
60+
return self.api_client.get(url, headers = self.headers)
61+

0 commit comments

Comments
 (0)