gitcode-api 1.2.21__py3-none-any.whl → 1.3.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.
- gitcode_api/__init__.py +8 -2
- gitcode_api/_exceptions.py +2 -0
- gitcode_api/exceptions.py +19 -0
- gitcode_api/llm/mcp.py +5 -5
- gitcode_api/models.py +205 -0
- gitcode_api/resources/__init__.py +1 -1
- gitcode_api/resources/_shared/__init__.py +18 -0
- gitcode_api/resources/_shared/base.py +129 -0
- gitcode_api/resources/{_shared.py → _shared/fetch_template.py} +133 -259
- gitcode_api/resources/account/__init__.py +17 -0
- gitcode_api/resources/account/oauth_resource_group.py +159 -0
- gitcode_api/resources/account/orgs_resource_group.py +422 -0
- gitcode_api/resources/account/search_resource_group.py +236 -0
- gitcode_api/resources/account/users_resource_group.py +249 -0
- gitcode_api/resources/collaboration/__init__.py +20 -0
- gitcode_api/resources/collaboration/_helpers.py +10 -0
- gitcode_api/resources/collaboration/issues_resource_group.py +855 -0
- gitcode_api/resources/collaboration/labels_resource_group.py +248 -0
- gitcode_api/resources/collaboration/members_resource_group.py +195 -0
- gitcode_api/resources/collaboration/milestones_resource_group.py +192 -0
- gitcode_api/resources/collaboration/pulls_resource_group.py +1300 -0
- gitcode_api/resources/misc/__init__.py +14 -0
- gitcode_api/resources/misc/releases_resource_group.py +445 -0
- gitcode_api/resources/misc/tags_resource_group.py +286 -0
- gitcode_api/resources/misc/webhooks_resource_group.py +192 -0
- gitcode_api/resources/repositories/__init__.py +17 -0
- gitcode_api/resources/repositories/branches_resource_group.py +151 -0
- gitcode_api/resources/repositories/commits_resource_group.py +333 -0
- gitcode_api/resources/repositories/repo_contents_resource_group.py +459 -0
- gitcode_api/resources/repositories/repos_resource_group.py +1279 -0
- gitcode_api/version.txt +1 -1
- {gitcode_api-1.2.21.dist-info → gitcode_api-1.3.0.dist-info}/METADATA +3 -3
- gitcode_api-1.3.0.dist-info/RECORD +52 -0
- gitcode_api/resources/account.py +0 -1086
- gitcode_api/resources/collaboration.py +0 -2818
- gitcode_api/resources/misc.py +0 -901
- gitcode_api/resources/repositories.py +0 -2197
- gitcode_api-1.2.21.dist-info/RECORD +0 -31
- {gitcode_api-1.2.21.dist-info → gitcode_api-1.3.0.dist-info}/WHEEL +0 -0
- {gitcode_api-1.2.21.dist-info → gitcode_api-1.3.0.dist-info}/entry_points.txt +0 -0
- {gitcode_api-1.2.21.dist-info → gitcode_api-1.3.0.dist-info}/licenses/LICENSE +0 -0
- {gitcode_api-1.2.21.dist-info → gitcode_api-1.3.0.dist-info}/top_level.txt +0 -0
gitcode_api/__init__.py
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""GitCode API — Python clients for interactions with GitCode REST API."""
|
|
2
2
|
|
|
3
3
|
import re
|
|
4
4
|
from importlib.metadata import PackageNotFoundError, metadata, version
|
|
5
5
|
from typing import cast
|
|
6
6
|
|
|
7
|
-
from . import constants
|
|
7
|
+
from . import constants, exceptions, models
|
|
8
8
|
from ._client import AsyncGitCode, GitCode
|
|
9
9
|
from ._exceptions import (
|
|
10
10
|
GitCodeAPIError,
|
|
11
11
|
GitCodeConfigurationError,
|
|
12
12
|
GitCodeError,
|
|
13
13
|
GitCodeHTTPStatusError,
|
|
14
|
+
GitCodeTokenError,
|
|
15
|
+
GitCodeUnauthorizedError,
|
|
14
16
|
)
|
|
15
17
|
from .utils import as_dict
|
|
16
18
|
|
|
@@ -43,6 +45,8 @@ __version__ = _VERSION_STR.strip()
|
|
|
43
45
|
|
|
44
46
|
__all__ = [
|
|
45
47
|
"constants",
|
|
48
|
+
"exceptions",
|
|
49
|
+
"models",
|
|
46
50
|
"__version__",
|
|
47
51
|
"__build_hash__",
|
|
48
52
|
"AsyncGitCode",
|
|
@@ -51,5 +55,7 @@ __all__ = [
|
|
|
51
55
|
"GitCodeConfigurationError",
|
|
52
56
|
"GitCodeError",
|
|
53
57
|
"GitCodeHTTPStatusError",
|
|
58
|
+
"GitCodeTokenError",
|
|
59
|
+
"GitCodeUnauthorizedError",
|
|
54
60
|
"as_dict",
|
|
55
61
|
]
|
gitcode_api/_exceptions.py
CHANGED
|
@@ -38,8 +38,10 @@ class GitCodeAPIError(GitCodeError):
|
|
|
38
38
|
class GitCodeHTTPStatusError(GitCodeAPIError):
|
|
39
39
|
"""Raised for non-success HTTP responses from the GitCode API."""
|
|
40
40
|
|
|
41
|
+
|
|
41
42
|
class GitCodeUnauthorizedError(GitCodeHTTPStatusError):
|
|
42
43
|
"""Raised for 401 unauthorized HTTP responses from the GitCode API."""
|
|
43
44
|
|
|
45
|
+
|
|
44
46
|
class GitCodeTokenError(GitCodeUnauthorizedError):
|
|
45
47
|
"""Raised for invalid token from the GitCode API."""
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Exception classes for the GitCode SDK."""
|
|
2
|
+
|
|
3
|
+
from gitcode_api._exceptions import (
|
|
4
|
+
GitCodeAPIError,
|
|
5
|
+
GitCodeConfigurationError,
|
|
6
|
+
GitCodeError,
|
|
7
|
+
GitCodeHTTPStatusError,
|
|
8
|
+
GitCodeTokenError,
|
|
9
|
+
GitCodeUnauthorizedError,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"GitCodeAPIError",
|
|
14
|
+
"GitCodeConfigurationError",
|
|
15
|
+
"GitCodeError",
|
|
16
|
+
"GitCodeHTTPStatusError",
|
|
17
|
+
"GitCodeTokenError",
|
|
18
|
+
"GitCodeUnauthorizedError",
|
|
19
|
+
]
|
gitcode_api/llm/mcp.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""FastMCP integration for the GitCode LLM tool."""
|
|
2
2
|
|
|
3
|
-
from typing import TYPE_CHECKING, Any, Callable, Optional, Union
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Callable, Optional, Union, cast
|
|
4
4
|
|
|
5
5
|
from ._tool import (
|
|
6
6
|
MCP_SERVER_INSTRUCTIONS,
|
|
@@ -25,8 +25,8 @@ def _missing_fastmcp_error() -> ImportError:
|
|
|
25
25
|
|
|
26
26
|
def _load_fastmcp() -> tuple["type[FastMCP]", Callable[..., "Tool"]]:
|
|
27
27
|
try:
|
|
28
|
-
from fastmcp import FastMCP
|
|
29
|
-
from fastmcp.tools import tool as fastmcp_tool
|
|
28
|
+
from fastmcp import FastMCP # pylint: disable=import-outside-toplevel
|
|
29
|
+
from fastmcp.tools import tool as fastmcp_tool # pylint: disable=import-outside-toplevel
|
|
30
30
|
except ImportError as exc:
|
|
31
31
|
raise _missing_fastmcp_error() from exc
|
|
32
32
|
return FastMCP, fastmcp_tool # type: ignore[return-value]
|
|
@@ -61,9 +61,9 @@ def register_mcp_gitcode_api_tool(mcp: Union["FastMCP", Any], tool: Optional[Git
|
|
|
61
61
|
callable_tool = create_mcp_gitcode_api_tool(tool)
|
|
62
62
|
if hasattr(mcp, "tool"):
|
|
63
63
|
try:
|
|
64
|
-
return mcp.tool(name=TOOL_NAME, description=TOOL_DESCRIPTION)(callable_tool)
|
|
64
|
+
return cast("Tool", mcp.tool(name=TOOL_NAME, description=TOOL_DESCRIPTION)(callable_tool))
|
|
65
65
|
except TypeError:
|
|
66
|
-
return mcp.tool()(callable_tool)
|
|
66
|
+
return cast("Tool", mcp.tool()(callable_tool))
|
|
67
67
|
if hasattr(mcp, "add_tool"):
|
|
68
68
|
_, fastmcp_tool = _load_fastmcp()
|
|
69
69
|
mcp_tool = fastmcp_tool(callable_tool, name=TOOL_NAME, description=TOOL_DESCRIPTION)
|
gitcode_api/models.py
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"""Response models for the GitCode SDK."""
|
|
2
|
+
|
|
3
|
+
from gitcode_api._models import (
|
|
4
|
+
APIObject,
|
|
5
|
+
ApiStatusResponse,
|
|
6
|
+
Blob,
|
|
7
|
+
Branch,
|
|
8
|
+
BranchDetail,
|
|
9
|
+
BranchDetailCommit,
|
|
10
|
+
BranchListCommit,
|
|
11
|
+
Commit,
|
|
12
|
+
CommitAuthorSummary,
|
|
13
|
+
CommitComment,
|
|
14
|
+
CommitComparison,
|
|
15
|
+
CommitFile,
|
|
16
|
+
CommitIdentity,
|
|
17
|
+
CommitParent,
|
|
18
|
+
CommitPayload,
|
|
19
|
+
CommitResult,
|
|
20
|
+
CommitStats,
|
|
21
|
+
CommitSummary,
|
|
22
|
+
CommitTreeRef,
|
|
23
|
+
ContentLinks,
|
|
24
|
+
ContentObject,
|
|
25
|
+
ContentWriteCommit,
|
|
26
|
+
Contributor,
|
|
27
|
+
ContributorStatistics,
|
|
28
|
+
ContributorStatisticsEntry,
|
|
29
|
+
ContributorStatisticsOverview,
|
|
30
|
+
Email,
|
|
31
|
+
EmptyResponse,
|
|
32
|
+
EnterpriseMember,
|
|
33
|
+
EnterpriseRef,
|
|
34
|
+
Issue,
|
|
35
|
+
IssueComment,
|
|
36
|
+
IssueOperationLog,
|
|
37
|
+
Label,
|
|
38
|
+
MergeResult,
|
|
39
|
+
MergeStatus,
|
|
40
|
+
Milestone,
|
|
41
|
+
Namespace,
|
|
42
|
+
NamespaceDetails,
|
|
43
|
+
OAuthToken,
|
|
44
|
+
Organization,
|
|
45
|
+
OrganizationMembership,
|
|
46
|
+
OrganizationSummary,
|
|
47
|
+
ProtectedBranch,
|
|
48
|
+
ProtectedTag,
|
|
49
|
+
PublicKey,
|
|
50
|
+
PullRequest,
|
|
51
|
+
PullRequestApprover,
|
|
52
|
+
PullRequestAssigneeCount,
|
|
53
|
+
PullRequestBranch,
|
|
54
|
+
PullRequestComment,
|
|
55
|
+
PullRequestCount,
|
|
56
|
+
PullRequestDiffRefs,
|
|
57
|
+
PullRequestFile,
|
|
58
|
+
PullRequestOperationLog,
|
|
59
|
+
PullRequestReview,
|
|
60
|
+
PullRequestSettingDetail,
|
|
61
|
+
PullRequestSettings,
|
|
62
|
+
PullRequestTest,
|
|
63
|
+
PullRequestTimeStats,
|
|
64
|
+
Release,
|
|
65
|
+
ReleaseAsset,
|
|
66
|
+
ReleaseUploadURL,
|
|
67
|
+
RepoCollaborator,
|
|
68
|
+
RepoMember,
|
|
69
|
+
RepoMemberPermission,
|
|
70
|
+
RepoMemberPermissions,
|
|
71
|
+
Repository,
|
|
72
|
+
RepositoryCollaboratorCheck,
|
|
73
|
+
RepositoryCustomizedRole,
|
|
74
|
+
RepositoryDownloadStatistics,
|
|
75
|
+
RepositoryDownloadStatisticsDetail,
|
|
76
|
+
RepositoryGitCodeTemplate,
|
|
77
|
+
RepositoryPermission,
|
|
78
|
+
RepositoryPermissionMode,
|
|
79
|
+
RepositoryPushConfig,
|
|
80
|
+
RepositoryReviewerSettingsUpdate,
|
|
81
|
+
RepositorySettings,
|
|
82
|
+
RepositorySummary,
|
|
83
|
+
RepositoryTransferResult,
|
|
84
|
+
RepositoryUploadResult,
|
|
85
|
+
SearchIssue,
|
|
86
|
+
SearchRepository,
|
|
87
|
+
SearchResult,
|
|
88
|
+
SearchUser,
|
|
89
|
+
Tag,
|
|
90
|
+
TagCommit,
|
|
91
|
+
Tagger,
|
|
92
|
+
Tree,
|
|
93
|
+
TreeEntry,
|
|
94
|
+
User,
|
|
95
|
+
UserEvent,
|
|
96
|
+
UserEventLinks,
|
|
97
|
+
UserEventProject,
|
|
98
|
+
UserEventPushData,
|
|
99
|
+
UserEventsResponse,
|
|
100
|
+
UserRef,
|
|
101
|
+
UserSummary,
|
|
102
|
+
Webhook,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
__all__ = [
|
|
106
|
+
"APIObject",
|
|
107
|
+
"ApiStatusResponse",
|
|
108
|
+
"Blob",
|
|
109
|
+
"Branch",
|
|
110
|
+
"BranchDetail",
|
|
111
|
+
"BranchDetailCommit",
|
|
112
|
+
"BranchListCommit",
|
|
113
|
+
"Commit",
|
|
114
|
+
"CommitAuthorSummary",
|
|
115
|
+
"CommitComment",
|
|
116
|
+
"CommitComparison",
|
|
117
|
+
"CommitFile",
|
|
118
|
+
"CommitIdentity",
|
|
119
|
+
"CommitParent",
|
|
120
|
+
"CommitPayload",
|
|
121
|
+
"CommitResult",
|
|
122
|
+
"CommitStats",
|
|
123
|
+
"CommitSummary",
|
|
124
|
+
"CommitTreeRef",
|
|
125
|
+
"ContentLinks",
|
|
126
|
+
"ContentObject",
|
|
127
|
+
"ContentWriteCommit",
|
|
128
|
+
"Contributor",
|
|
129
|
+
"ContributorStatistics",
|
|
130
|
+
"ContributorStatisticsEntry",
|
|
131
|
+
"ContributorStatisticsOverview",
|
|
132
|
+
"Email",
|
|
133
|
+
"EmptyResponse",
|
|
134
|
+
"EnterpriseMember",
|
|
135
|
+
"EnterpriseRef",
|
|
136
|
+
"Issue",
|
|
137
|
+
"IssueComment",
|
|
138
|
+
"IssueOperationLog",
|
|
139
|
+
"Label",
|
|
140
|
+
"MergeResult",
|
|
141
|
+
"MergeStatus",
|
|
142
|
+
"Milestone",
|
|
143
|
+
"Namespace",
|
|
144
|
+
"NamespaceDetails",
|
|
145
|
+
"OAuthToken",
|
|
146
|
+
"Organization",
|
|
147
|
+
"OrganizationMembership",
|
|
148
|
+
"OrganizationSummary",
|
|
149
|
+
"ProtectedBranch",
|
|
150
|
+
"ProtectedTag",
|
|
151
|
+
"PublicKey",
|
|
152
|
+
"PullRequest",
|
|
153
|
+
"PullRequestApprover",
|
|
154
|
+
"PullRequestAssigneeCount",
|
|
155
|
+
"PullRequestBranch",
|
|
156
|
+
"PullRequestComment",
|
|
157
|
+
"PullRequestCount",
|
|
158
|
+
"PullRequestDiffRefs",
|
|
159
|
+
"PullRequestFile",
|
|
160
|
+
"PullRequestOperationLog",
|
|
161
|
+
"PullRequestReview",
|
|
162
|
+
"PullRequestSettingDetail",
|
|
163
|
+
"PullRequestSettings",
|
|
164
|
+
"PullRequestTest",
|
|
165
|
+
"PullRequestTimeStats",
|
|
166
|
+
"Release",
|
|
167
|
+
"ReleaseAsset",
|
|
168
|
+
"ReleaseUploadURL",
|
|
169
|
+
"RepoCollaborator",
|
|
170
|
+
"RepoMember",
|
|
171
|
+
"RepoMemberPermission",
|
|
172
|
+
"RepoMemberPermissions",
|
|
173
|
+
"Repository",
|
|
174
|
+
"RepositoryCollaboratorCheck",
|
|
175
|
+
"RepositoryCustomizedRole",
|
|
176
|
+
"RepositoryDownloadStatistics",
|
|
177
|
+
"RepositoryDownloadStatisticsDetail",
|
|
178
|
+
"RepositoryGitCodeTemplate",
|
|
179
|
+
"RepositoryPermission",
|
|
180
|
+
"RepositoryPermissionMode",
|
|
181
|
+
"RepositoryPushConfig",
|
|
182
|
+
"RepositoryReviewerSettingsUpdate",
|
|
183
|
+
"RepositorySettings",
|
|
184
|
+
"RepositorySummary",
|
|
185
|
+
"RepositoryTransferResult",
|
|
186
|
+
"RepositoryUploadResult",
|
|
187
|
+
"SearchIssue",
|
|
188
|
+
"SearchRepository",
|
|
189
|
+
"SearchResult",
|
|
190
|
+
"SearchUser",
|
|
191
|
+
"Tag",
|
|
192
|
+
"TagCommit",
|
|
193
|
+
"Tagger",
|
|
194
|
+
"Tree",
|
|
195
|
+
"TreeEntry",
|
|
196
|
+
"User",
|
|
197
|
+
"UserEvent",
|
|
198
|
+
"UserEventLinks",
|
|
199
|
+
"UserEventProject",
|
|
200
|
+
"UserEventPushData",
|
|
201
|
+
"UserEventsResponse",
|
|
202
|
+
"UserRef",
|
|
203
|
+
"UserSummary",
|
|
204
|
+
"Webhook",
|
|
205
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Shared resource base classes and template helpers."""
|
|
2
|
+
|
|
3
|
+
from .base import AsyncResource, SyncResource
|
|
4
|
+
from .fetch_template import (
|
|
5
|
+
get_gitcode_template_body_async,
|
|
6
|
+
get_gitcode_template_body_sync,
|
|
7
|
+
list_gitcode_template_rows_async,
|
|
8
|
+
list_gitcode_template_rows_sync,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"AsyncResource",
|
|
13
|
+
"SyncResource",
|
|
14
|
+
"get_gitcode_template_body_sync",
|
|
15
|
+
"get_gitcode_template_body_async",
|
|
16
|
+
"list_gitcode_template_rows_sync",
|
|
17
|
+
"list_gitcode_template_rows_async",
|
|
18
|
+
]
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"""Synchronous and asynchronous resource base classes."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, List, Optional, Union
|
|
4
|
+
|
|
5
|
+
from ..._base_client import AsyncAPIClient, SyncAPIClient
|
|
6
|
+
from ..._base_resource import BaseResource
|
|
7
|
+
from ..._models import APIObject, ModelT, as_model, as_model_list
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SyncResource(BaseResource):
|
|
11
|
+
"""Base class for synchronous resource groups."""
|
|
12
|
+
|
|
13
|
+
def __init__(self, client: SyncAPIClient) -> None:
|
|
14
|
+
"""Bind the resource to a synchronous API client."""
|
|
15
|
+
self._client = client
|
|
16
|
+
|
|
17
|
+
def _request(
|
|
18
|
+
self,
|
|
19
|
+
method: str,
|
|
20
|
+
path: str,
|
|
21
|
+
*,
|
|
22
|
+
params: Optional[Dict[str, Any]] = None,
|
|
23
|
+
json: Any = None,
|
|
24
|
+
data: Optional[Dict[str, Any]] = None,
|
|
25
|
+
raw: bool = False,
|
|
26
|
+
) -> Any:
|
|
27
|
+
"""Dispatch a low-level request through the owning client.
|
|
28
|
+
|
|
29
|
+
:param method: HTTP verb (for example ``GET`` or ``POST``).
|
|
30
|
+
:param path: Absolute or root-relative URL path.
|
|
31
|
+
:param params: Optional query string parameters.
|
|
32
|
+
:param json: Optional JSON-serializable request body.
|
|
33
|
+
:param data: Optional form or body fields.
|
|
34
|
+
:param raw: When ``True``, return the raw response body (for example bytes).
|
|
35
|
+
:returns: Parsed JSON, raw body, or other value from the client.
|
|
36
|
+
"""
|
|
37
|
+
return self._client.request(method, path, params=params, json=json, data=data, raw=raw)
|
|
38
|
+
|
|
39
|
+
def _model(self, method: str, path: str, model_type: type[ModelT], **kwargs) -> ModelT:
|
|
40
|
+
"""Send a request and wrap a JSON object in ``model_type``.
|
|
41
|
+
|
|
42
|
+
:param method: HTTP verb.
|
|
43
|
+
:param path: Request path.
|
|
44
|
+
:param model_type: Model class for the top-level JSON object.
|
|
45
|
+
:param kwargs: Forwarded to :meth:`_request` (``params``, ``json``, ``data``, ``raw``, etc.).
|
|
46
|
+
:returns: An instance of ``model_type``.
|
|
47
|
+
"""
|
|
48
|
+
data = self._request(method, path, **kwargs)
|
|
49
|
+
return as_model(data, model_type)
|
|
50
|
+
|
|
51
|
+
def _models(self, method: str, path: str, model_type: type[ModelT], **kwargs) -> List[ModelT]:
|
|
52
|
+
"""Send a request and wrap a JSON array in ``model_type`` instances.
|
|
53
|
+
|
|
54
|
+
:param method: HTTP verb.
|
|
55
|
+
:param path: Request path.
|
|
56
|
+
:param model_type: Model class for each element of the JSON array.
|
|
57
|
+
:param kwargs: Forwarded to :meth:`_request`.
|
|
58
|
+
:returns: A list of ``model_type`` instances.
|
|
59
|
+
"""
|
|
60
|
+
data = self._request(method, path, **kwargs)
|
|
61
|
+
return as_model_list(data, model_type)
|
|
62
|
+
|
|
63
|
+
def _maybe_model(self, method: str, path: str, model_type: type[ModelT], **kwargs) -> Union[ModelT, APIObject]:
|
|
64
|
+
"""Wrap dict responses as models and scalar responses as ``APIObject``.
|
|
65
|
+
|
|
66
|
+
:param method: HTTP verb.
|
|
67
|
+
:param path: Request path.
|
|
68
|
+
:param model_type: Model class when the response is a JSON object.
|
|
69
|
+
:param kwargs: Forwarded to :meth:`_request`.
|
|
70
|
+
:returns: ``model_type`` for dict bodies; otherwise ``APIObject`` wrapping a ``value`` field.
|
|
71
|
+
"""
|
|
72
|
+
data = self._request(method, path, **kwargs)
|
|
73
|
+
if isinstance(data, dict):
|
|
74
|
+
return as_model(data, model_type)
|
|
75
|
+
return APIObject({"value": data})
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class AsyncResource(BaseResource):
|
|
79
|
+
"""Base class for asynchronous resource groups."""
|
|
80
|
+
|
|
81
|
+
def __init__(self, client: AsyncAPIClient) -> None:
|
|
82
|
+
"""Bind the resource to an asynchronous API client."""
|
|
83
|
+
self._client = client
|
|
84
|
+
|
|
85
|
+
async def _request(
|
|
86
|
+
self,
|
|
87
|
+
method: str,
|
|
88
|
+
path: str,
|
|
89
|
+
*,
|
|
90
|
+
params: Optional[Dict[str, Any]] = None,
|
|
91
|
+
json: Any = None,
|
|
92
|
+
data: Optional[Dict[str, Any]] = None,
|
|
93
|
+
raw: bool = False,
|
|
94
|
+
) -> Any:
|
|
95
|
+
"""Dispatch a low-level async request through the owning client.
|
|
96
|
+
|
|
97
|
+
:param method: HTTP verb (for example ``GET`` or ``POST``).
|
|
98
|
+
:param path: Absolute or root-relative URL path.
|
|
99
|
+
:param params: Optional query string parameters.
|
|
100
|
+
:param json: Optional JSON-serializable request body.
|
|
101
|
+
:param data: Optional form or body fields.
|
|
102
|
+
:param raw: When ``True``, return the raw response body (for example bytes).
|
|
103
|
+
:returns: Parsed JSON, raw body, or other value from the client.
|
|
104
|
+
"""
|
|
105
|
+
return await self._client.request(method, path, params=params, json=json, data=data, raw=raw)
|
|
106
|
+
|
|
107
|
+
async def _model(self, method: str, path: str, model_type: type[ModelT], **kwargs) -> ModelT:
|
|
108
|
+
"""Send a request and wrap a JSON object in ``model_type``.
|
|
109
|
+
|
|
110
|
+
:param method: HTTP verb.
|
|
111
|
+
:param path: Request path.
|
|
112
|
+
:param model_type: Model class for the top-level JSON object.
|
|
113
|
+
:param kwargs: Forwarded to :meth:`_request`.
|
|
114
|
+
:returns: An instance of ``model_type``.
|
|
115
|
+
"""
|
|
116
|
+
data = await self._request(method, path, **kwargs)
|
|
117
|
+
return as_model(data, model_type)
|
|
118
|
+
|
|
119
|
+
async def _models(self, method: str, path: str, model_type: type[ModelT], **kwargs) -> List[ModelT]:
|
|
120
|
+
"""Send a request and wrap a JSON array in ``model_type`` instances.
|
|
121
|
+
|
|
122
|
+
:param method: HTTP verb.
|
|
123
|
+
:param path: Request path.
|
|
124
|
+
:param model_type: Model class for each element of the JSON array.
|
|
125
|
+
:param kwargs: Forwarded to :meth:`_request`.
|
|
126
|
+
:returns: A list of ``model_type`` instances.
|
|
127
|
+
"""
|
|
128
|
+
data = await self._request(method, path, **kwargs)
|
|
129
|
+
return as_model_list(data, model_type)
|