-
Notifications
You must be signed in to change notification settings - Fork 708
Expand file tree
/
Copy path__init__.py
More file actions
255 lines (196 loc) · 9.46 KB
/
__init__.py
File metadata and controls
255 lines (196 loc) · 9.46 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# coding=utf-8
from .base import ConfluenceCloudBase
class Cloud(ConfluenceCloudBase):
"""
Confluence Cloud REST API wrapper
"""
def __init__(self, url="https://api.atlassian.com/", *args, **kwargs):
# Set default values only if not provided
if "cloud" not in kwargs:
kwargs["cloud"] = True
if "api_version" not in kwargs:
kwargs["api_version"] = "2"
if "api_root" not in kwargs:
kwargs["api_root"] = "wiki/api/v2"
url = url.strip("/")
super(Cloud, self).__init__(url, *args, **kwargs)
# Content Management
def get_content(self, content_id, **kwargs):
"""Get content by ID."""
return self.get(f"content/{content_id}", **kwargs)
def get_content_by_type(self, content_type, **kwargs):
"""Get content by type (page, blogpost, etc.)."""
return self.get("content", params={"type": content_type, **kwargs})
def get_all_pages_from_space(self, space_key, **kwargs):
"""Get all pages from space."""
return self._get_paged("content", params={"spaceKey": space_key, "type": "page", **kwargs})
def get_all_blog_posts_from_space(self, space_key, **kwargs):
"""Get all blog posts from space."""
return self._get_paged("content", params={"spaceKey": space_key, "type": "blogpost", **kwargs})
def create_content(self, data, **kwargs):
"""Create new content."""
return self.post("content", data=data, **kwargs)
def update_content(self, content_id, data, **kwargs):
"""Update existing content."""
return self.put(f"content/{content_id}", data=data, **kwargs)
def delete_content(self, content_id, **kwargs):
"""Delete content."""
return self.delete(f"content/{content_id}", **kwargs)
def get_content_children(self, content_id, **kwargs):
"""Get child content."""
return self.get(f"content/{content_id}/children", **kwargs)
def get_content_descendants(self, content_id, **kwargs):
"""Get descendant content."""
return self.get(f"content/{content_id}/descendants", **kwargs)
def get_content_ancestors(self, content_id, **kwargs):
"""Get ancestor content."""
return self.get(f"content/{content_id}/ancestors", **kwargs)
def get_page_by_title(self, space_key, title, **kwargs):
"""Get page by title and space key."""
return self.get("content", params={"spaceKey": space_key, "title": title, "type": "page", **kwargs})
def get_blog_post_by_title(self, space_key, title, **kwargs):
"""Get blog post by title and space key."""
return self.get("content", params={"spaceKey": space_key, "title": title, "type": "blogpost", **kwargs})
def page_exists(self, space_key, title, **kwargs):
"""Check if page exists."""
result = self.get_page_by_title(space_key, title, **kwargs)
return len(result.get("results", [])) > 0
def blog_post_exists(self, space_key, title, **kwargs):
"""Check if blog post exists."""
result = self.get_blog_post_by_title(space_key, title, **kwargs)
return len(result.get("results", [])) > 0
# Space Management
def get_spaces(self, **kwargs):
"""Get all spaces."""
return self.get("space", **kwargs)
def get_space(self, space_id, **kwargs):
"""Get space by ID."""
return self.get(f"space/{space_id}", **kwargs)
def create_space(self, data, **kwargs):
"""Create new space."""
return self.post("space", data=data, **kwargs)
def update_space(self, space_id, data, **kwargs):
"""Update existing space."""
return self.put(f"space/{space_id}", data=data, **kwargs)
def delete_space(self, space_id, **kwargs):
"""Delete space."""
return self.delete(f"space/{space_id}", **kwargs)
def get_space_content(self, space_id, **kwargs):
"""Get space content."""
return self.get(f"space/{space_id}/content", **kwargs)
# User Management
def get_users(self, **kwargs):
"""Get all users."""
return self.get("user", **kwargs)
def get_user(self, user_id, **kwargs):
"""Get user by ID."""
return self.get(f"user/{user_id}", **kwargs)
def get_current_user(self, **kwargs):
"""Get current user."""
return self.get("user/current", **kwargs)
# Group Management
def get_groups(self, **kwargs):
"""Get all groups."""
return self.get("group", **kwargs)
def get_group(self, group_id, **kwargs):
"""Get group by ID."""
return self.get(f"group/{group_id}", **kwargs)
def get_group_members(self, group_id, **kwargs):
"""Get group members."""
return self.get(f"group/{group_id}/member", **kwargs)
# Label Management
def get_labels(self, **kwargs):
"""Get all labels."""
return self.get("label", **kwargs)
def get_content_labels(self, content_id, **kwargs):
"""Get content labels."""
return self.get(f"content/{content_id}/label", **kwargs)
def add_content_labels(self, content_id, data, **kwargs):
"""Add labels to content."""
return self.post(f"content/{content_id}/label", data=data, **kwargs)
def remove_content_label(self, content_id, label_id, **kwargs):
"""Remove label from content."""
return self.delete(f"content/{content_id}/label/{label_id}", **kwargs)
# Attachment Management
def get_attachments(self, content_id, **kwargs):
"""Get content attachments."""
return self.get(f"content/{content_id}/child/attachment", **kwargs)
def get_attachment(self, attachment_id, **kwargs):
"""Get attachment by ID."""
return self.get(f"content/{attachment_id}", **kwargs)
def create_attachment(self, content_id, data, **kwargs):
"""Create new attachment."""
return self.post(f"content/{content_id}/child/attachment", data=data, **kwargs)
def update_attachment(self, attachment_id, data, **kwargs):
"""Update existing attachment."""
return self.put(f"content/{attachment_id}", data=data, **kwargs)
def delete_attachment(self, attachment_id, **kwargs):
"""Delete attachment."""
return self.delete(f"content/{attachment_id}", **kwargs)
# Comment Management
def get_comments(self, content_id, **kwargs):
"""Get content comments."""
return self.get(f"content/{content_id}/child/comment", **kwargs)
def get_comment(self, comment_id, **kwargs):
"""Get comment by ID."""
return self.get(f"content/{comment_id}", **kwargs)
def create_comment(self, content_id, data, **kwargs):
"""Create new comment."""
return self.post(f"content/{content_id}/child/comment", data=data, **kwargs)
def update_comment(self, comment_id, data, **kwargs):
"""Update existing comment."""
return self.put(f"content/{comment_id}", data=data, **kwargs)
def delete_comment(self, comment_id, **kwargs):
"""Delete comment."""
return self.delete(f"content/{comment_id}", **kwargs)
# Search
def search_content(self, query, **kwargs):
"""Search content."""
return self.get("content/search", params={"cql": query, **kwargs})
def search_spaces(self, query, **kwargs):
"""Search spaces."""
return self.get("space/search", params={"query": query, **kwargs})
# Page Properties
def get_content_properties(self, content_id, **kwargs):
"""Get content properties."""
return self.get(f"content/{content_id}/property", **kwargs)
def get_content_property(self, content_id, property_key, **kwargs):
"""Get content property by key."""
return self.get(f"content/{content_id}/property/{property_key}", **kwargs)
def create_content_property(self, content_id, data, **kwargs):
"""Create new content property."""
return self.post(f"content/{content_id}/property", data=data, **kwargs)
def update_content_property(self, content_id, property_key, data, **kwargs):
"""Update existing content property."""
return self.put(f"content/{content_id}/property/{property_key}", data=data, **kwargs)
def delete_content_property(self, content_id, property_key, **kwargs):
"""Delete content property."""
return self.delete(f"content/{content_id}/property/{property_key}", **kwargs)
# Templates
def get_templates(self, **kwargs):
"""Get all templates."""
return self.get("template", **kwargs)
def get_template(self, template_id, **kwargs):
"""Get template by ID."""
return self.get(f"template/{template_id}", **kwargs)
# Analytics
def get_content_analytics(self, content_id, **kwargs):
"""Get content analytics."""
return self.get(f"content/{content_id}/analytics", **kwargs)
def get_space_analytics(self, space_id, **kwargs):
"""Get space analytics."""
return self.get(f"space/{space_id}/analytics", **kwargs)
# Export
def export_content(self, content_id, **kwargs):
"""Export content."""
return self.get(f"content/{content_id}/export", **kwargs)
def export_space(self, space_id, **kwargs):
"""Export space."""
return self.get(f"space/{space_id}/export", **kwargs)
# Utility Methods
def get_metadata(self, **kwargs):
"""Get API metadata."""
return self.get("metadata", **kwargs)
def get_health(self, **kwargs):
"""Get API health status."""
return self.get("health", **kwargs)