1111
1212import httpx
1313
14- from re3data ._client .base import BaseClient , Endpoint , ResourceType , ReturnType , is_valid_return_type
14+ from re3data ._client .base import (
15+ BaseClient ,
16+ Endpoint ,
17+ ResourceType ,
18+ ReturnType ,
19+ _build_query_params ,
20+ is_valid_return_type ,
21+ )
1522from re3data ._exceptions import RepositoryNotFoundError
1623from re3data ._response import Response , _build_response , _parse_repositories_response , _parse_repository_response
1724
@@ -82,10 +89,14 @@ class RepositoryManager:
8289 def __init__ (self , client : Client ) -> None :
8390 self ._client = client
8491
85- def list (self , return_type : ReturnType = ReturnType .DATACLASS ) -> list [RepositorySummary ] | Response | str :
92+ def list (
93+ self , query : str | None = None , return_type : ReturnType = ReturnType .DATACLASS
94+ ) -> list [RepositorySummary ] | Response | str :
8695 """List the metadata of all repositories in the re3data API.
8796
8897 Args:
98+ query: A query string to filter the results. If provided, only repositories matching the query
99+ will be returned.
89100 return_type: The desired return type for the API resource. Defaults to `ReturnType.DATACLASS`.
90101
91102 Returns:
@@ -97,7 +108,8 @@ def list(self, return_type: ReturnType = ReturnType.DATACLASS) -> list[Repositor
97108 httpx.HTTPStatusError: If the server returned an error status code >= 500.
98109 """
99110 is_valid_return_type (return_type )
100- response = self ._client ._request (Endpoint .REPOSITORY_LIST .value )
111+ query_params = _build_query_params (query )
112+ response = self ._client ._request (Endpoint .REPOSITORY_LIST .value , query_params )
101113 return _dispatch_return_type (response , ResourceType .REPOSITORY_LIST , return_type )
102114
103115 def get (self , repository_id : str , return_type : ReturnType = ReturnType .DATACLASS ) -> Repository | Response | str :
@@ -135,6 +147,9 @@ class Client(BaseClient):
135147 >>> response
136148 [RepositorySummary(id='r3d100010468', doi='https://doi.org/10.17616/R3QP53', name='Zenodo', link=Link(href='https://www.re3data.org/api/beta/repository/r3d100010468', rel='self'))]
137149 ... (remaining repositories truncated)
150+ >>> response = client.repositories.list(query="biosharing")
151+ >>> response
152+ [RepositorySummary(id='r3d100010142', doi='https://doi.org/10.17616/R3WS3X', name='FAIRsharing', link=Link(href='https://www.re3data.org/api/beta/repository/r3d100010142', rel='self'))]
138153 """
139154
140155 _client : httpx .Client
@@ -144,11 +159,13 @@ def __init__(self) -> None:
144159 self ._client .event_hooks ["response" ] = [log_response ]
145160 self ._repository_manager : RepositoryManager = RepositoryManager (self )
146161
147- def _request (self , path : str ) -> Response :
162+ def _request (self , path : str , query_params : dict [ str , str ] | None = None ) -> Response :
148163 """Send a HTTP GET request to the specified API endpoint.
149164
150165 Args:
151166 path: The path to send the request to.
167+ query_params: Optional URL query parameters to be sent with the HTTP GET request. This dictionary
168+ contains key-value pairs that will be added as query parameters to the API endpoint specified by path.
152169
153170 Returns:
154171 The response object from the HTTP request.
@@ -157,7 +174,7 @@ def _request(self, path: str) -> Response:
157174 httpx.HTTPStatusError: If the server returned an error status code >= 500.
158175 RepositoryNotFoundError: If the `repository_id` is not found.
159176 """
160- http_response = self ._client .get (path )
177+ http_response = self ._client .get (path , params = query_params )
161178 if http_response .is_server_error :
162179 http_response .raise_for_status ()
163180 return _build_response (http_response )
0 commit comments