-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathresource.py
More file actions
163 lines (127 loc) · 4.85 KB
/
resource.py
File metadata and controls
163 lines (127 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import warnings
from typing import Iterable, Optional
from crowdin_api.api_resources.abstract.resources import BaseResource
from crowdin_api.api_resources.distributions.enums import ExportMode
from crowdin_api.api_resources.distributions.types import DistributionPatchRequest
class DistributionsResource(BaseResource):
"""
Resource for Distributions.
Link to documentation:
https://developer.crowdin.com/api/v2/#tag/Distributions
"""
def get_distributions_path(self, projectId: int, hash: Optional[str] = None):
if hash:
return f"projects/{projectId}/distributions/{hash}"
return f"projects/{projectId}/distributions"
def list_distributions(
self,
projectId: Optional[int] = None,
offset: Optional[int] = None,
limit: Optional[int] = None,
):
"""
List Distributions.
Link to documentation:
https://developer.crowdin.com/api/v2/#operation/api.projects.distributions.getMany
"""
projectId = projectId or self.get_project_id()
return self._get_entire_data(
method="get",
path=self.get_distributions_path(projectId=projectId),
params=self.get_page_params(offset=offset, limit=limit),
)
def add_distribution(
self,
name: str,
projectId: Optional[int] = None,
fileIds: Optional[Iterable[int]] = None,
bundleIds: Optional[Iterable[int]] = None,
exportMode: Optional[ExportMode] = None,
):
"""
Add Distribution.
Link to documentation:
https://developer.crowdin.com/api/v2/#operation/api.projects.distributions.post
"""
projectId = projectId or self.get_project_id()
if exportMode is not None:
warnings.warn(
"`exportMode` is deprecated, omit this parameter to use the API default behavior",
DeprecationWarning,
)
if fileIds is not None:
warnings.warn(
"`fileIds` is deprecated, use `bundleIds` instead",
DeprecationWarning,
)
return self.requester.request(
method="post",
path=self.get_distributions_path(projectId=projectId),
request_data={
"exportMode": exportMode,
"name": name,
"fileIds": fileIds,
"bundleIds": bundleIds
},
)
def get_distribution(self, hash: str, projectId: Optional[int] = None):
"""
Get Distribution.
Link to documentation:
https://developer.crowdin.com/api/v2/#operation/api.projects.distributions.get
"""
projectId = projectId or self.get_project_id()
return self.requester.request(
method="get",
path=self.get_distributions_path(projectId=projectId, hash=hash),
)
def delete_distribution(self, hash: str, projectId: Optional[int] = None):
"""
Delete Distribution.
Link to documentation:
https://developer.crowdin.com/api/v2/#operation/api.projects.distributions.delete
"""
projectId = projectId or self.get_project_id()
return self.requester.request(
method="delete",
path=self.get_distributions_path(projectId=projectId, hash=hash),
)
def edit_distribution(
self,
hash: str,
data: Iterable[DistributionPatchRequest],
projectId: Optional[int] = None,
):
"""
Edit Distribution.
Link to documentation:
https://developer.crowdin.com/api/v2/#operation/api.projects.distributions.patch
"""
projectId = projectId or self.get_project_id()
return self.requester.request(
method="patch",
path=self.get_distributions_path(projectId=projectId, hash=hash),
request_data=data,
)
def get_distribution_release(self, hash: str, projectId: Optional[int] = None):
"""
Get Distribution Release.
Link to documentation:
https://developer.crowdin.com/api/v2/#operation/api.projects.distributions.release.get
"""
projectId = projectId or self.get_project_id()
return self.requester.request(
method="get",
path=f"{self.get_distributions_path(projectId=projectId, hash=hash)}/release",
)
def release_distribution(self, hash: str, projectId: Optional[int] = None):
"""
Release Distribution.
Link to documentation:
https://developer.crowdin.com/api/v2/#operation/api.projects.distributions.release.post
"""
projectId = projectId or self.get_project_id()
return self.requester.request(
method="post",
path=f"{self.get_distributions_path(projectId=projectId, hash=hash)}/release",
)