Skip to content

Commit 55eaf55

Browse files
Added API documentation and added stacks test cases
1 parent 44880e1 commit 55eaf55

File tree

11 files changed

+830
-86
lines changed

11 files changed

+830
-86
lines changed

.talismanrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,18 @@ fileignoreconfig:
3434
checksum: 253a6e6a0234745cd5d194f6023d207acfb0259a8751d77c67fb8275a723d551
3535
- filename: contentstack_management/user_session/user_session.py
3636
checksum: 8f8353a3f658cd894fce7bee1d0211a612b18a639d1f8006548e89a5f5e32a17
37+
version: ""
38+
fileignoreconfig:
39+
- filename: contentstack_management/users/user.py
40+
checksum: 9944801292f054e6ffcc56b6e1eea2c401776147970dc137de33ad9b63992c36
41+
- filename: tests/stack/test_stack_apitest.py
42+
checksum: 9c9bc43b0aed1f94c27616ca198e3ec0cdc9e6680d9148f8ac7d507fad6d0d19
43+
- filename: contentstack_management/core/client.py
44+
checksum: c584f6982526755542afdb51dec421dd823073405827e32e6f229ff1c4cfa87e
45+
- filename: contentstack_management/organizations/organizations.py
46+
checksum: aea751acdfad7ebf07036d78f792abdf5339c9d02fb9d9f7540fcfe9f1d224f5
47+
- filename: tests/stack/test_stack_unittest.py
48+
checksum: a2ba35250e069e789f11e40efa7c1b2786f5db6899497643b5bf3a0e344d13e9
49+
- filename: contentstack_management/stack/stack.py
50+
checksum: f1b63294922e19f41dbf30caa6cbefe381b0c8834950d94dad7c7a28dd707047
3751
version: ""

contentstack_management/contentstack.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ def client(endpoint=None,
5151
:param max_requests:Optional maximum number of requests to be made
5252
:param retry_on_error: Optional boolean value indicating whether to retry API requests on error.
5353
:return: A client object for performing API operations.
54-
55-
:example:
56-
>>> from contentstack_management import contentstack
57-
>>> client = contentstack.client()
54+
-------------------------------
55+
[Example:]
56+
57+
>>> from contentstack_management import contentstack
58+
>>> client = contentstack.client()
59+
-------------------------------
5860
"""
5961
if headers is None:
6062
headers = {}

contentstack_management/core/client.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ def __init__(self, endpoint, host, headers, authtoken, authorization, failure_re
3131
self.timeout = timeout
3232
self.max_requests = max_requests
3333
self.retry_on_error = retry_on_error
34-
35-
34+
3635

3736
def get(self, url, headers=None, params=None):
3837
"""
@@ -110,6 +109,18 @@ def _call_request(self, method, url_path, headers=None, params=None, data=None,
110109
return None
111110

112111
def login(self, email=None, password=None):
112+
"""
113+
Fetches the user details and logging into the stack
114+
:return: User details, fetch authtoken.
115+
-------------------------------
116+
[Example:]
117+
118+
>>> from contentstack_management import contentstack
119+
>>> client = contentstack.client(host='HOST NAME')
120+
>>> response = client.login(email="email_id", password="password")
121+
-------------------------------
122+
"""
123+
113124
self.api_client = ApiClient(
114125
host=self.host, endpoint=self.endpoint, authtoken=self.authtoken,
115126
headers=self.headers, authorization=self.authorization,
@@ -119,11 +130,36 @@ def login(self, email=None, password=None):
119130
response = UserSession(username=email, password= password, api_client=self.api_client).login()
120131
self.auth_token = self.get_authtoken(response.json()) if response.status_code == 200 else self.authtoken
121132
return response
133+
134+
122135

123136
def logout(self):
137+
"""
138+
Logging out from the stack
139+
:return: Json, with status code and message.
140+
-------------------------------
141+
[Example:]
142+
143+
>>> from contentstack_management import contentstack
144+
>>> client = contentstack.client(host='HOST NAME')
145+
>>> response = client.logout()
146+
-------------------------------
147+
"""
124148
return UserSession(api_client = self.api_client).logout()
125149

126150
def get_authtoken(self, response):
151+
"""
152+
Fetches the authtoken from the successful response
153+
:return: Text, Auth token.
154+
-------------------------------
155+
[Example:]
156+
157+
>>> from contentstack_management import contentstack
158+
>>> client = contentstack.client(host='HOST NAME')
159+
>>> response = client.login(email="email_id", password="password").json()
160+
>>> auth_token = client.get_authtoken(response)
161+
-------------------------------
162+
"""
127163
return response['user']['authtoken']
128164

129165
def user(self):

contentstack_management/organizations/organizations.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ def __init__(self, endpoint, authtoken, headers, api_client, organization_uid):
1818

1919

2020
def get(self):
21+
"""
22+
Fetches the organizations entries
23+
:return: Json, with organizations details.
24+
-------------------------------
25+
[Example:]
26+
27+
>>> from contentstack_management import contentstack
28+
>>> client = contentstack.client(host='HOST NAME')
29+
>>> client.login(email="email_id", password="password")
30+
>>> result = client.organizations().get().json()
31+
32+
>>> result = client.organizations('ORG_UID').get().json()
33+
34+
-------------------------------
35+
"""
2136
url = "organizations"
2237
if self.organization_uid is None:
2338
url = "organizations"
@@ -28,31 +43,118 @@ def get(self):
2843

2944

3045
def get_organization_roles(self):
46+
"""
47+
Fetches the organization roles entries
48+
:return: Json, with organization role details.
49+
-------------------------------
50+
[Example:]
51+
52+
>>> from contentstack_management import contentstack
53+
>>> client = contentstack.client(host='HOST NAME')
54+
>>> client.login(email="email_id", password="password")
55+
>>> result = client.organizations('ORG_UID').get_organization_roles().json()
56+
57+
-------------------------------
58+
"""
3159
url = f"organizations/{self.organization_uid}/roles"
3260
self.headers['authtoken'] = self.authtoken
3361
return self.api_client.get(url, headers = self.headers)
3462

3563

3664
def organization_add_users(self, user_data):
65+
"""
66+
Add user to the organization
67+
:return: Json, with user details.
68+
-------------------------------
69+
[Example:]
70+
>>> data = {
71+
"share": {
72+
"users": {
73+
"abc@sample.com": ["{{orgAdminRoleUid}}"],
74+
"xyz@sample.com": ["{{orgMemberRoleUid}}"]
75+
},
76+
"stacks": {
77+
"abc@sample.com": {
78+
"{{apiKey}}": ["{{stackRoleUid1}}"]
79+
},
80+
"xyz@sample.com": {
81+
"blta1ed1f11111c1eb1": ["blt111d1b110111e1f1"],
82+
"bltf0c00caa0f0000f0": ["bltcea22222d2222222", "blt333f33cb3e33ffde"]
83+
}
84+
},
85+
"message": "Invitation message"
86+
}
87+
}
88+
89+
>>> from contentstack_management import contentstack
90+
>>> client = contentstack.client(host='HOST NAME')
91+
>>> client.login(email="email_id", password="password")
92+
>>> result = client.organizations('ORG_UID').organization_add_users(data).json()
93+
94+
-------------------------------
95+
"""
3796
url = f"organizations/{self.organization_uid}/share"
3897
self.headers['authtoken'] = self.authtoken
3998
data = json.dumps(user_data)
4099
return self.api_client.post(url, headers = self.headers, data = data)
41100

42101
def transfer_organizations_ownership(self, data):
102+
"""
103+
Add user to the organization
104+
:return: Json, with user details.
105+
-------------------------------
106+
[Example:]
107+
>>> data ={
108+
"transfer_to": "abc@sample.com"
109+
}
110+
111+
>>> from contentstack_management import contentstack
112+
>>> client = contentstack.client(host='HOST NAME')
113+
>>> client.login(email="email_id", password="password")
114+
>>> result = client.organizations('ORG_UID').transfer_organizations_ownership(data).json()
115+
116+
-------------------------------
117+
"""
118+
43119
url = f"organizations/{self.organization_uid}/transfer-ownership"
44120
self.headers['authtoken'] = self.authtoken
45121
data = json.dumps(data)
46122
return self.api_client.post(url, headers = self.headers, data = data)
47123

48124

49125
def organization_stacks(self):
126+
"""
127+
Fetches the organization stacks
128+
:return: Json, with organization stack details.
129+
-------------------------------
130+
[Example:]
131+
132+
>>> from contentstack_management import contentstack
133+
>>> client = contentstack.client(host='HOST NAME')
134+
>>> client.login(email="email_id", password="password")
135+
>>> result = client.organizations('ORG_UID').organization_stacks().json()
136+
137+
-------------------------------
138+
"""
50139
url = f"organizations/{self.organization_uid}/stacks"
51140
self.headers['authtoken'] = self.authtoken
52141
return self.api_client.get(url, headers = self.headers)
53142

54143

55144
def organization_logs(self):
145+
"""
146+
Fetches the organization log entries
147+
:return: Json, with organization log details.
148+
-------------------------------
149+
[Example:]
150+
151+
>>> from contentstack_management import contentstack
152+
>>> client = contentstack.client(host='HOST NAME')
153+
>>> client.login(email="email_id", password="password")
154+
>>> result = client.organizations('ORG_UID').organization_logs().json()
155+
156+
-------------------------------
157+
"""
56158
url = f"organizations/{self.organization_uid}/logs"
57159
self.headers['authtoken'] = self.authtoken
58160
return self.api_client.get(url, headers = self.headers)

0 commit comments

Comments
 (0)