Skip to content

Commit 1b7c208

Browse files
azure-eu and include_metadata support added
1 parent 8778307 commit 1b7c208

File tree

13 files changed

+132
-36
lines changed

13 files changed

+132
-36
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#
2-
3-
[![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)](https://www.contentstack.com/)
1+
#[![Contentstack](https://www.contentstack.com/docs/static/images/contentstack.png)](https://www.contentstack.com/)
42

53
<!-- ![Python package](https://github.com/contentstack/contentstack-python/workflows/Python%20package/badge.svg?branch=master) -->
64

@@ -132,7 +130,7 @@ Read through to understand how to use the Sync API with Contentstack Python SDK.
132130

133131
### The MIT License (MIT)
134132

135-
Copyright © 2012-2021 [Contentstack](https://www.contentstack.com/). All Rights Reserved
133+
Copyright © 2012-2023 [Contentstack](https://www.contentstack.com/). All Rights Reserved
136134

137135
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
138136

contentstack/asset.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ def __init__(self, http_instance, uid=None):
2222
self.__uid = uid
2323
if self.__uid is None or self.__uid.strip() == 0:
2424
raise KeyError('Please provide valid uid')
25-
self.base_url = '{}/assets/{}'.format(
26-
self.http_instance.endpoint, self.__uid)
25+
self.base_url = f'{self.http_instance.endpoint}/assets/{self.__uid}'
2726
if 'environment' in self.http_instance.headers:
2827
self.asset_params['environment'] = self.http_instance.headers['environment']
2928

@@ -133,5 +132,5 @@ def fetch(self):
133132
>>> result = asset.fetch()
134133
------------------------------
135134
"""
136-
url = '{}?{}'.format(self.base_url, parse.urlencode(self.asset_params))
135+
url = f'{self.base_url}?{parse.urlencode(self.asset_params)}'
137136
return self.http_instance.get(url)

contentstack/assetquery.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
You can also specify the environment of which you wish to get the assets.
44
"""
55

6-
# ************* Module assetquery **************
6+
# ************* Module asset_query **************
77
# Your code has been rated at 10/10 by pylint
88

99
import json
@@ -129,6 +129,22 @@ def include_fallback(self):
129129
self.asset_query_params['include_fallback'] = 'true'
130130
return self
131131

132+
def include_metadata(self):
133+
"""Retrieve the metadata in the response.
134+
135+
:return: AssetQuery, so we can chain the call
136+
137+
----------------------------
138+
Example::
139+
140+
>>> import contentstack
141+
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
142+
>>> result = stack.asset_query().include_metadata().find()
143+
----------------------------
144+
"""
145+
self.asset_query_params['include_metadata'] = 'true'
146+
return self
147+
132148
def locale(self, locale: str):
133149
"""Enter locale code. e.g., en-us
134150
This retrieves published entries of specific locale..

contentstack/basequery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
log = logging.getLogger(__name__)
55

66

7-
# ************* Module basequery.py **************
7+
# ************* Module base_query.py **************
88
# Your code has been rated at 10.00/10
99

1010
class QueryOperation(enum.Enum):
@@ -160,7 +160,7 @@ def add_params(self, param: dict):
160160

161161
def query(self, key: str, value):
162162
"""
163-
Adds key value pairs to the to the query parameters
163+
Adds key value pairs to the query parameters
164164
Arguments:
165165
key {str} -- key of the query param
166166
value {any} -- value of query param

contentstack/contenttype.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,9 @@ def fetch(self):
9191
raise KeyError(
9292
'content_type_uid can not be None to fetch contenttype')
9393
self.local_param['environment'] = self.http_instance.headers['environment']
94-
uri = '{}/content_types/{}'.format(
95-
self.http_instance.endpoint, self.__content_type_uid)
94+
uri = f'{self.http_instance.endpoint}/content_types/{self.__content_type_uid}'
9695
encoded_params = parse.urlencode(self.local_param)
97-
url = '{}?{}'.format(uri, encoded_params)
96+
url = f'{uri}?{encoded_params}'
9897
result = self.http_instance.get(url)
9998
return result
10099

@@ -117,7 +116,9 @@ def find(self, params=None):
117116
if params is not None:
118117
self.local_param.update(params)
119118
encoded_params = parse.urlencode(self.local_param)
120-
url = '{}?{}'.format(
121-
'{}/content_types'.format(self.http_instance.endpoint), encoded_params)
119+
endpoint = self.http_instance.endpoint
120+
url = f'{endpoint}/content_types?{encoded_params}'
121+
# url = '{}?{}'.format(
122+
# '{}/content_types'.format(self.http_instance.endpoint), encoded_params)
122123
result = self.http_instance.get(url)
123124
return result

contentstack/entryqueryable.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,20 @@ def include_reference_content_type_uid(self):
157157
self.entry_queryable_param['include_reference_content_type_uid'] = 'true'
158158
return self
159159

160+
def include_metadata(self):
161+
"""
162+
This method also includes the metadata in the response
163+
[Example for Query]
164+
>>> import contentstack
165+
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
166+
>>> content_type = stack.content_type('content_type_uid')
167+
>>> query = content_type.query()
168+
>>> query = query.include_metadata()
169+
>>> result = query.find()
170+
"""
171+
self.entry_queryable_param['include_metadata'] = 'true'
172+
return self
173+
160174
def add_param(self, key: str, value: str):
161175
"""
162176
This method adds key and value to an Entry.

contentstack/https_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ def get(self, url):
8282
"message": f'Timeout error ${timeout_err.strerror}'})) from timeout_err
8383
except ConnectionError as connect_err:
8484
raise ConnectionError(json.dumps({"httpStatus": 503,
85-
"message": f'Service error ${connect_err.strerror}'})) from connect_err
85+
"message": f'Service error ${connect_err.strerror}'})) from connect_err
8686
except JSONDecodeError as connection_err:
8787
raise TypeError(json.dumps({"httpStatus": 503,
88-
"message": 'Decoding JSON has failed.'})) from connection_err
88+
"message": 'Decoding JSON has failed.'})) from connection_err
8989
except HTTPError as http_err:
9090
raise HTTPError('Http error occurred') from http_err

contentstack/query.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import logging
88
from urllib import parse
99

10-
import deprecation
1110
import empty
11+
from sphinx import deprecation
1212

1313
from contentstack.basequery import BaseQuery
1414
from contentstack.entryqueryable import EntryQueryable
@@ -267,6 +267,13 @@ def include_embedded_items(self):
267267
self.query_params['include_embedded_items[]'] = "BASE"
268268
return self
269269

270+
def include_metadata(self):
271+
"""
272+
include_metadata includes metadata in the response
273+
"""
274+
self.query_params['include_metadata'] = 'true'
275+
return self
276+
270277
def find(self):
271278
"""It fetches the query result.
272279
List of :class:`Entry <contentstack.entry.Entry>` objects.

contentstack/stack.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ContentstackRegion(enum.Enum):
2929
US = 'us'
3030
EU = 'eu'
3131
AZURE_NA = 'azure-na'
32+
AZURE_EU = 'azure-eu'
3233

3334

3435
class Stack:
@@ -123,6 +124,8 @@ def _validate_stack(self):
123124
self.host = 'eu-cdn.contentstack.com'
124125
elif self.region.value == 'azure-na' and self.host == DEFAULT_HOST:
125126
self.host = 'azure-na-cdn.contentstack.com'
127+
elif self.region.value == 'azure-eu' and self.host == DEFAULT_HOST:
128+
self.host = 'azure-eu-cdn.contentstack.com'
126129
elif self.region.value != 'us':
127130
self.host = f'{self.region.value}-{DEFAULT_HOST}'
128131
self.endpoint = f'https://{self.host}/{self.version}'
@@ -329,7 +332,7 @@ def image_transform(self, image_url, **kwargs):
329332
mobile properties.\n
330333
331334
:param image_url: base url on which queries to apply
332-
:param kwargs: append queries to the asset URL.
335+
:param kwargs: to append queries to the asset URL.
333336
:return: instance of ImageTransform
334337
"""
335338
if image_url is None or image_url == '':
@@ -364,7 +367,6 @@ def _execute_management_api(self):
364367
_url = f'{_endpoint}/content_types/{_ct_uid}/entries/{_entry_uid}'
365368
import requests
366369
r = requests.get(url=_url, verify=True, headers=_headers)
367-
# _resp = self.http_instance.get(_url, headers=_headers)
368370
self.live_preview['resp'] = r.json()['entry']
369371
return self
370372

requirements.txt

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,61 @@
1-
twython~=3.9.1
2-
setuptools~=62.1.0
3-
urllib3~=1.26.2
1+
twython==3.9.1
2+
setuptools==67.7.2
3+
urllib3==2.0.1
44
contentstack-utils
55
python-dateutil==2.8.2
6-
requests==2.27.1
7-
coverage==6.3.2
8-
tox==3.25.0
9-
virtualenv==20.14.1
10-
Sphinx==4.5.0
6+
requests==2.29.0
7+
coverage==7.2.5
8+
tox==4.5.1
9+
virtualenv==20.23.0
10+
Sphinx==7.0.0
1111
sphinxcontrib-websupport==1.2.4
12-
pip~=22.0.4
13-
build~=0.7.0
14-
wheel~=0.37.1
12+
pip==23.1.2
13+
build==0.10.0
14+
wheel==0.40.0
1515
py~=1.11.0
16-
lxml~=4.8.0
16+
lxml==4.9.2
1717
utils~=1.0.1
18-
keyring~=23.5.0
19-
docutils==0.16
18+
keyring==23.13.1
19+
docutils==0.19
2020
pyparsing~=3.0.8
21-
config~=0.5.1
21+
config~=0.5.1
22+
colorama~=0.4.6
23+
attrs==23.1.0
24+
argparse~=1.4.0
25+
toml~=0.10.2
26+
Jinja2~=3.1.2
27+
env~=0.1.0
28+
filelock~=3.12.0
29+
pluggy~=1.0.0
30+
six~=1.16.0
31+
packaging~=23.1
32+
pytest==7.3.1
33+
dill~=0.3.6
34+
pytz==2023.3
35+
Babel==2.12.1
36+
pep517==0.13.0
37+
tomli~=2.0.1
38+
Werkzeug~=2.3.3
39+
Flask~=2.3.2
40+
click~=8.1.3
41+
MarkupSafe==2.1.2
42+
blinker~=1.6.2
43+
itsdangerous~=2.1.2
44+
isort==5.12.0
45+
pkginfo==1.9.6
46+
pylint==2.17.3
47+
astroid==2.15.4
48+
mccabe==0.7.0
49+
platformdirs~=3.5.0
50+
imagesize==1.4.1
51+
snowballstemmer~=2.2.0
52+
Pygments~=2.15.1
53+
wrapt==1.15.0
54+
certifi==2022.12.7
55+
oauthlib==3.2.2
56+
idna==3.4
57+
chardet~=5.1.0
58+
alabaster==0.7.13
59+
zipp==3.15.0
60+
distlib~=0.3.6
61+
Empty~=0.4.4

0 commit comments

Comments
 (0)