Skip to content

Commit 5ebb171

Browse files
stack, config, content_type, error error
1 parent 46579f2 commit 5ebb171

File tree

12 files changed

+469
-0
lines changed

12 files changed

+469
-0
lines changed

.vscode/launch.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "extensionHost",
9+
"request": "launch",
10+
"name": "Launch Extension",
11+
"runtimeExecutable": "${execPath}",
12+
"args": [
13+
"--extensionDevelopmentPath=${workspaceFolder}"
14+
],
15+
"outFiles": [
16+
"${workspaceFolder}/out/**/*.js"
17+
],
18+
"preLaunchTask": "npm"
19+
},
20+
{
21+
"name": "Python: Current File (Integrated Terminal)",
22+
"type": "python",
23+
"request": "launch",
24+
"program": "${file}",
25+
"console": "integratedTerminal"
26+
}
27+
]
28+
}

.vscode/settings.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"editor.fontSize": 13,
3+
"python.testing.unittestArgs": [
4+
"-v",
5+
"-s",
6+
"./tests",
7+
"-p",
8+
"*_test.py"
9+
],
10+
"python.testing.pyTestEnabled": true,
11+
"python.testing.nosetestsEnabled": false,
12+
"python.testing.unittestEnabled": false,
13+
"python.testing.pyTestArgs": [
14+
"tests"
15+
],
16+
"python.pythonPath": "/usr/local/bin/python3",
17+
"workbench.fontAliasing": "auto",
18+
"workbench.tree.indent": 20
19+
}

CHANGELOGS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
## v1.0.0
3+
Initial release of the python Content Delivery API SDK.

READ.ME.md

Whitespace-only changes.

contentstack/HTTPConnection.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import logging
2+
import requests
3+
from requests.auth import HTTPDigestAuth
4+
import json
5+
import config
6+
import urllib.parse
7+
8+
9+
class HTTPConnection:
10+
11+
def __init__(self, local_headers, query):
12+
self.__local_headers = {}
13+
self.__query = {}
14+
self.__local_headers = local_headers
15+
self.__query = query
16+
17+
18+
def get_query_request(self):
19+
return self.__http_request()
20+
21+
22+
def get_entry_request(self):
23+
return self.__http_request()
24+
25+
26+
def get_stack_request(self):
27+
return self.__http_request()
28+
29+
30+
def get_content_type_req(self):
31+
return self.__http_request()
32+
33+
34+
def get_group_request(self):
35+
return self.__http_request()
36+
37+
38+
def __http_request(self):
39+
40+
__config = config.Config()
41+
encoded_query = urllib.parse.urlencode(self.__query)
42+
self.__local_headers.update({'Content-Type': 'application/json',
43+
'X-User-Agent': __config.SDK_VERSION })
44+
response = requests.post(
45+
__config.get_host(), encoded_query, self.__local_headers)
46+
47+
print(response.json)
48+
49+

contentstack/asser_model.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
* MIT License
3+
*
4+
* Copyright (c) 2012 - 2019 Contentstack
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
"""
25+
26+
import logging
27+
28+
29+
class AssetModel():
30+
logging.info("Asset Model")
31+
32+
def __init__(self):
33+
logging.info('AssetModel initialised')

contentstack/asset_library.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
* MIT License
3+
*
4+
* Copyright (c) 2012 - 2019 Contentstack
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
"""
25+
26+
import logging
27+
28+
29+
class AssetLibrary():
30+
logging.info("Asset library")
31+
32+
def __init__(self):
33+
logging.info('Asset initialised')

contentstack/config.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
* MIT License
3+
*
4+
* Copyright (c) 2012 - 2019 Contentstack
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
"""
25+
26+
import logging
27+
28+
class Config(object):
29+
30+
31+
def __init__(self):
32+
self.host_url = 'cdn.contentstack.io'
33+
self.api_version = 'v3'
34+
self.environment = None
35+
self.SDK_VERSION = 0.0.1
36+
self.SDK_NAME = 'contentstack-python'
37+
38+
39+
def set_host(self, host_url= 'cdn.contentstack.io'):
40+
logging.info("set host")
41+
if host_url != None:
42+
self.url = host_url
43+
return self
44+
45+
46+
def set_environment(self, environment):
47+
logging.info("set environment")
48+
if environment != None:
49+
self.environment = environment
50+
return self
51+
52+
def get_host(self):
53+
logging.info('getting host url')
54+
return self.host_url
55+
56+
57+
def get_version(self):
58+
logging.info('getting api version')
59+
return self.api_version
60+
61+
62+
def get_environment(self):
63+
logging.info('get invironment')
64+
return self.environment

contentstack/contentstack.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
"""
3+
* MIT License
4+
*
5+
* Copyright (c) 2012 - 2019 Contentstack
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*
25+
"""
26+
27+
import config
28+
import logging
29+
import stack
30+
from contentstack import stack
31+
32+
33+
class Contentstack(object):
34+
35+
def stack(self, api_key, access_token, environment, config):
36+
logging.info("Initicalised with configs")
37+
38+
if api_key is None:
39+
logging.error("API Key can not be empty")
40+
raise AssertionError("API Key can not be empty")
41+
42+
if access_token is None:
43+
logging.error("Access Token can not be empty")
44+
raise AssertionError("Access Token can not be empty")
45+
46+
if environment is None:
47+
logging.error("Environment can not be empty")
48+
raise AssertionError("Environment can not be empty")
49+
50+
if config is None:
51+
logging.error("congig can not be empty")
52+
raise AssertionError("Environment can not be empty")
53+
54+
else:
55+
logging.info("stack initialisation attempted with config")
56+
return_stack = stack(api_key, access_token, environment)
57+
return return_stack
58+
59+
60+
61+
62+
63+

contentstack/errors.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"""
2+
* MIT License
3+
*
4+
* Copyright (c) 2012 - 2019 Contentstack
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*
24+
"""
25+
26+
27+
import logging
28+
29+
class HTTPError(Exception):
30+
31+
errors_str = {
32+
33+
'error_invalid_json' : "Please provide valid JSON.",
34+
'error_message_stack_api_key_is_null' : "Stack api key can not be null.",
35+
'error_form_name' : "Please set contentType name.",
36+
'error_stack_access_token_is_null' : "Access token can not be null.",
37+
'error_stack_environment_is_null' : "Environment can not be null.",
38+
'Error_Connection_Error' : "Connection error",
39+
'Error_Auth_Failure_Error' : "Authentication Not present.",
40+
'Error_Parse_Error' : "Parsing Error.",
41+
'Error_Server_Error' : "Server interaction went wrong, Please try again.",
42+
'Error_Default' : "Oops! Something went wrong. Please try again.",
43+
'Error_No_Network' : "Network not available.",
44+
'Error_Called_Default_Method' : "You must called Contentstack.stack() first",
45+
'Error_Query_Filter_Exception' : "Please provide valid params."
46+
}
47+
48+
def __init__(self):
49+
50+
errors = {
51+
52+
400: "The request was incorrect or corrupted.",
53+
401: "The login credentials are invalid.",
54+
403: "The page or resource that is being accessed is forbidden.",
55+
404: "The requested page or resource could not be found.",
56+
412: "The entered API key is invalid.",
57+
422: "The request is syntactically correct but contains semantic errors",
58+
429: "The number of requests exceeds the allowed limit for the given time period.",
59+
500: "The server is malfunctioning and is not specific on what the problem is.",
60+
502: "A server received an invalid response from another server.",
61+
504: "A server did not receive a timely response from another server that it was accessing while attempting to load the web page or fill another request by the browser."
62+
}
63+
64+
65+
def get_error(self, response):
66+
print('Error')
67+
68+
69+
def set_logging_config(self,level):
70+
print('level '+level)
71+
72+
73+
class ConfigError(Exception):
74+
"""Configuration Error Class"""
75+
pass
76+
77+

0 commit comments

Comments
 (0)