Skip to content

Commit f582f8b

Browse files
group & asset added
1 parent 3f7e3d1 commit f582f8b

File tree

7 files changed

+108
-15
lines changed

7 files changed

+108
-15
lines changed

contentstack/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
"""Export module packages."""
2727

28+
# from .stack import Stack
2829
from .entry import Entry
2930
from .asset import Asset
3031
from .asset_library import AssetLibrary
@@ -37,7 +38,9 @@
3738
from .group import Group
3839
from .http_request import HTTPRequestConnection
3940

40-
__author__ = 'contentstack - (www.github.con/contentstack)'
41-
__email__ = 'shailesh.mishra@contentstack.com'
42-
__version__ = '1.0.0'
43-
__endpoint__ = 'cdn.contentstack.io'
41+
__author__ = "Shailesh Mishra <mshaileshr@gmail.com>"
42+
__status__ = "debug"
43+
__date__ = "27 June 2019"
44+
__version__ = "1.0.0"
45+
__endpoint__ = "cdn.contentstack.io"
46+

contentstack/asset_library.py

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

26-
import logging
26+
from contentstack import http_request
2727

2828

2929
class AssetLibrary():
3030

3131
def __init__(self):
32-
logging.info('Asset initialised')
32+
self.count = 0
33+
self.__local_header: dict = {}
34+
self.__post_params: dict = {}
35+
36+
def set_header(self, key: str, value):
37+
if key is not None and value is not None:
38+
self.__local_header[key] = value
39+
return self
40+
41+
def set_headers(self, **headers):
42+
if headers is not None:
43+
self.__local_header = headers
44+
for key, value in self.__local_header.items():
45+
self.__local_header[key] = value
46+
return self
47+
48+
def remove_header(self, key):
49+
if key is not None:
50+
if key in self.__local_header:
51+
self.__local_header.pop(key)
52+
return self
53+
54+
def include_count(self):
55+
self.__post_params['include_count'] = 'true'
56+
return self
57+
58+
def include_relative_url(self):
59+
self.__post_params['relative_urls'] = 'true'
60+
return self
61+
62+
def get_count(self) -> int:
63+
return self.count
64+
65+
# order_by = Enum('ORDER_BY', 'ASCENDING DESCENDING')
66+
# def sort(self, key: str, order_by):
67+
# if ORDER_.ASCENDING:
68+
# self.__post_params['asc'] = key
69+
# if ORDER_BY.DESCENDING:
70+
# self.__post_params['desc'] = key
71+
# return self.__post_params
72+
73+
def fetch(self) -> tuple:
74+
print('__params ::', self.__post_params)
75+
print('__headers ::', self.__local_header)
76+
asset_request = http_request.HTTPRequestConnection('assets', self.__post_params, self.__local_header)
77+
(response, error) = asset_request.http_request()
78+
if error is None:
79+
print(response)
80+
self.__set_response(response['assets'])
81+
return response, error
82+
else:
83+
return response, error
84+
85+
def __set_response(self, param):
86+
87+
pass

contentstack/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import logging
2727

2828

29-
class Config(object):
29+
class Config:
3030

3131
def __init__(self, host_url: str = 'cdn.contentstack.io'):
3232
self.host_url = host_url

contentstack/group.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,43 @@
2424
"""
2525
import logging
2626

27+
from contentstack.stack import Stack
2728

28-
class Group:
29+
30+
class Group(Stack):
2931

30-
def __init__(self):
32+
def __init__(self, stack: Stack, dictionary: dict):
33+
self._result_dict = dictionary
34+
self._stack_instance = stack
3135
logging.info('Group initialised')
3236

33-
def callme(self):
34-
pass
37+
def to_json(self) -> dict:
38+
return self._result_dict
39+
40+
def get(self, key: str):
41+
if self._result_dict is not None and key is not None:
42+
if key in self._result_dict:
43+
return self._result_dict[key]
44+
else:
45+
return None
46+
47+
def get_list(self, key: str) -> list:
48+
is_list = self.get(key)
49+
if list == type(is_list):
50+
return is_list
51+
52+
def get_asset(self, key: str):
53+
pass
54+
55+
def get_assets(self, key: str) -> list:
56+
pass
57+
58+
def get_group(self, key: str):
59+
pass
60+
61+
def get_groups(self, key: str) -> list:
62+
pass
63+
64+
def get_all_entries(self, key: str) -> list:
65+
pass
66+

contentstack/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
"""
2525

2626
import logging
27-
import urllib
28-
import requests
2927

3028
try:
3129
from logging import NullHandler
@@ -39,11 +37,16 @@ def emit(self, record):
3937

4038

4139
class utils:
40+
41+
def __init__(self):
42+
log.error('logging called in utils')
43+
pass
4244
'''def is_internet_on():
4345
try: urllib.request.urlopen('http://216.58.192.142', timeout=1)
4446
#return True
4547
except urllib2.URLError as err:
4648
return False'''
4749

4850

51+
util = utils()
4952

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "contentstack-python",
2+
"name": "contentstack.py",
33
"version": "1.0.0",
44
"dependencies": {
55

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def get_version():
3535
author='Shailesh Mishra',
3636
author_email='shailesh.mishra@contentstack.com',
3737
description='Create python-based applications and use the python SDK to fetch and deliver content from Contentstack. The SDK uses Content Delivery APIs. ',
38-
install_requires=['requests'],
38+
install_requires=['requests', 'asset'],
3939
tests_require=['pytest'],
4040
long_description=read('README.rst'),
4141
include_package_data=True,

0 commit comments

Comments
 (0)