99import enum
1010import logging
1111from urllib import parse
12-
13- from urllib3 import Retry
14-
15- import contentstack
12+ from urllib3 .util import Retry
1613from contentstack .asset import Asset
1714from contentstack .assetquery import AssetQuery
1815from contentstack .contenttype import ContentType
1916from contentstack .https_connection import HTTPSConnection
2017from contentstack .image_transform import ImageTransform
2118
19+
2220__author__ = "ishaileshmishra (ishaileshmishra@gmail.com)"
2321__license__ = "MIT"
2422__version__ = '1.7.0'
2523
2624log = logging .getLogger (__name__ )
27- default_host = 'cdn.contentstack.io'
25+ DEFAULT_HOST = 'cdn.contentstack.io'
2826
2927
3028class ContentstackRegion (enum .Enum ):
@@ -37,17 +35,17 @@ class ContentstackRegion(enum.Enum):
3735
3836
3937class Stack :
40- from urllib3 .util import Retry
4138
4239 """
4340 A stack can be defined as a pool of data or a container that holds all
4441 the content/assets related to a site. It is a collaboration space where multiple users can work
4542 together to create, edit, approve, and publish content.
4643 (API Reference)[https://www.contentstack.com/docs/developers/apis/content-delivery-api/#stack]:
4744 """
45+ #from urllib3.util import Retry
4846
4947 def __init__ (self , api_key : str , delivery_token : str , environment : str ,
50- host = default_host ,
48+ host = DEFAULT_HOST ,
5149 version = 'v3' ,
5250 region = ContentstackRegion .US ,
5351 timeout = 30 ,
@@ -67,7 +65,8 @@ def __init__(self, api_key: str, delivery_token: str, environment: str,
6765 :param branch: branch of the stack
6866 :param version: (optional) apiVersion of the stack default is v3
6967 :param region: (optional) region support of the stack default is ContentstackRegion.US
70- :param live_preview: (optional) accepts type dictionary that enables live_preview option for request,
68+ :param live_preview: (optional) accepts type dictionary that enables
69+ live_preview option for request,
7170 takes input as dictionary object. containing one/multiple key value pair like below.
7271
7372 ```python
@@ -82,7 +81,6 @@ def __init__(self, api_key: str, delivery_token: str, environment: str,
8281 :param retry_strategy (optional) custom retry_strategy can be set.
8382 # Method to create retry_strategy: create object of Retry() and provide the
8483 # required parameters like below
85-
8684 **Example:**
8785
8886 >>> _strategy = Retry(total=5, backoff_factor=1, status_forcelist=[408, 429])
@@ -123,22 +121,19 @@ def _validate_stack(self):
123121 'You are not permitted to the stack without valid Environment' )
124122
125123
126- if self .region .value == 'eu' and self .host == default_host :
124+ if self .region .value == 'eu' and self .host == DEFAULT_HOST :
127125 self .host = 'eu-cdn.contentstack.com'
128- elif self .region .value == 'azure-na' and self .host == default_host :
126+ elif self .region .value == 'azure-na' and self .host == DEFAULT_HOST :
129127 self .host = 'azure-na-cdn.contentstack.com'
130128 elif self .region .value != 'us' :
131- self .host = '{}-{}' .format (self .region .value , default_host )
132-
133- self .endpoint = 'https://{}/{}' . format ( self .host , self . version )
129+ # self.host = '{}-{}'.format(self.region.value, DEFAULT_HOST )
130+ self . host = f' { self . region . value } - { DEFAULT_HOST } '
131+ self .endpoint = f 'https://{ self . host } /{ self .version } '
134132
135133 self .headers = {
136- 'api_key' :
137- self .api_key ,
138- 'access_token' :
139- self .delivery_token ,
140- 'environment' :
141- self .environment
134+ 'api_key' : self .api_key ,
135+ 'access_token' :self .delivery_token ,
136+ 'environment' : self .environment
142137 }
143138
144139 if self .branch is not None :
@@ -163,7 +158,7 @@ def _validate_live_preview(self):
163158 self .headers ['authorization' ] = self .live_preview_dict ['authorization' ]
164159 # remove deliveryToken and environment
165160 self .host = self .live_preview_dict ['host' ]
166- self .endpoint = 'https://{}/{}' . format ( self .host , self . version )
161+ self .endpoint = f 'https://{ self . host } /{ self .version } '
167162 self .headers .pop ('access_token' )
168163 self .headers .pop ('environment' )
169164
@@ -252,18 +247,22 @@ def asset_query(self):
252247 """
253248 return AssetQuery (self .http_instance )
254249
255- def sync_init (self , content_type_uid = None , start_from = None , locale = None , type = None ):
250+ def sync_init (self , content_type_uid = None , start_from = None , locale = None , publish_type = None ):
256251 """
257- Set init to ‘true’ if you want to sync all the published entries and assets. This is usually used when the
258- app does not have any content and you want to get all the content for the first time.\n
252+ Set init to ‘true’ if you want to sync all the published entries and assets.
253+ This is usually used when the app does not have any content and you want to
254+ get all the content for the first time.\n
259255
260256 :param content_type_uid: (optional) content type UID. e.g., products
261257 This retrieves published entries of specified content type
262258 :param start_from: (optional) The start date. e.g., 2018-08-14T00:00:00.000Z
263259 This retrieves published entries starting from a specific date
264- :param locale: (optional) locale code. e.g., en-us, This retrieves published entries of specific locale.
265- :param type: (optional) If you do not specify any value, it will bring all published
266- entries and published assets. You can pass multiple types as comma-separated values,
260+ :param locale: (optional) locale code. e.g., en-us, This retrieves published
261+ entries of specific locale.
262+ :param publish_type: (optional) If you do not specify any value,
263+ it will bring all published
264+ entries and published assets. You can pass multiple types
265+ as comma-separated values,
267266 for example, entry_published,entry_unpublished,asset_published
268267 :return: list of sync items
269268 -------------------------------
@@ -273,7 +272,7 @@ def sync_init(self, content_type_uid=None, start_from=None, locale=None, type=No
273272 >>> import contentstack
274273 >>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
275274 >>> result = stack.sync_init(content_type_uid='content_type_uid',
276- start_from='date', locale='en-us', type ='asset_published')
275+ start_from='date', locale='en-us', publish_type ='asset_published')
277276 -------------------------------
278277 """
279278 self .sync_param ['init' ] = 'true'
@@ -283,8 +282,8 @@ def sync_init(self, content_type_uid=None, start_from=None, locale=None, type=No
283282 self .sync_param ['start_from' ] = start_from
284283 if locale is not None and isinstance (locale , str ):
285284 self .sync_param ['locale' ] = locale
286- if type is not None and isinstance (type , str ):
287- self .sync_param ['type' ] = type
285+ if publish_type is not None and isinstance (publish_type , str ):
286+ self .sync_param ['type' ] = publish_type
288287 return self .__sync_request ()
289288
290289 def pagination (self , pagination_token : str ):
@@ -333,18 +332,18 @@ def __sync_request(self):
333332 :return: :class:`Response <Response>` object
334333 :rtype: requests.Response
335334 """
336- base_url = '{ }/stacks/sync'. format ( self . http_instance . endpoint )
335+ base_url = f' { self . http_instance . endpoint } /stacks/sync'
337336 self .sync_param ['environment' ] = self .http_instance .headers ['environment' ]
338337 encoded_query = parse .urlencode (self .sync_param )
339- url = '{ }?{}' . format ( base_url , encoded_query )
338+ url = f' { base_url } ?{ encoded_query } '
340339 result = self .http_instance .get (url )
341340 return result
342341
343342 def image_transform (self , image_url , ** kwargs ):
344343 """
345344 This document is a detailed reference to Contentstack’s Image Delivery
346345 API and covers the parameters that you can add to the URL to retrieve,
347- manipulate (or convert) image files and display it to your web or
346+ manipulate (or convert) image files and display it to your web or
348347 mobile properties.\n
349348
350349 :param image_url: base url on which queries to apply
0 commit comments