Skip to content
Merged

Next #28

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Added API documentation and added stacks test cases
  • Loading branch information
sunil-lakshman committed Jun 12, 2023
commit 55eaf5587faf2d714bbb4afd8acd45549e87cf90
14 changes: 14 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,18 @@ fileignoreconfig:
checksum: 253a6e6a0234745cd5d194f6023d207acfb0259a8751d77c67fb8275a723d551
- filename: contentstack_management/user_session/user_session.py
checksum: 8f8353a3f658cd894fce7bee1d0211a612b18a639d1f8006548e89a5f5e32a17
version: ""
fileignoreconfig:
- filename: contentstack_management/users/user.py
checksum: 9944801292f054e6ffcc56b6e1eea2c401776147970dc137de33ad9b63992c36
- filename: tests/stack/test_stack_apitest.py
checksum: 9c9bc43b0aed1f94c27616ca198e3ec0cdc9e6680d9148f8ac7d507fad6d0d19
- filename: contentstack_management/core/client.py
checksum: c584f6982526755542afdb51dec421dd823073405827e32e6f229ff1c4cfa87e
- filename: contentstack_management/organizations/organizations.py
checksum: aea751acdfad7ebf07036d78f792abdf5339c9d02fb9d9f7540fcfe9f1d224f5
- filename: tests/stack/test_stack_unittest.py
checksum: a2ba35250e069e789f11e40efa7c1b2786f5db6899497643b5bf3a0e344d13e9
- filename: contentstack_management/stack/stack.py
checksum: f1b63294922e19f41dbf30caa6cbefe381b0c8834950d94dad7c7a28dd707047
version: ""
10 changes: 6 additions & 4 deletions contentstack_management/contentstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ def client(endpoint=None,
:param max_requests:Optional maximum number of requests to be made
:param retry_on_error: Optional boolean value indicating whether to retry API requests on error.
:return: A client object for performing API operations.

:example:
>>> from contentstack_management import contentstack
>>> client = contentstack.client()
-------------------------------
[Example:]

>>> from contentstack_management import contentstack
>>> client = contentstack.client()
-------------------------------
"""
if headers is None:
headers = {}
Expand Down
40 changes: 38 additions & 2 deletions contentstack_management/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ def __init__(self, endpoint, host, headers, authtoken, authorization, failure_re
self.timeout = timeout
self.max_requests = max_requests
self.retry_on_error = retry_on_error




def get(self, url, headers=None, params=None):
"""
Expand Down Expand Up @@ -110,6 +109,18 @@ def _call_request(self, method, url_path, headers=None, params=None, data=None,
return None

def login(self, email=None, password=None):
"""
Fetches the user details and logging into the stack
:return: User details, fetch authtoken.
-------------------------------
[Example:]

>>> from contentstack_management import contentstack
>>> client = contentstack.client(host='HOST NAME')
>>> response = client.login(email="email_id", password="password")
-------------------------------
"""

self.api_client = ApiClient(
host=self.host, endpoint=self.endpoint, authtoken=self.authtoken,
headers=self.headers, authorization=self.authorization,
Expand All @@ -119,11 +130,36 @@ def login(self, email=None, password=None):
response = UserSession(username=email, password= password, api_client=self.api_client).login()
self.auth_token = self.get_authtoken(response.json()) if response.status_code == 200 else self.authtoken
return response



def logout(self):
"""
Logging out from the stack
:return: Json, with status code and message.
-------------------------------
[Example:]

>>> from contentstack_management import contentstack
>>> client = contentstack.client(host='HOST NAME')
>>> response = client.logout()
-------------------------------
"""
return UserSession(api_client = self.api_client).logout()

def get_authtoken(self, response):
"""
Fetches the authtoken from the successful response
:return: Text, Auth token.
-------------------------------
[Example:]

>>> from contentstack_management import contentstack
>>> client = contentstack.client(host='HOST NAME')
>>> response = client.login(email="email_id", password="password").json()
>>> auth_token = client.get_authtoken(response)
-------------------------------
"""
return response['user']['authtoken']

def user(self):
Expand Down
102 changes: 102 additions & 0 deletions contentstack_management/organizations/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ def __init__(self, endpoint, authtoken, headers, api_client, organization_uid):


def get(self):
"""
Fetches the organizations entries
:return: Json, with organizations details.
-------------------------------
[Example:]

>>> from contentstack_management import contentstack
>>> client = contentstack.client(host='HOST NAME')
>>> client.login(email="email_id", password="password")
>>> result = client.organizations().get().json()

>>> result = client.organizations('ORG_UID').get().json()

-------------------------------
"""
url = "organizations"
if self.organization_uid is None:
url = "organizations"
Expand All @@ -28,31 +43,118 @@ def get(self):


def get_organization_roles(self):
"""
Fetches the organization roles entries
:return: Json, with organization role details.
-------------------------------
[Example:]

>>> from contentstack_management import contentstack
>>> client = contentstack.client(host='HOST NAME')
>>> client.login(email="email_id", password="password")
>>> result = client.organizations('ORG_UID').get_organization_roles().json()

-------------------------------
"""
url = f"organizations/{self.organization_uid}/roles"
self.headers['authtoken'] = self.authtoken
return self.api_client.get(url, headers = self.headers)


def organization_add_users(self, user_data):
"""
Add user to the organization
:return: Json, with user details.
-------------------------------
[Example:]
>>> data = {
"share": {
"users": {
"abc@sample.com": ["{{orgAdminRoleUid}}"],
"xyz@sample.com": ["{{orgMemberRoleUid}}"]
},
"stacks": {
"abc@sample.com": {
"{{apiKey}}": ["{{stackRoleUid1}}"]
},
"xyz@sample.com": {
"blta1ed1f11111c1eb1": ["blt111d1b110111e1f1"],
"bltf0c00caa0f0000f0": ["bltcea22222d2222222", "blt333f33cb3e33ffde"]
}
},
"message": "Invitation message"
}
}

>>> from contentstack_management import contentstack
>>> client = contentstack.client(host='HOST NAME')
>>> client.login(email="email_id", password="password")
>>> result = client.organizations('ORG_UID').organization_add_users(data).json()

-------------------------------
"""
url = f"organizations/{self.organization_uid}/share"
self.headers['authtoken'] = self.authtoken
data = json.dumps(user_data)
return self.api_client.post(url, headers = self.headers, data = data)

def transfer_organizations_ownership(self, data):
"""
Add user to the organization
:return: Json, with user details.
-------------------------------
[Example:]
>>> data ={
"transfer_to": "abc@sample.com"
}

>>> from contentstack_management import contentstack
>>> client = contentstack.client(host='HOST NAME')
>>> client.login(email="email_id", password="password")
>>> result = client.organizations('ORG_UID').transfer_organizations_ownership(data).json()

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

url = f"organizations/{self.organization_uid}/transfer-ownership"
self.headers['authtoken'] = self.authtoken
data = json.dumps(data)
return self.api_client.post(url, headers = self.headers, data = data)


def organization_stacks(self):
"""
Fetches the organization stacks
:return: Json, with organization stack details.
-------------------------------
[Example:]

>>> from contentstack_management import contentstack
>>> client = contentstack.client(host='HOST NAME')
>>> client.login(email="email_id", password="password")
>>> result = client.organizations('ORG_UID').organization_stacks().json()

-------------------------------
"""
url = f"organizations/{self.organization_uid}/stacks"
self.headers['authtoken'] = self.authtoken
return self.api_client.get(url, headers = self.headers)


def organization_logs(self):
"""
Fetches the organization log entries
:return: Json, with organization log details.
-------------------------------
[Example:]

>>> from contentstack_management import contentstack
>>> client = contentstack.client(host='HOST NAME')
>>> client.login(email="email_id", password="password")
>>> result = client.organizations('ORG_UID').organization_logs().json()

-------------------------------
"""
url = f"organizations/{self.organization_uid}/logs"
self.headers['authtoken'] = self.authtoken
return self.api_client.get(url, headers = self.headers)
Expand Down
Loading