Beispiel #1
0
    def __init__(self,
                 url_or_resource,
                 http_client=None,
                 api_base_path=None,
                 raise_with=None):
        if not http_client:
            http_client = SynchronousHttpClient()
        # Wrap http client's errors with raise_with
        http_client.raise_with = raise_with
        self._http_client = http_client

        # Load Swagger APIs always synchronously
        loader = Loader(SynchronousHttpClient(headers=http_client._headers),
                        [ClientProcessor()])

        forced_api_base_path = api_base_path is not None
        # url_or_resource can be url of type str,
        # OR a dict of resource itself.
        if isinstance(url_or_resource, (str, unicode)):
            log.debug(u"Loading from %s" % url_or_resource)
            self._api_docs = loader.load_resource_listing(url_or_resource)
            parsed_uri = urlparse(url_or_resource)
            if not api_base_path:
                api_base_path = "{uri.scheme}://{uri.netloc}".format(
                    uri=parsed_uri)
        else:
            log.debug(u"Loading from %s" % url_or_resource.get(u'url'))
            self._api_docs = url_or_resource
            loader.process_resource_listing(self._api_docs)
            if not api_base_path:
                api_base_path = url_or_resource.get(u'url')

        self._resources = {}
        for resource in self._api_docs[u'apis']:
            if forced_api_base_path and 'api_declaration' in resource:
                resource['api_declaration']['basePath'] = api_base_path
            self._resources[resource[u'name']] = Resource(
                resource, http_client, api_base_path)
            setattr(self, resource['name'],
                    self._get_resource(resource[u'name']))
Beispiel #2
0
    def __init__(self, url_or_resource, http_client=None,
                 api_base_path=None, raise_with=None):
        if not http_client:
            http_client = SynchronousHttpClient()
        # Wrap http client's errors with raise_with
        http_client.raise_with = raise_with
        self._http_client = http_client

        # Load Swagger APIs always synchronously
        loader = Loader(
            SynchronousHttpClient(headers=http_client._headers),
            [ClientProcessor()])

        forced_api_base_path = api_base_path is not None
        # url_or_resource can be url of type str,
        # OR a dict of resource itself.
        if isinstance(url_or_resource, (str, unicode)):
            log.debug(u"Loading from %s" % url_or_resource)
            self._api_docs = loader.load_resource_listing(url_or_resource)
            parsed_uri = urlparse(url_or_resource)
            if not api_base_path:
                api_base_path = "{uri.scheme}://{uri.netloc}".format(
                    uri=parsed_uri)
        else:
            log.debug(u"Loading from %s" % url_or_resource.get(u'url'))
            self._api_docs = url_or_resource
            loader.process_resource_listing(self._api_docs)
            if not api_base_path:
                api_base_path = url_or_resource.get(u'url')

        self._resources = {}
        for resource in self._api_docs[u'apis']:
            if forced_api_base_path and 'api_declaration' in resource:
                resource['api_declaration']['basePath'] = api_base_path
            self._resources[resource[u'name']] = Resource(
                resource, http_client, api_base_path)
            setattr(self, resource['name'],
                    self._get_resource(resource[u'name']))