Skip to content

Commit d1e1e9a

Browse files
config changes
1 parent 4680fe8 commit d1e1e9a

File tree

3 files changed

+39
-26
lines changed

3 files changed

+39
-26
lines changed

contentstack/config.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,41 @@
2020
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
23-
*
24-
"""
2523
26-
import logging
24+
"""
2725

2826

2927
class Config:
3028

31-
def __init__(self, host_url: str = 'cdn.contentstack.io'):
32-
self.host_url = host_url
33-
self.api_version: str = 'v3'
34-
self.http_protocol: str = 'https://'
35-
36-
def set_host(self, host_url=None):
37-
logging.info("set host", host_url)
38-
self.host_url = host_url
39-
return self
29+
def __init__(self):
30+
self.default_config = dict(protocol="https", host="cdn.contentstack.io", port=443, version="v3", urls={
31+
"sync": "/stacks/sync",
32+
"content_types": "/content_types/",
33+
"entries": "/entries/",
34+
"assets": "/assets/",
35+
"environments": "/environments/"
36+
})
4037

41-
def get_host(self):
42-
logging.info('getting host url', self.host_url)
43-
return self.host_url
38+
def host(self, host_url=None):
39+
if host_url is not None:
40+
self.default_config["host"] = host_url
41+
return self.default_config["host"]
4442

45-
def get_version(self):
46-
logging.info('getting api version', self.api_version)
47-
return self.api_version
43+
def version(self):
44+
return self.default_config["host"]
4845

49-
def get_http_protocol(self):
50-
logging.info('get http protocol', self.http_protocol)
51-
return self.http_protocol
46+
def protocol(self):
47+
return self.default_config["protocol"]
5248

5349
def get_endpoint(self, url_path):
54-
api_version: str = self.get_version()
55-
host_url = self.get_host()
56-
http_protocol = self.get_http_protocol()
57-
config_url = "{0}{1}/{2}/{3}".format(http_protocol, host_url, api_version, url_path)
50+
config_url = "{0}{1}/{2}/{3}".format(self.protocol(), self.host(), self.version(), url_path)
5851
return config_url
52+
53+
def hiShailesh(self):
54+
print("Something")
55+
56+
57+
config = Config()
58+
host = config.host("stag-cdn.contentstack.io")
59+
print(host)
60+

contentstack/errors.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,16 @@
2525

2626
import logging
2727

28+
"""
29+
contentstack.error
30+
~~~~~~~~~~~~~~~~~~
31+
This module implements the Error class.
32+
API Reference: https://www.contentstack.com/docs/apis/content-delivery-api/#error
33+
34+
"""
2835

2936
class HTTPError(Exception):
37+
3038
errors_str = {
3139

3240
'error_invalid_json': "Please provide valid JSON.",

contentstack/http_request.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import urllib.parse
12
from urllib import parse
3+
24
import requests
35
from requests import Response
6+
47
from contentstack import config
58

69

@@ -19,11 +22,11 @@ def __init__(self, url_path, query=dict, local_headers=dict):
1922
self._query_prams['environment'] = self._local_headers['environment']
2023

2124
def http_request(self) -> tuple:
25+
print("prams", self._query_prams.__str__())
2226
payload = parse.urlencode(query=self._query_prams, encoding='UTF-8')
2327
print("encoded prams", payload)
2428
response: Response = requests.get(self.url_path, params=payload, headers=self._local_headers)
2529
var_url = response.url
26-
2730
if response.ok:
2831
self.result = response.json()
2932
else:

0 commit comments

Comments
 (0)