-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaliases.py
More file actions
92 lines (79 loc) · 3.83 KB
/
aliases.py
File metadata and controls
92 lines (79 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""An alias acts as a pointer to a particular branch. You can specify the alias ID in your
frontend code to pull content from the target branch associated with an alias."""
import json
from ..common import Parameter
from .._messages import ALIAS_UID_REQUIRED
_path = 'stacks/branch_aliases'
class Alias(Parameter):
"""An alias acts as a pointer to a particular branch. You can specify the alias ID in your
frontend code to pull content from the target branch associated with an alias."""
def __init__(self, client, alias_uid=None):
self.client = client
self.alias_uid = alias_uid
super().__init__(self.client)
def find(self):
r"""
The Get all aliases request returns comprehensive information of all the
aliases available in a particular stack in your account.
:params limit: {int} -- A limit on the number of objects to return.
:params skip: {int} -- The number of objects to skip before returning any.
:params include_count: {bool}
:return: Returns all the aliases
--------------------------------
[Example:]
>>> import contentstack_management
>>> alias = contentstack_management.Client(authtoken='your_authtoken').stack(api_key='api_key').alias()
>>> response = alias.find()
--------------------------------
"""
return self.client.get(_path, headers=self.client.headers, params=self.params)
def fetch(self):
r"""
The Get a single alias request returns information of a specific alias.
:return: Returns the aliase of the given UID
--------------------------------
[Example:]
>>> import contentstack_management
>>> alias = contentstack_management.Client(authtoken='your_authtoken').stack(api_key='api_key').alias('alias_uid')
>>> response = alias.fetch()
--------------------------------
"""
if self.alias_uid is None or '':
raise Exception(ALIAS_UID_REQUIRED)
url = f"{_path}/{self.alias_uid}"
return self.client.get(url, headers=self.client.headers, params=self.params)
def assign(self, data):
r"""
The Assign an alias request creates a new alias in a particular stack of your organization.
This alias can point to any existing branch (target branch) of your stack.
:param data: {json} -- Data required in json format to assign an alias
:return: Returns an alias with the given data
--------------------------------
[Example:]
>>> from contentstack import contentstack
>>> body = {
>>> "branch_alias": {
>>> "target_branch": "test"
>>> }
>>> }
>>> alias = contentstack_management.Client(authtoken='your_authtoken').stack(api_key='api_key').alias("alias_uid")
>>> response = alias.assign(data)
--------------------------------
"""
url = f"{_path}/{self.alias_uid}"
body = json.dumps(data)
return self.client.put(url, headers=self.client.headers, params=self.params, data=body)
def delete(self):
r"""
The Delete BranchAlias call is used to delete an existing BranchAlias permanently from your Stack.
:params force: {bool}
:return: Returns status code and message
--------------------------------
[Example:]
>>> import contentstack_management
>>> alias = contentstack_management.Client(authtoken='your_authtoken').stack(api_key='api_key').alias(alias_uid="alias_uid")
>>> response = alias.delete()
--------------------------------
"""
url = f"{_path}/{self.alias_uid}"
return self.client.delete(url, headers=self.client.headers, params=self.params)