1+ """
2+ Downloads Operations Client - Level 3: Downloads-Specific Operations
3+
4+ This module provides downloads-specific operations within the Core API.
5+ Part of the three-tier V1.1 architecture with complete 4-pattern detailed functions.
6+
7+ Each operation provides 4 variants:
8+ - operation(params) - basic sync with explicit parameters
9+ - operation_async(params) - basic async with explicit parameters
10+ - operation_detailed(params) - detailed sync with explicit parameters
11+ - operation_detailed_async(params) - detailed async with explicit parameters
12+
13+ Perfect for MCP servers and documentation generation.
14+ """
15+
16+ import asyncio
17+ from typing import Optional , List , Union , Any
18+ from httpx import Response
19+
20+ # Import from Level 3 (operation-specific models)
21+ from .models import DownloadsResponse , DownloadsListResponse , CreateDownloadsRequest
22+
23+ # Import raw operations
24+ try :
25+ from ....raw_clients .alfresco_core_client .core_client .api .downloads import (
26+ cancel_download as _cancel_download ,
27+ create_download as _create_download ,
28+ get_download as _get_download
29+ )
30+ RAW_OPERATIONS_AVAILABLE = True
31+ except ImportError :
32+ RAW_OPERATIONS_AVAILABLE = False
33+
34+
35+ class DownloadsClient :
36+ """
37+ Downloads operations client with 4-pattern detailed functions.
38+
39+ Provides high-level methods for downloads management operations
40+ that are essential for MCP servers and downloads workflows.
41+
42+ Each operation has 4 variants for maximum flexibility:
43+ - Basic sync/async for simple use cases
44+ - Detailed sync/async for full HTTP response access
45+ """
46+
47+ def __init__ (self , client_factory ):
48+ """Initialize with client factory for raw client access."""
49+ self ._client_factory = client_factory
50+ self ._raw_client = None
51+
52+ # Store raw operation references
53+ if RAW_OPERATIONS_AVAILABLE :
54+ self ._cancel_download = _cancel_download
55+ self ._create_download = _create_download
56+ self ._get_download = _get_download
57+
58+ def _get_raw_client (self ):
59+ """Get or create the raw client."""
60+ if self ._raw_client is None :
61+ # Import the raw core client directly
62+ from ....raw_clients .alfresco_core_client .core_client .client import AuthenticatedClient
63+
64+ # Create the raw client with same auth setup
65+ self ._raw_client = AuthenticatedClient (
66+ base_url = f"{ self ._client_factory .base_url } /alfresco/api/-default-/public/alfresco/versions/1" ,
67+ token = self ._client_factory .auth .get_auth_token (),
68+ prefix = self ._client_factory .auth .get_auth_prefix (),
69+ verify_ssl = self ._client_factory .verify_ssl
70+ )
71+ return self ._raw_client
72+
73+ def get_httpx_client (self ):
74+ """
75+ Get direct access to raw httpx client for advanced operations.
76+
77+ Perfect for MCP servers that need raw HTTP access.
78+ """
79+ return self ._get_raw_client ().get_httpx_client ()
80+
81+ # ==================== CANCEL_DOWNLOAD OPERATION ====================
82+
83+ def cancel_download (self , download_id : str ) -> Any :
84+ """Cancel Download operation."""
85+ from ....raw_clients .alfresco_core_client .core_client .api .downloads import cancel_download
86+ return cancel_download .sync (client = self ._get_raw_client (), download_id = download_id )
87+
88+ async def cancel_download_async (self , download_id : str ) -> Any :
89+ """Cancel Download operation (async)."""
90+ from ....raw_clients .alfresco_core_client .core_client .api .downloads import cancel_download
91+ return await cancel_download .asyncio (client = self ._get_raw_client (), download_id = download_id )
92+
93+ def cancel_download_detailed (self , download_id : str ) -> Response :
94+ """Cancel Download operation (detailed)."""
95+ from ....raw_clients .alfresco_core_client .core_client .api .downloads import cancel_download
96+ return cancel_download .sync_detailed (client = self ._get_raw_client (), download_id = download_id )
97+
98+ async def cancel_download_detailed_async (self , download_id : str ) -> Response :
99+ """Cancel Download operation (detailed, async)."""
100+ from ....raw_clients .alfresco_core_client .core_client .api .downloads import cancel_download
101+ return await cancel_download .asyncio_detailed (client = self ._get_raw_client (), download_id = download_id )
102+
103+ # ==================== CREATE_DOWNLOAD OPERATION ====================
104+
105+ def create_download (self , body : Any , fields : Optional [List [str ]] = None ) -> Any :
106+ """Create Download operation."""
107+ from ....raw_clients .alfresco_core_client .core_client .api .downloads import create_download
108+ from ....raw_clients .alfresco_core_client .core_client .types import UNSET
109+ return create_download .sync (
110+ client = self ._get_raw_client (),
111+ body = body ,
112+ fields = fields if fields is not None else UNSET
113+ )
114+
115+ async def create_download_async (self , body : Any , fields : Optional [List [str ]] = None ) -> Any :
116+ """Create Download operation (async)."""
117+ from ....raw_clients .alfresco_core_client .core_client .api .downloads import create_download
118+ from ....raw_clients .alfresco_core_client .core_client .types import UNSET
119+ return await create_download .asyncio (
120+ client = self ._get_raw_client (),
121+ body = body ,
122+ fields = fields if fields is not None else UNSET
123+ )
124+
125+ def create_download_detailed (self , body : Any , fields : Optional [List [str ]] = None ) -> Response :
126+ """Create Download operation (detailed)."""
127+ from ....raw_clients .alfresco_core_client .core_client .api .downloads import create_download
128+ from ....raw_clients .alfresco_core_client .core_client .types import UNSET
129+ return create_download .sync_detailed (
130+ client = self ._get_raw_client (),
131+ body = body ,
132+ fields = fields if fields is not None else UNSET
133+ )
134+
135+ async def create_download_detailed_async (self , body : Any , fields : Optional [List [str ]] = None ) -> Response :
136+ """Create Download operation (detailed, async)."""
137+ from ....raw_clients .alfresco_core_client .core_client .api .downloads import create_download
138+ from ....raw_clients .alfresco_core_client .core_client .types import UNSET
139+ return await create_download .asyncio_detailed (
140+ client = self ._get_raw_client (),
141+ body = body ,
142+ fields = fields if fields is not None else UNSET
143+ )
144+
145+ # ==================== GET_DOWNLOAD OPERATION ====================
146+
147+ def get_download (self , download_id : str , fields : Optional [List [str ]] = None ) -> Any :
148+ """Get Download operation."""
149+ from ....raw_clients .alfresco_core_client .core_client .api .downloads import get_download
150+ from ....raw_clients .alfresco_core_client .core_client .types import UNSET
151+ return get_download .sync (
152+ client = self ._get_raw_client (),
153+ download_id = download_id ,
154+ fields = fields if fields is not None else UNSET
155+ )
156+
157+ async def get_download_async (self , download_id : str , fields : Optional [List [str ]] = None ) -> Any :
158+ """Get Download operation (async)."""
159+ from ....raw_clients .alfresco_core_client .core_client .api .downloads import get_download
160+ from ....raw_clients .alfresco_core_client .core_client .types import UNSET
161+ return await get_download .asyncio (
162+ client = self ._get_raw_client (),
163+ download_id = download_id ,
164+ fields = fields if fields is not None else UNSET
165+ )
166+
167+ def get_download_detailed (self , download_id : str , fields : Optional [List [str ]] = None ) -> Response :
168+ """Get Download operation (detailed)."""
169+ from ....raw_clients .alfresco_core_client .core_client .api .downloads import get_download
170+ from ....raw_clients .alfresco_core_client .core_client .types import UNSET
171+ return get_download .sync_detailed (
172+ client = self ._get_raw_client (),
173+ download_id = download_id ,
174+ fields = fields if fields is not None else UNSET
175+ )
176+
177+ async def get_download_detailed_async (self , download_id : str , fields : Optional [List [str ]] = None ) -> Response :
178+ """Get Download operation (detailed, async)."""
179+ from ....raw_clients .alfresco_core_client .core_client .api .downloads import get_download
180+ from ....raw_clients .alfresco_core_client .core_client .types import UNSET
181+ return await get_download .asyncio_detailed (
182+ client = self ._get_raw_client (),
183+ download_id = download_id ,
184+ fields = fields if fields is not None else UNSET
185+ )
186+
187+ def __repr__ (self ) -> str :
188+ """String representation for debugging."""
189+ base_url = getattr (self ._client_factory , 'base_url' , 'unknown' )
190+ return f"DownloadsClient(base_url='{ base_url } ')"
0 commit comments