Skip to content

Commit 87986ae

Browse files
requests implemented in stack
1 parent dfdf34e commit 87986ae

File tree

6 files changed

+51
-59
lines changed

6 files changed

+51
-59
lines changed

contentstack/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
from .entry import Entry
33
from .asset import Asset
44
from .asset_library import AssetLibrary
5-
from .asset_model import AssetModel
65
from .config import Config
6+
from .sync_stack import SyncStack
7+
from .query_result import QueryResult
78
from .content_type import ContentType
89
from .entry_model import EntryModel
910
from .errors import HTTPError, ConfigError
1011
from .group import Group
11-
from .http_request import HTTPRequest
12+
from .http_request import HTTPRequestConnection
1213
from .stack import Stack
1314

1415
__author__ = 'contentstack - (www.github.con/contentstack)'

contentstack/asset_model.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

contentstack/config.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@
2828

2929
class Config(object):
3030

31-
SDK_VERSION = '[0.0.1]'
32-
33-
def __init__(self):
34-
self.host_url: str = 'cdn.contentstack.io'
31+
def __init__(self, host_url: str = 'cdn.contentstack.io'):
32+
self.host_url = host_url
3533
self.api_version: str = 'v3'
3634
self.http_protocol: str = 'https://'
3735

contentstack/http_request.py

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,49 @@
11
import requests
22
from contentstack import config
33
import 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

contentstack/query_result.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class QueryResult(object):
2+
3+
def __init__(self):
4+
pass

contentstack/sync_stack.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class SyncStack(object):
2+
3+
def __init__(self):
4+
pass

0 commit comments

Comments
 (0)