python-zendesk-sdk 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_zendesk_sdk-0.1.0.dist-info/METADATA +218 -0
- python_zendesk_sdk-0.1.0.dist-info/RECORD +16 -0
- python_zendesk_sdk-0.1.0.dist-info/WHEEL +4 -0
- python_zendesk_sdk-0.1.0.dist-info/licenses/LICENSE +21 -0
- zendesk_sdk/__init__.py +28 -0
- zendesk_sdk/client.py +321 -0
- zendesk_sdk/config.py +111 -0
- zendesk_sdk/exceptions.py +178 -0
- zendesk_sdk/http_client.py +256 -0
- zendesk_sdk/models/__init__.py +40 -0
- zendesk_sdk/models/base.py +50 -0
- zendesk_sdk/models/comment.py +62 -0
- zendesk_sdk/models/organization.py +59 -0
- zendesk_sdk/models/ticket.py +169 -0
- zendesk_sdk/models/user.py +107 -0
- zendesk_sdk/pagination.py +296 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python-zendesk-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Modern Python SDK for Zendesk API
|
|
5
|
+
Project-URL: Homepage, https://github.com/bormog/python-zendesk-sdk
|
|
6
|
+
Project-URL: Repository, https://github.com/bormog/python-zendesk-sdk
|
|
7
|
+
Project-URL: Issues, https://github.com/bormog/python-zendesk-sdk/issues
|
|
8
|
+
Author: bormog
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: api,client,sdk,zendesk
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Requires-Python: >=3.8.1
|
|
25
|
+
Requires-Dist: httpx>=0.25.0
|
|
26
|
+
Requires-Dist: pydantic>=2.0.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: black>=23.0.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: flake8>=6.0.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: isort>=5.12.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: mypy>=1.5.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: pre-commit>=3.0.0; extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
35
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# Python Zendesk SDK
|
|
39
|
+
|
|
40
|
+
Modern Python SDK for Zendesk API with async support, full type safety, and comprehensive error handling.
|
|
41
|
+
|
|
42
|
+
## Status: Ready for Read-Only Operations ✅
|
|
43
|
+
|
|
44
|
+
This project has completed iterations 1-4 and is ready for production use in read-only mode.
|
|
45
|
+
|
|
46
|
+
### Completed Features ✅
|
|
47
|
+
|
|
48
|
+
- **Project Infrastructure**: Complete setup with `pyproject.toml`, dependencies, and linting
|
|
49
|
+
- **Configuration System**: `ZendeskConfig` with environment variable support and validation
|
|
50
|
+
- **Exception Handling**: Comprehensive exception hierarchy for different error types
|
|
51
|
+
- **HTTP Client**: Async HTTP client with retry logic, rate limiting, and exponential backoff
|
|
52
|
+
- **Pagination**: Both offset-based and cursor-based pagination support
|
|
53
|
+
- **Data Models**: Full Pydantic v2 models for Users, Organizations, Tickets, and Comments
|
|
54
|
+
- **Read API Methods**: 13 methods for reading data from Zendesk
|
|
55
|
+
- Users: `get_users()`, `get_user()`, `get_user_by_email()`
|
|
56
|
+
- Organizations: `get_organizations()`, `get_organization()`
|
|
57
|
+
- Tickets: `get_tickets()`, `get_ticket()`, `get_user_tickets()`, `get_organization_tickets()`
|
|
58
|
+
- Comments: `get_ticket_comments()`
|
|
59
|
+
- Search: `search()`, `search_users()`, `search_tickets()`, `search_organizations()`
|
|
60
|
+
- **Testing Framework**: Full test suite with 128+ passing tests
|
|
61
|
+
- **Code Quality**: Black, isort, flake8, and mypy configured
|
|
62
|
+
|
|
63
|
+
### In Development 🚧
|
|
64
|
+
|
|
65
|
+
- Write operations (create/update/delete) - planned for future iteration
|
|
66
|
+
- Documentation & Examples (Iteration 5)
|
|
67
|
+
|
|
68
|
+
## Installation
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
# Install from PyPI (when published)
|
|
72
|
+
pip install python-zendesk-sdk
|
|
73
|
+
|
|
74
|
+
# Or install from source
|
|
75
|
+
git clone <repository-url>
|
|
76
|
+
cd python-zendesk-sdk
|
|
77
|
+
pip install -e ".[dev]"
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Quick Start
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
import asyncio
|
|
84
|
+
from zendesk_sdk import ZendeskClient, ZendeskConfig
|
|
85
|
+
|
|
86
|
+
async def main():
|
|
87
|
+
# Create configuration
|
|
88
|
+
config = ZendeskConfig(
|
|
89
|
+
subdomain="your-subdomain",
|
|
90
|
+
email="your-email@example.com",
|
|
91
|
+
token="your-api-token", # or use password="your-password"
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# Use async context manager
|
|
95
|
+
async with ZendeskClient(config) as client:
|
|
96
|
+
# Get users with pagination
|
|
97
|
+
users_paginator = await client.get_users(per_page=10)
|
|
98
|
+
users = await users_paginator.get_page()
|
|
99
|
+
|
|
100
|
+
for user in users:
|
|
101
|
+
print(f"User: {user.name} ({user.email})")
|
|
102
|
+
|
|
103
|
+
# Get specific ticket
|
|
104
|
+
ticket = await client.get_ticket(ticket_id=12345)
|
|
105
|
+
print(f"Ticket: {ticket.subject}")
|
|
106
|
+
|
|
107
|
+
# Search tickets
|
|
108
|
+
results = await client.search_tickets("status:open priority:high")
|
|
109
|
+
for ticket in results:
|
|
110
|
+
print(f"High priority: {ticket.subject}")
|
|
111
|
+
|
|
112
|
+
asyncio.run(main())
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Configuration
|
|
116
|
+
|
|
117
|
+
The SDK supports multiple ways to configure authentication:
|
|
118
|
+
|
|
119
|
+
### 1. Direct instantiation
|
|
120
|
+
```python
|
|
121
|
+
config = ZendeskConfig(
|
|
122
|
+
subdomain="mycompany",
|
|
123
|
+
email="user@example.com",
|
|
124
|
+
token="api_token_here"
|
|
125
|
+
)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### 2. Environment variables
|
|
129
|
+
```bash
|
|
130
|
+
export ZENDESK_SUBDOMAIN=mycompany
|
|
131
|
+
export ZENDESK_EMAIL=user@example.com
|
|
132
|
+
export ZENDESK_TOKEN=api_token_here
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
config = ZendeskConfig() # Will load from environment
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 3. Mixed approach
|
|
140
|
+
```python
|
|
141
|
+
# Override specific values, rest from environment
|
|
142
|
+
config = ZendeskConfig(subdomain="different-subdomain")
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Development
|
|
146
|
+
|
|
147
|
+
### Running Tests
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# Run all tests
|
|
151
|
+
pytest
|
|
152
|
+
|
|
153
|
+
# Run with coverage
|
|
154
|
+
pytest --cov=src/zendesk_sdk --cov-report=html
|
|
155
|
+
|
|
156
|
+
# Run specific test file
|
|
157
|
+
pytest tests/test_config.py -v
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Code Quality
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
# Format code
|
|
164
|
+
python -m black src tests
|
|
165
|
+
python -m isort src tests
|
|
166
|
+
|
|
167
|
+
# Lint code
|
|
168
|
+
python -m flake8 src tests
|
|
169
|
+
|
|
170
|
+
# Type checking
|
|
171
|
+
python -m mypy src
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Running All Checks
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
# Format, lint, and test
|
|
178
|
+
python -m black src tests && python -m isort src tests && python -m flake8 src tests && python -m mypy src && pytest
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Project Structure
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
├── src/zendesk_sdk/ # Main package
|
|
185
|
+
│ ├── __init__.py # Public API exports
|
|
186
|
+
│ ├── client.py # Main ZendeskClient class
|
|
187
|
+
│ ├── config.py # Configuration management
|
|
188
|
+
│ ├── exceptions.py # Exception hierarchy
|
|
189
|
+
│ └── models/ # Data models
|
|
190
|
+
│ ├── __init__.py
|
|
191
|
+
│ └── base.py # Base model class
|
|
192
|
+
├── tests/ # Test suite
|
|
193
|
+
├── pyproject.toml # Project configuration
|
|
194
|
+
└── README.md # This file
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Requirements
|
|
198
|
+
|
|
199
|
+
- Python 3.8+
|
|
200
|
+
- httpx (for async HTTP client)
|
|
201
|
+
- pydantic >=2.0 (for data validation)
|
|
202
|
+
|
|
203
|
+
## Development Roadmap
|
|
204
|
+
|
|
205
|
+
- [x] **Iteration 1**: Infrastructure Setup
|
|
206
|
+
- [x] **Iteration 2**: HTTP Client & Pagination
|
|
207
|
+
- [x] **Iteration 3**: Data Models (Users, Tickets, Organizations, Comments)
|
|
208
|
+
- [x] **Iteration 4**: Read-Only API Methods & Search
|
|
209
|
+
- [ ] **Iteration 5**: Documentation & Examples (in progress)
|
|
210
|
+
- [ ] **Future**: Write operations (create/update/delete)
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
MIT License - see LICENSE file for details.
|
|
215
|
+
|
|
216
|
+
## Contributing
|
|
217
|
+
|
|
218
|
+
This project is currently in early development. Contribution guidelines will be added in future iterations.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
zendesk_sdk/__init__.py,sha256=xxTf8ePsDZwIlHs_obXSXOnvu9m8kz60SaBR9ElIzJQ,641
|
|
2
|
+
zendesk_sdk/client.py,sha256=n4xAexkX_VDXJ1x7VkO7L-3pdBNB5OJIb_i5D7hq3oE,10432
|
|
3
|
+
zendesk_sdk/config.py,sha256=2GT0LcW6u3oALy9gMhJ1_fk2l_p1PJgitGij-13YmOY,3833
|
|
4
|
+
zendesk_sdk/exceptions.py,sha256=ByzdL68EQZaP6BY5ukWfr8Myhr11PpEm4Xy0FgBwHJ4,5672
|
|
5
|
+
zendesk_sdk/http_client.py,sha256=n41KJ0fCYLGbCkEw1uNLmD7XpHweNxwdSSXR9Q0ehnk,9696
|
|
6
|
+
zendesk_sdk/pagination.py,sha256=9bm7x0-N0gM-Y0FjPGK6szxwsRZOdKQzxb4Ii68BMhs,10815
|
|
7
|
+
zendesk_sdk/models/__init__.py,sha256=xxRGGZgyelMKHK53lSyFWiqmrxDTk8OSPa_eWH8zbQM,894
|
|
8
|
+
zendesk_sdk/models/base.py,sha256=SMLcNW2lHOpuOn0DUB3CPQ7lIjPGtcwA85cC604iIMI,1686
|
|
9
|
+
zendesk_sdk/models/comment.py,sha256=us1vaH7bRYET3ChoJdUhbKXJfwb0jjqLC3t2h-PUwtE,3474
|
|
10
|
+
zendesk_sdk/models/organization.py,sha256=fZL3Sg4pOo3k6CynbqcVFT2jZKLG0BPyplnb4tpuovw,3970
|
|
11
|
+
zendesk_sdk/models/ticket.py,sha256=okCBCghhFhDCOtDAXa5q-cM3w8aI61fEY8NgHt1fD3c,11496
|
|
12
|
+
zendesk_sdk/models/user.py,sha256=jUxorGLVFb1dizFH167H7Q3S_PAkuh6z-Lh2i25beoM,7694
|
|
13
|
+
python_zendesk_sdk-0.1.0.dist-info/METADATA,sha256=AxjvMwXNwxzO3uz9bxx41ErBClbC5u59GnlPw-Ez948,6624
|
|
14
|
+
python_zendesk_sdk-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
15
|
+
python_zendesk_sdk-0.1.0.dist-info/licenses/LICENSE,sha256=JwtuUB9xpnmbUUkeC96rIL5z7MOicj9zULISh1-_1Dg,1063
|
|
16
|
+
python_zendesk_sdk-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 bormog
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
zendesk_sdk/__init__.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Modern Python SDK for Zendesk API.
|
|
3
|
+
|
|
4
|
+
This package provides a clean, async-first interface to the Zendesk API
|
|
5
|
+
with full type safety and comprehensive error handling.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
__version__ = "0.1.0"
|
|
9
|
+
|
|
10
|
+
from .client import ZendeskClient
|
|
11
|
+
from .config import ZendeskConfig
|
|
12
|
+
from .exceptions import (
|
|
13
|
+
ZendeskAuthException,
|
|
14
|
+
ZendeskBaseException,
|
|
15
|
+
ZendeskHTTPException,
|
|
16
|
+
ZendeskPaginationException,
|
|
17
|
+
ZendeskRateLimitException,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"ZendeskClient",
|
|
22
|
+
"ZendeskConfig",
|
|
23
|
+
"ZendeskBaseException",
|
|
24
|
+
"ZendeskHTTPException",
|
|
25
|
+
"ZendeskAuthException",
|
|
26
|
+
"ZendeskRateLimitException",
|
|
27
|
+
"ZendeskPaginationException",
|
|
28
|
+
]
|
zendesk_sdk/client.py
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"""Main Zendesk API client."""
|
|
2
|
+
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
|
4
|
+
|
|
5
|
+
from .config import ZendeskConfig
|
|
6
|
+
from .http_client import HTTPClient
|
|
7
|
+
from .models import Comment, Organization, Ticket, User
|
|
8
|
+
from .pagination import ZendeskPaginator
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from .pagination import Paginator
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class ZendeskClient:
|
|
15
|
+
"""Main client for interacting with the Zendesk API.
|
|
16
|
+
|
|
17
|
+
This client provides a unified interface to all Zendesk API resources
|
|
18
|
+
including users, tickets, organizations, and search functionality.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def __init__(self, config: ZendeskConfig) -> None:
|
|
22
|
+
"""Initialize the Zendesk client.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
config: Zendesk configuration object containing authentication
|
|
26
|
+
and connection settings.
|
|
27
|
+
"""
|
|
28
|
+
self.config = config
|
|
29
|
+
self._http_client: Optional[HTTPClient] = None
|
|
30
|
+
|
|
31
|
+
def __repr__(self) -> str:
|
|
32
|
+
"""String representation of the client."""
|
|
33
|
+
return f"ZendeskClient(subdomain='{self.config.subdomain}')"
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def http_client(self) -> HTTPClient:
|
|
37
|
+
"""Get or create HTTP client instance."""
|
|
38
|
+
if self._http_client is None:
|
|
39
|
+
self._http_client = HTTPClient(self.config)
|
|
40
|
+
return self._http_client
|
|
41
|
+
|
|
42
|
+
async def get(
|
|
43
|
+
self,
|
|
44
|
+
path: str,
|
|
45
|
+
*,
|
|
46
|
+
params: Optional[Dict[str, Any]] = None,
|
|
47
|
+
max_retries: Optional[int] = None,
|
|
48
|
+
) -> Dict[str, Any]:
|
|
49
|
+
"""Make GET request to Zendesk API.
|
|
50
|
+
|
|
51
|
+
Args:
|
|
52
|
+
path: API endpoint path (e.g., 'users.json')
|
|
53
|
+
params: Query parameters
|
|
54
|
+
max_retries: Override default retry count
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
JSON response from API
|
|
58
|
+
"""
|
|
59
|
+
return await self.http_client.get(path, params=params, max_retries=max_retries)
|
|
60
|
+
|
|
61
|
+
async def post(
|
|
62
|
+
self,
|
|
63
|
+
path: str,
|
|
64
|
+
*,
|
|
65
|
+
json: Optional[Dict[str, Any]] = None,
|
|
66
|
+
max_retries: Optional[int] = None,
|
|
67
|
+
) -> Dict[str, Any]:
|
|
68
|
+
"""Make POST request to Zendesk API.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
path: API endpoint path (e.g., 'users.json')
|
|
72
|
+
json: Request body data
|
|
73
|
+
max_retries: Override default retry count
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
JSON response from API
|
|
77
|
+
"""
|
|
78
|
+
return await self.http_client.post(path, json=json, max_retries=max_retries)
|
|
79
|
+
|
|
80
|
+
async def put(
|
|
81
|
+
self,
|
|
82
|
+
path: str,
|
|
83
|
+
*,
|
|
84
|
+
json: Optional[Dict[str, Any]] = None,
|
|
85
|
+
max_retries: Optional[int] = None,
|
|
86
|
+
) -> Dict[str, Any]:
|
|
87
|
+
"""Make PUT request to Zendesk API.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
path: API endpoint path (e.g., 'users/123.json')
|
|
91
|
+
json: Request body data
|
|
92
|
+
max_retries: Override default retry count
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
JSON response from API
|
|
96
|
+
"""
|
|
97
|
+
return await self.http_client.put(path, json=json, max_retries=max_retries)
|
|
98
|
+
|
|
99
|
+
async def delete(
|
|
100
|
+
self,
|
|
101
|
+
path: str,
|
|
102
|
+
*,
|
|
103
|
+
max_retries: Optional[int] = None,
|
|
104
|
+
) -> Optional[Dict[str, Any]]:
|
|
105
|
+
"""Make DELETE request to Zendesk API.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
path: API endpoint path (e.g., 'users/123.json')
|
|
109
|
+
max_retries: Override default retry count
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
JSON response from API if any, None for empty responses
|
|
113
|
+
"""
|
|
114
|
+
return await self.http_client.delete(path, max_retries=max_retries)
|
|
115
|
+
|
|
116
|
+
async def close(self) -> None:
|
|
117
|
+
"""Close HTTP client and cleanup resources."""
|
|
118
|
+
if self._http_client:
|
|
119
|
+
await self._http_client.close()
|
|
120
|
+
|
|
121
|
+
async def __aenter__(self) -> "ZendeskClient":
|
|
122
|
+
"""Async context manager entry."""
|
|
123
|
+
return self
|
|
124
|
+
|
|
125
|
+
async def __aexit__(self, exc_type, exc_val, exc_tb) -> None: # type: ignore[no-untyped-def]
|
|
126
|
+
"""Async context manager exit."""
|
|
127
|
+
await self.close()
|
|
128
|
+
|
|
129
|
+
# Users API methods
|
|
130
|
+
|
|
131
|
+
async def get_users(self, per_page: int = 100) -> "Paginator[Dict[str, Any]]":
|
|
132
|
+
"""Get paginated list of users.
|
|
133
|
+
|
|
134
|
+
Args:
|
|
135
|
+
per_page: Number of users per page (max 100)
|
|
136
|
+
|
|
137
|
+
Returns:
|
|
138
|
+
Paginator for iterating through all users
|
|
139
|
+
"""
|
|
140
|
+
paginator = ZendeskPaginator.create_users_paginator(self.http_client, per_page=per_page)
|
|
141
|
+
return paginator
|
|
142
|
+
|
|
143
|
+
async def get_user(self, user_id: int) -> User:
|
|
144
|
+
"""Get a specific user by ID.
|
|
145
|
+
|
|
146
|
+
Args:
|
|
147
|
+
user_id: The user's ID
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
User object
|
|
151
|
+
"""
|
|
152
|
+
response = await self.get(f"users/{user_id}.json")
|
|
153
|
+
return User(**response["user"])
|
|
154
|
+
|
|
155
|
+
async def get_user_by_email(self, email: str) -> Optional[User]:
|
|
156
|
+
"""Get a user by email address.
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
email: The user's email address
|
|
160
|
+
|
|
161
|
+
Returns:
|
|
162
|
+
User object if found, None otherwise
|
|
163
|
+
"""
|
|
164
|
+
response = await self.get("users/search.json", params={"query": email})
|
|
165
|
+
users = response.get("users", [])
|
|
166
|
+
if users:
|
|
167
|
+
return User(**users[0])
|
|
168
|
+
return None
|
|
169
|
+
|
|
170
|
+
# Organizations API methods
|
|
171
|
+
|
|
172
|
+
async def get_organizations(self, per_page: int = 100) -> "Paginator[Dict[str, Any]]":
|
|
173
|
+
"""Get paginated list of organizations.
|
|
174
|
+
|
|
175
|
+
Args:
|
|
176
|
+
per_page: Number of organizations per page (max 100)
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
Paginator for iterating through all organizations
|
|
180
|
+
"""
|
|
181
|
+
paginator = ZendeskPaginator.create_organizations_paginator(self.http_client, per_page=per_page)
|
|
182
|
+
return paginator
|
|
183
|
+
|
|
184
|
+
async def get_organization(self, org_id: int) -> Organization:
|
|
185
|
+
"""Get a specific organization by ID.
|
|
186
|
+
|
|
187
|
+
Args:
|
|
188
|
+
org_id: The organization's ID
|
|
189
|
+
|
|
190
|
+
Returns:
|
|
191
|
+
Organization object
|
|
192
|
+
"""
|
|
193
|
+
response = await self.get(f"organizations/{org_id}.json")
|
|
194
|
+
return Organization(**response["organization"])
|
|
195
|
+
|
|
196
|
+
# Tickets API methods
|
|
197
|
+
|
|
198
|
+
async def get_tickets(self, per_page: int = 100) -> "Paginator[Dict[str, Any]]":
|
|
199
|
+
"""Get paginated list of tickets.
|
|
200
|
+
|
|
201
|
+
Args:
|
|
202
|
+
per_page: Number of tickets per page (max 100)
|
|
203
|
+
|
|
204
|
+
Returns:
|
|
205
|
+
Paginator for iterating through all tickets
|
|
206
|
+
"""
|
|
207
|
+
paginator = ZendeskPaginator.create_tickets_paginator(self.http_client, per_page=per_page)
|
|
208
|
+
return paginator
|
|
209
|
+
|
|
210
|
+
async def get_ticket(self, ticket_id: int) -> Ticket:
|
|
211
|
+
"""Get a specific ticket by ID.
|
|
212
|
+
|
|
213
|
+
Args:
|
|
214
|
+
ticket_id: The ticket's ID
|
|
215
|
+
|
|
216
|
+
Returns:
|
|
217
|
+
Ticket object
|
|
218
|
+
"""
|
|
219
|
+
response = await self.get(f"tickets/{ticket_id}.json")
|
|
220
|
+
return Ticket(**response["ticket"])
|
|
221
|
+
|
|
222
|
+
async def get_user_tickets(self, user_id: int, per_page: int = 100) -> List[Ticket]:
|
|
223
|
+
"""Get tickets requested by a specific user.
|
|
224
|
+
|
|
225
|
+
Args:
|
|
226
|
+
user_id: The user's ID
|
|
227
|
+
per_page: Number of tickets per page (max 100)
|
|
228
|
+
|
|
229
|
+
Returns:
|
|
230
|
+
List of Ticket objects
|
|
231
|
+
"""
|
|
232
|
+
response = await self.get(f"users/{user_id}/tickets/requested.json", params={"per_page": per_page})
|
|
233
|
+
return [Ticket(**ticket_data) for ticket_data in response.get("tickets", [])]
|
|
234
|
+
|
|
235
|
+
async def get_organization_tickets(self, org_id: int, per_page: int = 100) -> List[Ticket]:
|
|
236
|
+
"""Get tickets for a specific organization.
|
|
237
|
+
|
|
238
|
+
Args:
|
|
239
|
+
org_id: The organization's ID
|
|
240
|
+
per_page: Number of tickets per page (max 100)
|
|
241
|
+
|
|
242
|
+
Returns:
|
|
243
|
+
List of Ticket objects
|
|
244
|
+
"""
|
|
245
|
+
response = await self.get(f"organizations/{org_id}/tickets.json", params={"per_page": per_page})
|
|
246
|
+
return [Ticket(**ticket_data) for ticket_data in response.get("tickets", [])]
|
|
247
|
+
|
|
248
|
+
# Comments API methods
|
|
249
|
+
|
|
250
|
+
async def get_ticket_comments(self, ticket_id: int, per_page: int = 100) -> List[Comment]:
|
|
251
|
+
"""Get comments for a specific ticket.
|
|
252
|
+
|
|
253
|
+
Args:
|
|
254
|
+
ticket_id: The ticket's ID
|
|
255
|
+
per_page: Number of comments per page (max 100)
|
|
256
|
+
|
|
257
|
+
Returns:
|
|
258
|
+
List of Comment objects
|
|
259
|
+
"""
|
|
260
|
+
response = await self.get(f"tickets/{ticket_id}/comments.json", params={"per_page": per_page})
|
|
261
|
+
return [Comment(**comment_data) for comment_data in response.get("comments", [])]
|
|
262
|
+
|
|
263
|
+
# Search API methods
|
|
264
|
+
|
|
265
|
+
async def search(self, query: str, per_page: int = 100) -> "Paginator[Dict[str, Any]]":
|
|
266
|
+
"""Search across all Zendesk resources.
|
|
267
|
+
|
|
268
|
+
Args:
|
|
269
|
+
query: Search query string
|
|
270
|
+
per_page: Number of results per page (max 100)
|
|
271
|
+
|
|
272
|
+
Returns:
|
|
273
|
+
Paginator for iterating through search results
|
|
274
|
+
"""
|
|
275
|
+
paginator = ZendeskPaginator.create_search_paginator(self.http_client, query=query, per_page=per_page)
|
|
276
|
+
return paginator
|
|
277
|
+
|
|
278
|
+
async def search_users(self, query: str, per_page: int = 100) -> List[User]:
|
|
279
|
+
"""Search for users.
|
|
280
|
+
|
|
281
|
+
Args:
|
|
282
|
+
query: Search query string
|
|
283
|
+
per_page: Number of results per page (max 100)
|
|
284
|
+
|
|
285
|
+
Returns:
|
|
286
|
+
List of User objects
|
|
287
|
+
"""
|
|
288
|
+
full_query = f"type:user {query}"
|
|
289
|
+
response = await self.get("search.json", params={"query": full_query, "per_page": per_page})
|
|
290
|
+
results = response.get("results", [])
|
|
291
|
+
return [User(**result) for result in results if result.get("result_type") == "user"]
|
|
292
|
+
|
|
293
|
+
async def search_tickets(self, query: str, per_page: int = 100) -> List[Ticket]:
|
|
294
|
+
"""Search for tickets.
|
|
295
|
+
|
|
296
|
+
Args:
|
|
297
|
+
query: Search query string
|
|
298
|
+
per_page: Number of results per page (max 100)
|
|
299
|
+
|
|
300
|
+
Returns:
|
|
301
|
+
List of Ticket objects
|
|
302
|
+
"""
|
|
303
|
+
full_query = f"type:ticket {query}"
|
|
304
|
+
response = await self.get("search.json", params={"query": full_query, "per_page": per_page})
|
|
305
|
+
results = response.get("results", [])
|
|
306
|
+
return [Ticket(**result) for result in results if result.get("result_type") == "ticket"]
|
|
307
|
+
|
|
308
|
+
async def search_organizations(self, query: str, per_page: int = 100) -> List[Organization]:
|
|
309
|
+
"""Search for organizations.
|
|
310
|
+
|
|
311
|
+
Args:
|
|
312
|
+
query: Search query string
|
|
313
|
+
per_page: Number of results per page (max 100)
|
|
314
|
+
|
|
315
|
+
Returns:
|
|
316
|
+
List of Organization objects
|
|
317
|
+
"""
|
|
318
|
+
full_query = f"type:organization {query}"
|
|
319
|
+
response = await self.get("search.json", params={"query": full_query, "per_page": per_page})
|
|
320
|
+
results = response.get("results", [])
|
|
321
|
+
return [Organization(**result) for result in results if result.get("result_type") == "organization"]
|