Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
91a4390
Added users and organisations api methods
sunil-lakshman May 22, 2023
4c7f587
added requirements.txt file
sunil-lakshman May 23, 2023
6944e1c
loaded install, changlog , codeowners and release.yml file
sunil-lakshman May 23, 2023
a35426f
Organized package structure
sunil-lakshman May 24, 2023
4b0777e
Merge branch 'next' into feat/cs-38768-stack-implementation
sunil-lakshman May 24, 2023
1c4eb48
Developed stack Implementation
sunil-lakshman May 26, 2023
1d14bce
Code Optimized
sunil-lakshman May 29, 2023
24d3927
Added Mock test and Api Test cases
sunil-lakshman Jun 5, 2023
44880e1
Added test cases and coverage packages
sunil-lakshman Jun 7, 2023
55eaf55
Added API documentation and added stacks test cases
sunil-lakshman Jun 12, 2023
faf700d
Added coverage reports generartion in github action
sunil-lakshman Jul 6, 2023
d224cc3
Added global fields class
sunil-lakshman Jul 6, 2023
7c5d513
- General code improvements
ishaileshmishra Jul 6, 2023
d84e1ef
Merge pull request #8 from contentstack/fix/general-improvements
ishaileshmishra Jul 6, 2023
c1b1c80
Feat/cs 40287 workflow class implemetation (#14)
sunil-lakshman Sep 8, 2023
8a16b18
Feat/cs 41199 label class implementation (#25)
sunil-lakshman Sep 15, 2023
a2fb234
Merge branch 'main' into next
sunil-lakshman Sep 15, 2023
9793243
Feat/cs 41332 terms class implemetation (#27)
sunil-lakshman Sep 21, 2023
4aa0424
Merge branch 'main' into next
sunil-lakshman Sep 21, 2023
68b6b25
Added bulk operations class implementation (#29)
sunil-lakshman Sep 27, 2023
25e541a
Merge branch 'next' of https://github.com/contentstack/contentstack-m…
sunil-lakshman Sep 27, 2023
e628ae2
Added release and release item class implementation (#31)
sunil-lakshman Sep 28, 2023
a63683b
Merge branch 'main' into next
sunil-lakshman Sep 28, 2023
fff0f0f
Fixed pagination issue, added custom payload option in all methods an…
sunil-lakshman Dec 8, 2023
38b4e87
Merge branch 'next' of https://github.com/contentstack/contentstack-m…
sunil-lakshman Dec 12, 2023
8d16341
Resolved conflicts
sunil-lakshman Dec 12, 2023
cd19d87
Fixed code conflits
sunil-lakshman Dec 12, 2023
9103d1a
Updated changelog file
sunil-lakshman Dec 12, 2023
c47d736
Enh/dx 74 gcp na support (#47)
sunil-lakshman May 6, 2024
2eb866e
Merge branch 'main' into fix/dx-74
abhinav-from-contentstack May 6, 2024
b0263e6
Merge pull request #49 from contentstack/fix/dx-74
abhinav-from-contentstack May 6, 2024
e3c1f3d
Updated License file (#50)
sunil-lakshman May 13, 2024
f853c45
Bug/dx 588 asset upload (#51)
sunil-lakshman May 20, 2024
d39e5ef
Fix/merge issue (#53)
sunil-lakshman May 20, 2024
98d2262
Merge branch 'main' into fix/merge-branch-1
abhinav-from-contentstack May 20, 2024
9158c93
Merge pull request #54 from contentstack/fix/merge-branch-1
abhinav-from-contentstack May 20, 2024
2c2c445
Fixed license issue (#56)
sunil-lakshman May 24, 2024
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 global fields class
  • Loading branch information
sunil-lakshman committed Jul 6, 2023
commit d224cc30c7cc7ffa32f22e0fa5d7f3896d3321cd
4 changes: 4 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ fileignoreconfig:
checksum: 1aa5ed251d166293e2616c6a227ee945a8213c5fde03778db08abac5f1a09c72
- filename: tests/stack/test_stack_unittest.py
checksum: 12389c99db0d917954cd9970b340cc443602b4acf512090f42d13f7a726c85b6
version: ""
fileignoreconfig:
- filename: contentstack_management/global_fields/global_fields.py
checksum: 53742c03c5c459a195b99b613a1df2dde7b9a61f6c4839b51be3f54dec56dd21
version: ""
226 changes: 226 additions & 0 deletions contentstack_management/global_fields/global_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
"""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

class Globalfields:
"""
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, endpoint, authtoken, headers, api_client, api_key, global_field_uid):
self.api_client = api_client
self.endpoint = endpoint
self.authtoken = authtoken
self.headers = headers
self.api_key = api_key
self.global_field_uid = global_field_uid

def find(self):
"""
Find the global fields entries
:return: Json, with global fields details.
-------------------------------
[Example:]

>>> from contentstack_management import contentstack
>>> client = contentstack.client(host='HOST NAME')
>>> client.login(email="email_id", password="password")
>>> result = client.stack("API_KEY").global_fields('global_field_uid').find().json()

-------------------------------
"""
url = "global_fields"
self.headers['api_key'] = self.api_key
self.headers['authtoken'] = self.authtoken
return self.api_client.get(url, headers = self.headers)



def fetch(self):
"""
Fetches the global fields entry
:return: Json, with global fields details.
-------------------------------
[Example:]

>>> from contentstack_management import contentstack
>>> client = contentstack.client(host='HOST NAME')
>>> client.login(email="email_id", password="password")
>>> result = client.stack('API_KEY').global_fields('global_field_uid').fetch().json()

-------------------------------
"""
url = f"global_fields/{self.global_field_uid}"
self.headers['authtoken'] = self.authtoken
self.headers['api_key'] = self.api_key
return self.api_client.get(url, headers = self.headers)


def create(self, data):
"""
Create the global fields entries
:return: Json, with global fields details.
-------------------------------
[Example:]
>>> data = {
"global_field": {
"title": "Servlet",
"uid": "servlet",
"schema": [{
"display_name": "Name",
"uid": "name",
"data_type": "text"
}, {
"data_type": "text",
"display_name": "Rich text editor",
"uid": "description",
"field_metadata": {
"allow_rich_text": true,
"description": "",
"multiline": false,
"rich_text_type": "advanced",
"options": [],
"version": 3
},
"multiple": false,
"mandatory": false,
"unique": false
}]
}
}
>>> from contentstack_management import contentstack
>>> client = contentstack.client(host='HOST NAME')
>>> client.login(email="email_id", password="password")
>>> result = client.stack('API_KEY').global_fields().create(data).json()

-------------------------------
"""
url = "global_fields"
self.headers['api_key'] = self.api_key
self.headers['authtoken'] = self.authtoken
data = json.dumps(data)
return self.api_client.post(url, headers = self.headers, data=data)

def update(self, data):
"""
Update the global fields entries
:return: Json, with global fields details.
-------------------------------
[Example:]
>>> data = {
"global_field": {
"title": "Servlet",
"uid": "servlet",
"schema": [{
"display_name": "Name",
"uid": "name",
"data_type": "text"
}, {
"data_type": "text",
"display_name": "Rich text editor",
"uid": "description",
"field_metadata": {
"allow_rich_text": true,
"description": "",
"multiline": false,
"rich_text_type": "advanced",
"options": [],
"version": 3
},
"multiple": false,
"mandatory": false,
"unique": false
}]
}
}
>>> from contentstack_management import contentstack
>>> client = contentstack.client(host='HOST NAME')
>>> client.login(email="email_id", password="password")
>>> result = client.stack('API_KEY').global_fields('global_field_uid').update(data).json()

-------------------------------
"""
url = f"global_fields/{self.global_field_uid}"
self.headers['authtoken'] = self.authtoken
self.headers['api_key'] = self.api_key
data = json.dumps(data)
return self.api_client.put(url, headers = self.headers, data=data)

def delete(self):
"""
Delete the global fields
:return: Json, with status code and message.
-------------------------------
[Example:]

>>> from contentstack_management import contentstack
>>> client = contentstack.client(host='HOST NAME')
>>> client.login(email="email_id", password="password")
>>> result = result = client.stack('API_KEY').global_fields('global_field_uid').delete().json()

-------------------------------
"""
url = f"global_fields/{self.global_field_uid}"
self.headers['authtoken'] = self.authtoken
self.headers['api_key'] = self.api_key
params = {'force': True}
return self.api_client.delete(url, headers = self.headers, params = params)

def imports(self, file_path):
"""
Import the global fields
:return: Json, with global fields details.
-------------------------------
[Example:]

>>> from contentstack_management import contentstack
>>> client = contentstack.client(host='HOST NAME')
>>> client.login(email="email_id", password="password")
>>> file_path = "tests/resources/mock_global_fields/import_global_fields.json"
>>> result = client.stack('API_KEY').global_fields().imports(file_path).json()

-------------------------------
"""
url = f"global_fields/import"
self.headers['authtoken'] = self.authtoken
self.headers['api_key'] = self.api_key
self.headers['Content-Type'] = "multipart/form-data"
params = {'include_branch': False}
files = {'global_field': open(f"{file_path}",'rb')}
return self.api_client.post(url, headers = self.headers, params = params, files = files)

def export(self):
"""
Export the global fields
:return: Json, with global fields details.
-------------------------------
[Example:]

>>> from contentstack_management import contentstack
>>> client = contentstack.client(host='HOST NAME')
>>> client.login(email="email_id", password="password")
>>> result = client.stack('API_KEY').global_fields().export().json()

-------------------------------
"""
url = f"global_fields/{self.global_field_uid}/export"
self.headers['authtoken'] = self.authtoken
self.headers['api_key'] = self.api_key
return self.api_client.get(url, headers = self.headers)