Skip to content

Commit 35ce0e1

Browse files
stack code refactored
1 parent 8dea386 commit 35ce0e1

File tree

11 files changed

+81
-37
lines changed

11 files changed

+81
-37
lines changed

content/__init__.py

Whitespace-only changes.

content/test_functions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def check_dict() -> int:
2+
_image_params = dict
3+
4+
_image_params = {'image_values': '20', 'image_size': '34'}
5+
counter = len(_image_params)
6+
print(counter)
7+
return counter
8+
9+
10+
if __name__ == '__main__':
11+
check_dict()

contentstack/HTTPConnection.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88

99
class HTTPConnection:
1010

11-
def __init__(self, local_headers, query):
12-
self.__local_headers = local_headers
13-
self.__local_headers = local_headers
14-
self.__query = query
11+
def __init__(self, query=None):
12+
self._query = query
1513

1614
def get_query_request(self):
1715
return self.__http_request()
@@ -29,10 +27,9 @@ def get_group_request(self):
2927
return self.__http_request()
3028

3129
def __http_request(self):
32-
3330
encoded_query = urllib.parse.urlencode(self.__query)
34-
self.__local_headers['Content-Type'] ='application/json'
35-
self.__local_headers['X-User-Agent'] = config.Config.SDK_VERSION
31+
self._local_headers['Content-Type'] ='application/json'.format()
32+
self._local_headers['X-User-Agent'] = config.Config.SDK_VERSION
3633
response = requests.post(config.Config.get_host(), encoded_query, self.__local_headers)
3734

3835
print(response.json)

contentstack/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from .stack import Stack
2+
from .entry import Entry
3+
from .asset import Asset
4+
from .asset_library import AssetLibrary
5+
from .asset_model import AssetModel
6+
from .config import Config
7+
from .content_type import ContentType
8+
from .entry_model import EntryModel
9+
from .errors import HTTPError, ConfigError
10+
from .group import Group
11+
from .HTTPConnection import HTTPConnection
12+
from .stack import Stack
13+
14+
__author__ = 'contentstack GmbH (Shailesh Mishra)'
15+
__email__ = 'shailesh.mishra@contentstack.com'
16+
__version__ = '0.0.1'
17+
__endpoint__ = 'cdn.contentstack.io'

contentstack/config.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,24 @@
2828

2929
class Config(object):
3030

31-
SDK_VERSION = 'contentstack-python[0.0.1]'
31+
SDK_VERSION = '[0.0.1]'
32+
SDK_NAME = 'contentstack-python'
3233

3334
def __init__(self):
3435
self.host_url = 'cdn.contentstack.io'
3536
self.api_version = 'v3'
3637
self.environment = None
37-
self.SDK_VERSION = "0.0.1"
38-
self.SDK_NAME = 'contentstack-python'
38+
self.http_protocol = 'https://'
3939

4040
def set_host(self, host_url='cdn.contentstack.io'):
4141
logging.info("set host")
42-
if host_url != None:
43-
self.url = host_url
42+
if host_url is not None:
43+
self.host_url = host_url
4444
return self
4545

4646
def set_environment(self, environment):
4747
logging.info("set environment")
48-
if environment != None:
48+
if environment is not None:
4949
self.environment = environment
5050
return self
5151

@@ -58,5 +58,9 @@ def get_version(self):
5858
return self.api_version
5959

6060
def get_environment(self):
61-
logging.info('get invironment')
61+
logging.info('get environment')
6262
return self.environment
63+
64+
def get_http_protocol(self):
65+
logging.info('get http protocol')
66+
return self.http_protocol

contentstack/errors.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,19 @@ def set_logging_config(self, level):
7070
class ConfigError(Exception):
7171
"""Configuration Error Class"""
7272
pass
73+
74+
75+
class StackException(Exception):
76+
"""StackException Class"""
77+
pass
78+
79+
80+
class NotSupportedException(Exception):
81+
""" exception is thrown when something is not supported by the API."""
82+
pass
83+
84+
85+
class retry_request(object):
86+
"""
87+
Decorator to retry function calls in case they raise rate limit exceptions
88+
"""

contentstack/group.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
import logging
2626

2727

28-
class Group(object):
28+
class Group:
2929

3030
def __init__(self):
3131
logging.info('Group initialised')
32+
33+
def callme(self):
34+
pass

contentstack/utils.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,22 @@
2323
*
2424
"""
2525

26-
2726
import logging
2827
import urllib
2928
import requests
3029

31-
try:
30+
try:
3231
from logging import NullHandler
3332
except ImportError:
3433
class NullHandler(logging.Handler):
3534
def emit(self, record):
3635
pass
3736

38-
3937
logging.getLogger(__name__).addHandler(NullHandler())
4038
log = logging.getLogger(__name__)
4139

42-
class utils:
4340

41+
class utils:
4442
'''def is_internet_on():
4543
try: urllib.request.urlopen('http://216.58.192.142', timeout=1)
4644
#return True
@@ -49,21 +47,3 @@ class utils:
4947

5048

5149

52-
class StackException(Exception):
53-
"""StackException Class"""
54-
pass
55-
56-
57-
class NotSupportedException(Exception):
58-
""" exception is thrown when something is not supported by the API."""
59-
pass
60-
61-
62-
class retry_request(object):
63-
"""
64-
Decorator to retry function calls in case they raise rate limit exceptions
65-
"""
66-
pass
67-
68-
69-

runtests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from unittest import main
2+
from tests import *
3+
4+
main()

0 commit comments

Comments
 (0)