11import requests
22from contentstack import config
33import urllib .parse
4+ import logging
45
56
6- class HTTPRequest (object ):
7+ class HTTPRequestConnection (object ):
78
89 def __init__ (self , url_path , query = dict , local_headers = dict ):
910 self .url_path = url_path
1011 self ._query_prams = query
1112 self ._local_headers = local_headers
1213 if 'environment' in self ._local_headers :
1314 self ._query_prams ['environment' ] = self ._local_headers ['environment' ]
15+ self .url_path = config .Config ().get_endpoint (self .url_path )
1416
15- # self._query_prams = urllib.parse.quote_plus (self._query_prams)
17+ def http_request (self ) -> dict :
1618 self ._local_headers ['X-User-Agent' ] = self ._contentstack_user_agent ()
1719 self ._local_headers ['Content-Type' ] = 'application/json'
18- # http request based on url_path and respected query
19- self .url_path = config .Config ().get_endpoint (self .url_path )
20- self ._http_request ()
21-
22- def _http_request (self ):
20+ # print('_query_prams', self._query_prams)
21+ # print('url_endpoint', self.url_path)
22+ # print('Please wait we are fetching {0} response'.format(self.url_path))
2323 response = requests .get (
24- self .url_path ,
25- params = self ._query_prams ,
24+ self .url_path , params = self ._query_prams ,
2625 headers = self ._local_headers ,
2726 )
2827
29- json_response = response .json ()
30- stack = json_response ['stack' ]
31- collaborators = stack ['collaborators' ]
32- print (collaborators , collaborators )
28+ print (response .url )
29+ logging .info ('url' , response .url )
30+ if response .ok :
31+ json_response = response .json ()
32+ if 'stack' in json_response :
33+ logging .info ('stack response' )
34+ return json_response ['stack' ]
35+ if 'content_types' in json_response :
36+ logging .info ('content type response' )
37+ return json_response ['content_types' ]
38+ if 'items' in json_response :
39+ logging .info ('sync response' )
40+ return json_response ['items' ]
41+ else :
42+ error_response = response .json ()
43+ # error_message = error_response["error_message"]
44+ # error_code = error_response["error_code"]
45+ # error_code = error_response["errors"]
46+ return error_response
3347
3448 @staticmethod
3549 def _contentstack_user_agent () -> str :
@@ -58,5 +72,14 @@ def _contentstack_user_agent() -> str:
5872
5973 return header .__str__ ()
6074
61- # connection = HTTPRequest(url_path='sync', query=None)
62- # connection._http_request()
75+ def set_entry_model (self ):
76+ pass
77+
78+ def set_content_type_model (self ):
79+ pass
80+
81+ def set_query_model (self ):
82+ pass
83+
84+ def set_asset_model (self ):
85+ pass
0 commit comments