Skip to content

Commit ee44833

Browse files
mshaileshr@gmail.commshaileshr@gmail.com
authored andcommitted
1.0.0
1 parent c62345c commit ee44833

File tree

12 files changed

+348
-282
lines changed

12 files changed

+348
-282
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ wheels/
2626
MANIFEST
2727
*.DS_Store
2828
*.DS_Store?
29+
.pytest_cache
30+
.idea
31+
.vscode
32+
.report.log
2933

3034
# PyInstaller
3135
# Usually these files are written by a python script from a template

CHANGELOGS.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1+
# Changelog
2+
3+
-----------------------------
4+
5+
## Version 1.0.0
6+
7+
### May-18, 2019 -Initial Release
8+
9+
#### Initial release for the contentstack-python-sdk for Content Delivery API
10+
11+
-----------------------------
112

213
## Version 0.1.0
3-
##### November-18, 2019 -beta release
414

5-
### Initial release for the contentstack-python-sdk for Content Delivery API
15+
### November-18, 2019 -Beta Release
616

17+
#### Beta release for the contentstack-python-sdk for Content Delivery API
718

819
-----------------------------

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2012 - 2019 Contentstack. All rights reserved.
3+
Copyright (c) 2012 - 2020 Contentstack. All rights reserved.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

contentstack/__init__.py

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
1+
from .entry import Entry
2+
from .asset import Asset
3+
from .contenttype import ContentType
4+
from .https_connection import HTTPSConnection
5+
from .stack import Stack
6+
from .utility import Utils
7+
# from contentstack import assetquery, entry, asset, contenttype, https_connection, stack, utility
18

2-
"""
3-
__init__.py
4-
contentstack
5-
Created by Shailesh Mishra on 22/06/19.
6-
Copyright 2019 Contentstack. All rights reserved.
7-
"""
8-
9-
import warnings
10-
import logging
11-
from logging import NullHandler
129

1310
__author__ = 'Contentstack'
1411
__status__ = 'debug'
15-
__version__ = '0.1.0'
16-
#__package__ = 'contentstack'
12+
__version__ = '1.0.0'
1713
__endpoint__ = 'cdn.contentstack.io'
18-
__email__ = "mobile@contentstack.com"
19-
20-
from .entry import Entry
21-
from .asset import Asset
22-
from .config import Config
23-
from .content_type import ContentType
24-
from .errors import Error, FileModeWarning
25-
from .http_connection import HTTPConnection
26-
from .stack import Stack
27-
28-
logging.getLogger(__name__).addHandler(NullHandler())
29-
warnings.simplefilter('default', FileModeWarning, append=True)
14+
__email__ = 'mshaileshr@gmail.com'

contentstack/assetquery.py

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
"""
2+
This call fetches the list of all the assets of a particular stack.
3+
It also returns the content of each asset in JSON format.
4+
You can also specify the environment of which you wish to get the assets.
5+
"""
6+
7+
# ************* Module assetquery **************
8+
# Your code has been rated at 10/10 by pylint
9+
10+
from urllib import parse
11+
12+
13+
class AssetQuery:
14+
"""
15+
This call fetches the list of all the assets of a particular stack.
16+
"""
17+
18+
def __init__(self, http_instance):
19+
self.http_instance = http_instance
20+
self.__query_params = {}
21+
self.base_url = '{}/assets'.format(self.http_instance.endpoint)
22+
if 'environment' in self.http_instance.headers:
23+
self.__query_params['environment'] = self.http_instance.headers['environment']
24+
# self.http_instance.headers.pop('environment')
25+
26+
def environment(self, environment):
27+
"""
28+
Provide the name of the environment if you wish to retrieve the assets published
29+
in a particular environment.
30+
:param environment: environment of the stack
31+
:return: AssetQuery - so we can chain the call
32+
33+
-----------------------------
34+
[Example]:
35+
36+
>>> import contentstack
37+
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
38+
>>> result = stack.asset_query().environment('production').find()
39+
------------------------------
40+
"""
41+
self.__query_params['environment'] = environment
42+
return self
43+
44+
def version(self, version):
45+
"""
46+
Specify the version number of the asset that you wish to retrieve.
47+
If the version is not specified, the details of the latest version will be retrieved.
48+
To retrieve a specific version, keep the environment parameter blank.
49+
50+
:param version: version number of the asset that you wish to retrieve
51+
:return: AssetQuery: so we can chain the call
52+
53+
-----------------------------
54+
[Example]:
55+
56+
>>> import contentstack
57+
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
58+
>>> result = stack.asset_query().version(3).find()
59+
------------------------------
60+
"""
61+
self.__query_params['version'] = version
62+
return self
63+
64+
def include_dimension(self):
65+
"""
66+
include the dimensions (height and width) of the image in the response.
67+
Supported image types: JPG, GIF, PNG, WebP, BMP, TIFF, SVG, and PSD
68+
:return: AssetQuery: so we can chain the call
69+
70+
-----------------------------
71+
[Example]:
72+
73+
>>> import contentstack
74+
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
75+
>>> result = stack.asset_query().include_dimension().find()
76+
------------------------------
77+
"""
78+
self.__query_params['include_dimension'] = 'true'
79+
return self
80+
81+
def relative_url(self):
82+
"""
83+
include the relative URLs of the assets in the response.
84+
:return: AssetQuery: so we can chain the call
85+
86+
-----------------------------
87+
[Example]:
88+
89+
>>> import contentstack
90+
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
91+
>>> result = stack.asset_query().relative_url().find()
92+
------------------------------
93+
"""
94+
self.__query_params['relative_urls'] = 'true'
95+
return self
96+
97+
def include_count(self):
98+
"""
99+
include count provides asset count
100+
:return: AssetQuery: so we can chain the call
101+
102+
-----------------------------
103+
[Example]:
104+
105+
>>> import contentstack
106+
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
107+
>>> result = stack.asset_query().include_count().find()
108+
------------------------------
109+
"""
110+
self.__query_params['include_count'] = 'true'
111+
return self
112+
113+
def find(self):
114+
"""
115+
This call fetches the list of all the assets of a particular stack.
116+
It also returns the content of each asset in JSON format.
117+
Learn more about Assets
118+
[https://www.contentstack.com/docs/content-managers/work-with-assets].
119+
120+
:return: json result, List of asset object
121+
122+
-----------------------------
123+
[Example]:
124+
125+
>>> import contentstack
126+
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
127+
>>> result = stack.asset_query().find()
128+
129+
"""
130+
url = '{}?{}'.format(self.base_url, parse.urlencode(self.__query_params))
131+
return self.http_instance.get(url)

contentstack/contenttype.py

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
content type.
66
"""
77

8-
98
# ************* Module asset **************
10-
# Your code has been rated at 9.09/10 by pylint
9+
# Your code has been rated at 10.00/10 by pylint
10+
11+
from urllib import parse
12+
from contentstack.entry import Entry
13+
from contentstack.query import Query
1114

1215

1316
class ContentType:
@@ -20,11 +23,12 @@ class ContentType:
2023
"""
2124

2225
def __init__(self, http_instance, content_type_uid):
23-
self.__http_instance = http_instance
26+
self.http_instance = http_instance
2427
self.__content_type_uid = content_type_uid
28+
self.local_param = {}
2529

2630
def entry(self, uid):
27-
"""
31+
r"""
2832
An entry is the actual piece of content created using one of the defined content types.
2933
:param uid: {str} -- uid of the entry
3034
:return: Entry -- Returns the Entry class object so we can chain the entry functions
@@ -37,8 +41,7 @@ def entry(self, uid):
3741
>>> entry = content_type.entry(uid='entry_uid')
3842
--------------------------------
3943
"""
40-
from contentstack import Entry
41-
entry = Entry(self.__http_instance, self.__content_type_uid, entry_uid=uid)
44+
entry = Entry(self.http_instance, self.__content_type_uid, entry_uid=uid)
4245
return entry
4346

4447
def query(self):
@@ -54,33 +57,51 @@ def query(self):
5457
>>> query = content_type.query()
5558
------------------------------
5659
"""
57-
from contentstack.query import Query
5860
query = Query(self.__content_type_uid)
5961
return query
6062

61-
def fetch(self, params=None):
63+
def fetch(self):
6264
"""
6365
This method is useful to fetch ContentType of the of the stack.
64-
:param params: dictionary of params
6566
:return:dict -- contentType response
6667
------------------------------
6768
Example:
6869
6970
>>> import contentstack
7071
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
7172
>>> content_type = stack.content_type('content_type_uid')
72-
>>> content_type.add_header('key', 'someheader')
7373
>>> some_dict = {'abc':'something'}
7474
>>> response = content_type.fetch(some_dict)
7575
------------------------------
7676
"""
77-
if params is None:
78-
params = {}
79-
params_dict = {}
80-
url = '{}/content_types'.format(self.__http_instance.endpoint)
81-
content_type_url = '{0}/{1}'.format(url, self.__content_type_uid)
82-
if params is not None and isinstance(params, dict):
83-
params_dict.update(params)
84-
# params_dict, self.__stack_headers
85-
result = self.__http_instance.get(content_type_url)
77+
if self.__content_type_uid is None:
78+
raise KeyError('content_type_uid can not be None to fetch contenttype')
79+
self.local_param['environment'] = self.http_instance.headers['environment']
80+
uri = '{}/content_types/{}'.format(self.http_instance.endpoint, self.__content_type_uid)
81+
encoded_params = parse.urlencode(self.local_param)
82+
url = '{}?{}'.format(uri, encoded_params)
83+
result = self.http_instance.get(url)
84+
return result
85+
86+
def find(self, params=None):
87+
"""
88+
This method is useful to fetch ContentType of the of the stack.
89+
:param params: dictionary of params
90+
:return:dict -- contentType response
91+
------------------------------
92+
Example:
93+
94+
>>> import contentstack
95+
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
96+
>>> content_type = stack.content_type()
97+
>>> some_dict = {'abc':'something'}
98+
>>> response = content_type.find(param=some_dict)
99+
------------------------------
100+
"""
101+
self.local_param['environment'] = self.http_instance.headers['environment']
102+
if params is not None:
103+
self.local_param.update(params)
104+
encoded_params = parse.urlencode(self.local_param)
105+
url = '{}?{}'.format('{}/content_types'.format(self.http_instance.endpoint), encoded_params)
106+
result = self.http_instance.get(url)
86107
return result

0 commit comments

Comments
 (0)