Exemplo n.º 1
0
    def __init__(self, cfg: Union[str, dict]):
        """Initializes Class

        Args:
            cfg (Union[str, dict]): As a str it should contain a full path
                pointing to a configuration file (json/toml). See
                config.* in the examples folder for reference."""
        BaseApiClient.__init__(self, cfg=cfg)
        self.logged_in: bool = False
Exemplo n.º 2
0
    def __init__(self, cfg: Union[str, dict]):
        """Initializes Class

        Args:
            cfg (Union[str, dict]): As a str it should contain a full path
                pointing to a configuration file (json/toml). See
                config.* in the examples folder for reference.
            sem (Optional[int]): An integer that defines the number of parallel
                requests to make."""
        BaseApiClient.__init__(self, cfg=cfg)
Exemplo n.º 3
0
    def __init__(self, cfg: Union[str, dict], autoconnect=True):
        BaseApiClient.__init__(self, cfg=cfg)
        self.adserver: Server = Server(self.cfg['URI']['Base'], get_info=ALL)

        if autoconnect:
            self.connection: Connection = Connection(
                self.adserver,
                auto_bind=True,
                user=self.cfg['Auth']['Username'],
                password=self.cfg['Auth']['Password'],
                authentication=self.cfg['Auth']['Type'] or None)
        else:
            self.connection = None
Exemplo n.º 4
0
async def test_request_debug():
    ts = time.perf_counter()
    bprint('Test: Request Debug')

    async with BaseApiClient() as bac:
        async with aio.ClientSession() as session:
            response = await session.get('https://www.google.com', ssl=False)

        results = await bac.request_debug(response=response)

        assert type(results) is str

        print('Results:\n', results)

    bprint(f'-> Completed in {(time.perf_counter() - ts):f} seconds.')
Exemplo n.º 5
0
async def test_process_results():
    ts = time.perf_counter()
    bprint('Test: Process Results')

    async with BaseApiClient() as bac:
        tasks = [asyncio.create_task(bac.request(method='get',
                                                 end_point='http://openlibrary.org/search/lists.json',
                                                 params={'limit':  5,
                                                         'q':      'book',
                                                         'offset': 0}))]
        results = Results(data=await asyncio.gather(*tasks))

        assert type(results) is Results
        assert results.success is not None
        assert not results.failure

        processed_results = await bac.process_results(results, data_key='docs')
        tprint(processed_results, top=5)

    bprint(f'-> Completed in {(time.perf_counter() - ts):f} seconds.')
Exemplo n.º 6
0
async def test_request_debug():
    ts = time.perf_counter()

    async with BaseApiClient() as bac:
        tasks = [
            asyncio.create_task(
                bac.request(
                    method='get',
                    end_point='http://openlibrary.org/search/lists.json',
                    params={
                        'limit': 5,
                        'q': 'book',
                        'offset': 0
                    }))
        ]
        results = Results(data=await asyncio.gather(*tasks))

    # Test top 3 (expecting 3 success)
    bprint('Test: Test Print (Top 5 Results)')
    tprint(await bac.process_results(results, data_key='docs'), top=5)

    bprint(f'-> Completed in {(time.perf_counter() - ts):f} seconds.')
Exemplo n.º 7
0
 def __init__(self, cfg: Union[str, dict], sem: Optional[int] = None):
     BaseApiClient.__init__(self, cfg=cfg, sem=sem or self.SEM)