|
20 | 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22 | 22 | * SOFTWARE. |
23 | | - * |
24 | | - """ |
25 | 23 |
|
26 | | -import logging |
| 24 | + """ |
27 | 25 |
|
28 | 26 |
|
29 | 27 | class Config: |
30 | 28 |
|
31 | | - def __init__(self, host_url: str = 'cdn.contentstack.io'): |
32 | | - self.host_url = host_url |
33 | | - self.api_version: str = 'v3' |
34 | | - self.http_protocol: str = 'https://' |
35 | | - |
36 | | - def set_host(self, host_url=None): |
37 | | - logging.info("set host", host_url) |
38 | | - self.host_url = host_url |
39 | | - return self |
| 29 | + def __init__(self): |
| 30 | + self.default_config = dict(protocol="https", host="cdn.contentstack.io", port=443, version="v3", urls={ |
| 31 | + "sync": "/stacks/sync", |
| 32 | + "content_types": "/content_types/", |
| 33 | + "entries": "/entries/", |
| 34 | + "assets": "/assets/", |
| 35 | + "environments": "/environments/" |
| 36 | + }) |
40 | 37 |
|
41 | | - def get_host(self): |
42 | | - logging.info('getting host url', self.host_url) |
43 | | - return self.host_url |
| 38 | + def host(self, host_url=None): |
| 39 | + if host_url is not None: |
| 40 | + self.default_config["host"] = host_url |
| 41 | + return self.default_config["host"] |
44 | 42 |
|
45 | | - def get_version(self): |
46 | | - logging.info('getting api version', self.api_version) |
47 | | - return self.api_version |
| 43 | + def version(self): |
| 44 | + return self.default_config["host"] |
48 | 45 |
|
49 | | - def get_http_protocol(self): |
50 | | - logging.info('get http protocol', self.http_protocol) |
51 | | - return self.http_protocol |
| 46 | + def protocol(self): |
| 47 | + return self.default_config["protocol"] |
52 | 48 |
|
53 | 49 | def get_endpoint(self, url_path): |
54 | | - api_version: str = self.get_version() |
55 | | - host_url = self.get_host() |
56 | | - http_protocol = self.get_http_protocol() |
57 | | - config_url = "{0}{1}/{2}/{3}".format(http_protocol, host_url, api_version, url_path) |
| 50 | + config_url = "{0}{1}/{2}/{3}".format(self.protocol(), self.host(), self.version(), url_path) |
58 | 51 | return config_url |
| 52 | + |
| 53 | + def hiShailesh(self): |
| 54 | + print("Something") |
| 55 | + |
| 56 | + |
| 57 | +config = Config() |
| 58 | +host = config.host("stag-cdn.contentstack.io") |
| 59 | +print(host) |
| 60 | + |
0 commit comments