3232class Config :
3333
3434 def __init__ (self ):
35- self .defaultConfig = dict (protocol = "https://" , host = "cdn.contentstack.io" , port = 443 , version = "v3" , path = {
36- "stacks" : "stacks" ,
37- "sync" : "stacks/sync" ,
38- "content_types" : "content_types" ,
39- "entries" : "content_types" ,
40- "assets" : "assets" ,
41- "environments" : "environments"
42- })
35+ self .defaultConfig = dict (protocol = "https:/" ,
36+ host = "cdn.contentstack.io" ,
37+ port = 443 ,
38+ version = "v3" ,
39+ path = {
40+ "stacks" : "stacks" ,
41+ "sync" : "stacks/sync" ,
42+ "content_types" : "content_types" ,
43+ "entries" : "content_types" ,
44+ "assets" : "assets" ,
45+ "environments" : "environments"
46+ })
4347
4448 def host (self , host_url = None ):
45- if host_url is not None :
46- self .defaultConfig [" host" ] = host_url
47- return self .defaultConfig [" host" ]
49+ if host_url is not None and isinstance ( host_url , str ) :
50+ self .defaultConfig [' host' ] = host_url
51+ return self .defaultConfig [' host' ]
4852
49- def version (self , version : str = None ):
53+ def version (self , version = None ):
5054 if version is not None and isinstance (version , str ):
5155 self .defaultConfig ['version' ] = version
5256 return self .defaultConfig ['version' ]
@@ -59,20 +63,25 @@ def path(self, path):
5963 return url_section [path ]
6064 else :
6165 logging .error ("{0} is invalid endpoint path" .format (path ))
62- raise ValueError ('Invalid endpoint!!, {0} is invalid endpoint path, '
63- 'Path can be found among {1}'
64- .format (path , url_section .keys ()))
66+ raise Exception ('Invalid endpoint!!, {0} is invalid endpoint path, Path can be found among {1}'
67+ .format (path , url_section .keys ()))
68+
69+ @property
70+ def default_endpoint (self ):
71+ endpoint_url = "{0}/{1}/{2}" .format (self .defaultConfig ["protocol" ], self .host (), self .version ())
72+ return endpoint_url
6573
6674 def endpoint (self , path ):
6775 url = self .path (path )
6876 if url is not None and isinstance (url , str ):
69- url = "{0}{1}/{2}/{3}" .format (self .defaultConfig ["protocol" ], self .host (), self .version (), url )
77+ url = "{0}/ {1}/{2}/{3}" .format (self .defaultConfig ["protocol" ], self .host (), self .version (), url )
7078 logging .info ('endpoint is :: {0} ' .format (url ))
79+
7180 return url
7281
7382
74- config = Config ()
75- config .host ("cdn.contentstack.io" )
76- result_url = config .endpoint ('entries ' )
77- print (result_url )
83+ # config = Config()
84+ # config.host("stag- cdn.contentstack.io")
85+ # result_url = config.endpoint('assets ')
86+ # print(result_url)
7887
0 commit comments