Skip to content

Commit 4db2602

Browse files
mshaileshr@gmail.commshaileshr@gmail.com
authored andcommitted
doc string added
1 parent 5a0bd19 commit 4db2602

File tree

6 files changed

+112
-58
lines changed

6 files changed

+112
-58
lines changed

CHANGELOGS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11

2-
##v0.0.1
2+
## version 0.0.1 - beta release
3+
34
Initial release of the python Content Delivery API SDK.

contentstack/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
"""
88

99
import warnings
10-
import os
11-
import sys
12-
sys.path.insert(0, os.path.abspath('.'))
1310

1411
__author__ = 'contentstack'
1512
__status__ = 'debug'

contentstack/config.py

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import os
2-
import sys
31
import enum
42
import logging
5-
sys.path.insert(0, os.path.abspath('.'))
63

74
"""
85
Config
@@ -26,32 +23,44 @@ class Config(object):
2623

2724
def __init__(self):
2825

29-
"""
30-
26+
"""Config class arguments accepts protocol, region, host and version:
27+
28+
protocol: It support https protocol only
29+
region: It accepts us and eu region.
30+
host: host of the stack
31+
version: API version, contentstack support v3 API version
32+
3133
"""
3234
self.default = dict(protocol="https", region=ContentstackRegion.US, host="cdn.contentstack.io", version="v3")
3335

3436
@property
3537
def region(self):
36-
""" :returns region of the stack """
38+
39+
"""It sets the region in the API, We support us and eu region
40+
default region will be us.
41+
42+
Returns:
43+
ContentstackRegion -- It returns type of ContentstackRegion
44+
"""
3745
return self.default['region']
3846

3947
@region.setter
4048
def region(self, region=ContentstackRegion.US):
4149

4250
"""
43-
The base URL for Content Delivery API is cdn.contentstack.io.
44-
default region is for ContentstackRegion is US
45-
46-
:param region: Region support given for US and EU
47-
:return: ContentstackRegion
51+
A Contentstack region refers to the location of the data centers where your organization's data resides.
52+
53+
Keyword Arguments:
54+
region {ContentstackRegion} -- region refers to the location of the data centers where your organization's data resides. (default: {ContentstackRegion.US})
4855
56+
For more details: https://www.contentstack.com/docs/guide/contentstack-regions
57+
4958
==============================
5059
5160
[Example:]
5261
53-
>>> config = Config()
54-
>>> config.region = ContentstackRegion.US
62+
>>> config = Config()
63+
>>> config.region = ContentstackRegion.US
5564
5665
==============================
5766
"""
@@ -63,6 +72,12 @@ def region(self, region=ContentstackRegion.US):
6372
@property
6473
def host(self):
6574

75+
"""host property returns host of the API
76+
77+
Returns:
78+
str -- host of the API
79+
"""
80+
6681
return self.default['host']
6782

6883
@host.setter
@@ -74,9 +89,20 @@ def host(self, host):
7489
port number if different from the scheme's default
7590
port (443 for HTTPS).
7691
92+
Arguments:
93+
host {str} -- host of the stack
94+
7795
Returns:
7896
[Config] -- Config, So we can chain more functions
7997
98+
==============================
99+
100+
[Example:]
101+
102+
>>> config = Config()
103+
>>> config.host = 'cdn.contentstack.io'
104+
105+
==============================
80106
"""
81107

82108
if host is not None and isinstance(host, str):
@@ -85,21 +111,23 @@ def host(self, host):
85111
def version(self, version=None):
86112

87113
"""
88-
Note: Only version 3 is supported on the CDN. If you're still using version 2 (which we recommend you should
89-
not), switch to the CDN version for even faster loading.
90-
:param version: The API version can be found in the URL that is basePath
91-
:type version: str
92-
:return: self
93-
:rtype: Config
114+
Only version v3 is supported on the CDN.
94115
116+
Keyword Arguments:
117+
version {str} -- version of the API (default: {None})
118+
119+
Returns:
120+
Config -- class instance to chain the functions
121+
95122
==============================
96123
97-
[Example:] The API version (in our case, 'v3') can be found in the URL
124+
[Example:]
98125
99-
>>> config = Config()
100-
>>> config.version = 'v3'
126+
>>> config = Config()
127+
>>> config = config.version('v3')
101128
102129
==============================
130+
103131
"""
104132

105133
if version is not None and isinstance(version, str):
@@ -110,9 +138,14 @@ def version(self, version=None):
110138
@property
111139
def endpoint(self):
112140

113-
"""
114-
:return: url endpoint to make Http requst
141+
"""It returns endpoint url of the API
142+
The base URL for Content Delivery API for the US region is cdn.contentstack.io. and
143+
for the European region it is eu-cdn.contentstack.com
144+
For more details: https://www.contentstack.com/docs/apis/content-delivery-api/#base-url
115145
146+
Returns:
147+
str -- endpoint url of the API
148+
116149
"""
117150
return self.__get_url()
118151

contentstack/contentstack.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,28 @@
44
Copyright 2019 Contentstack. All rights reserved.
55
66
"""
7-
import stack
87

98

109
class contentstack(object):
1110

1211
"""
13-
:param api_key: api_key of your target stack.
14-
:param access_token: access token for the stack.
15-
:param environment: environment of the stack
16-
:param config: (optional) contains configuration of the stack
12+
Below arguments are needed to initialise stack
13+
14+
Arguments:
15+
api_key {[type]} -- api_key of your target stack.
16+
access_token {[type]} -- access token for the stack.
17+
environment {[type]} -- environment of the stack
18+
config {[type]} -- (optional) contains configuration of the stack
19+
20+
Returns:
21+
stack -- stack
22+
23+
==============================
24+
25+
Example:
26+
>>> stack = contentstack.stack.Stack("api_key", "access_token", "environment_name")
27+
28+
==============================
1729
"""
1830

1931
@staticmethod

contentstack/errors.py

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,74 @@
1+
12
"""
2-
Error
3-
contentstack
3+
44
Created by Shailesh Mishra on 22/06/19.
55
Copyright 2019 Contentstack. All rights reserved.
66
7-
"""
7+
contentstack.error
8+
~~~~~~~~~~~~~~~~~~
89
9-
import os
10-
import sys
10+
API Reference: https://www.contentstack.com/docs/apis/content-delivery-api/#error
1111
12-
sys.path.insert(0, os.path.abspath('.'))
12+
"""
1313

1414

1515
class Error:
16+
1617
"""
17-
>>> error = Error()
18-
~~~~~~~~~~~~~~~~~~
1918
This module implements the Error class.
19+
2020
API Reference: https://www.contentstack.com/docs/apis/content-delivery-api/#error
2121
2222
"""
2323

2424
def __init__(self):
25+
2526
self.__error_dict = {}
2627
self.__error_code = str
2728
self.__msg = str
2829

2930
def _config(self, result: dict):
31+
32+
# _instance is the protected member of the asset, So outsiders can not access this file.
3033
if result is not None and len(result) > 0:
3134
self.__error_dict = result
3235
self.__error_code = self.__error_dict['error_code']
3336
self.__msg = self.__error_dict['error_message']
37+
3438
return self
3539

3640
@property
3741
def error_code(self):
38-
"""
39-
It returns error code from the stack response
40-
:return: error_code as int
41-
:rtype: int
42+
"""It returns error code from the stack response
43+
44+
Returns:
45+
int -- error_code as int
4246
4347
==============================
4448
4549
[Example:]
4650
47-
>>> code = Error.error_code
51+
>>> error_code = error.error_code
4852
4953
==============================
54+
5055
"""
5156
return self.__error_code
5257

5358
@property
5459
def error_message(self):
60+
5561
"""
5662
Returns error_message from the stack response
57-
:return: error_message
58-
:rtype: str
63+
64+
Returns:
65+
str -- error_message from the stack response
5966
6067
==============================
6168
6269
[Example:]
6370
64-
>>> message = Error.error_message
71+
>>> message = error.error_message
6572
6673
==============================
6774
"""
@@ -70,16 +77,18 @@ def error_message(self):
7077

7178
@property
7279
def error(self):
80+
7381
"""
74-
This returns error code and error_message in dict formats
75-
:return: error dict
76-
:rtype: dict
82+
error property returns error code and error_message in dict formats
83+
84+
Returns:
85+
dict -- error code and error_message in dict formats
7786
7887
==============================
7988
8089
[Example:]
8190
82-
>>> ode = Error.error
91+
>>> error = error.error
8392
8493
==============================
8594
"""
@@ -88,16 +97,17 @@ def error(self):
8897

8998
@property
9099
def error_info(self) -> dict:
91-
"""
92-
error information
93-
:return: error information
94-
:rtype: dict
100+
101+
"""error information
102+
103+
Returns:
104+
dict -- error information
95105
96106
==============================
97107
98108
[Example:]
99109
100-
>>> ode = Error.error_info
110+
>>> ode = error.error_info
101111
102112
==============================
103113
"""

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
requests==2.22.0
2+
sphinx_rtd_theme

0 commit comments

Comments
 (0)