Repository URL to install this package:
|
Version:
0.6.1 ▾
|
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
"""Base REST adapter."""
from ..session import RetrySession
class RestAdapterBase:
"""Base class for REST adapters."""
URL_MAP = {} # type: ignore[var-annotated]
"""Mapping between the internal name of an endpoint and the actual URL."""
_HEADER_JSON_CONTENT = {"Content-Type": "application/json"}
def __init__(self, session: RetrySession, prefix_url: str = "") -> None:
"""RestAdapterBase constructor.
Args:
session: Session to be used in the adapter.
prefix_url: String to be prepend to all URLs.
"""
self.session = session
self.prefix_url = prefix_url
def get_url(self, identifier: str) -> str:
"""Return the resolved URL for the specified identifier.
Args:
identifier: Internal identifier of the endpoint.
Returns:
The resolved URL of the endpoint (relative to the session base URL).
"""
return "{}{}".format(self.prefix_url, self.URL_MAP[identifier])
def get_facade_url(self, facade_prefix: str, identifier: str) -> str:
"""Return the resolved facade URL for the specified identifier.
Args:
identifier: Internal identifier of the endpoint.
Returns:
The resolved facade URL of the endpoint.
"""
return "{}{}{}".format(facade_prefix, self.prefix_url, self.URL_MAP[identifier])