Skip to content

Commit

Permalink
Merge pull request #91 from JaviCerveraIngram/CPS-76-rql-fix
Browse files Browse the repository at this point in the history
CPS-76 Accept rql.Query in BaseResource.list method
  • Loading branch information
marcserrat committed Mar 23, 2020
2 parents 8285722 + a24149d commit d814325
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions connect/resources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import functools
import logging
from typing import Any, List, Dict, Tuple
from typing import Any, List, Dict, Tuple, Union

import requests
from requests import compat
Expand All @@ -15,6 +15,7 @@
from connect.logger import function_log
from connect.models.base import BaseModel
from connect.models.server_error_response import ServerErrorResponse
from connect.rql import Query


class ApiClient(object):
Expand Down Expand Up @@ -158,8 +159,13 @@ def filters(self, **kwargs):
return filters

def list(self, filters=None):
# type: (Dict[str, Any]) -> List[Any]
# type: (Union[Query, Dict[str, Any]]) -> List[Any]
filters = filters or self.filters()
self.logger.info('Get list request with filters - {}'.format(filters))
response, _ = self._api.get(params=filters)
if isinstance(filters, Query):
compiled = filters.compile()
self.logger.info('Get list request with Query - {}'.format(compiled))
response, _ = ApiClient(self._api.config, self._api.base_path + compiled).get()
else:
self.logger.info('Get list request with filters - {}'.format(filters))
response, _ = self._api.get(params=filters)
return self.model_class.deserialize(response)

0 comments on commit d814325

Please sign in to comment.