Skip to content

Commit 4079eb1

Browse files
committed
add examples
1 parent ef18316 commit 4079eb1

File tree

2 files changed

+250
-2
lines changed

2 files changed

+250
-2
lines changed

synapseclient/models/protocols/wikipage_protocol.py

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,57 @@
1616

1717
class WikiOrderHintSynchronousProtocol(Protocol):
1818
"""Protocol for the methods of the WikiOrderHint class that have synchronous counterparts
19-
generated at runtime."""
19+
generated at runtime.
20+
"""
2021

2122
def store(
2223
self,
2324
*,
2425
synapse_client: Optional["Synapse"] = None,
2526
) -> "WikiOrderHint":
2627
"""
27-
Update the order hint of a wiki page tree.
28+
Store the order hint of a wiki page tree.
2829
Arguments:
2930
synapse_client: Optionally provide a Synapse client.
3031
Returns:
3132
The updated WikiOrderHint object for the entity.
33+
34+
Example: Set the WikiOrderHint for a project
35+
This example shows how to set a WikiOrderHint for existing wiki pages in a project.
36+
The WikiOrderHint is not set by default, so you need to set it explicitly.
37+
from synapseclient import Synapse
38+
from synapseclient.models import (
39+
Project,
40+
WikiOrderHint,
41+
)
42+
syn = Synapse()
43+
syn.login()
44+
45+
project = Project(name="My uniquely named project about Alzheimer's Disease").get()
46+
# get the WikiOrderHint for the project
47+
wiki_order_hint = WikiOrderHint(owner_id=project.id).get()
48+
49+
wiki_order_hint.id_list = [
50+
root_wiki_page.id,
51+
wiki_page_1.id,
52+
wiki_page_3.id,
53+
wiki_page_2.id,
54+
wiki_page_4.id,
55+
]
56+
wiki_order_hint.store()
57+
print(wiki_order_hint)
58+
59+
Example: Update the WikiOrderHint for a project
60+
This example shows how to update a WikiOrderHint for existing wiki pages in a project.
61+
wiki_order_hint.id_list = [
62+
root_wiki_page.id,
63+
wiki_page_1.id,
64+
wiki_page_2.id,
65+
wiki_page_3.id,
66+
wiki_page_4.id,
67+
]
68+
wiki_order_hint.store()
69+
print(wiki_order_hint)
3270
"""
3371
return self
3472

@@ -43,6 +81,22 @@ def get(
4381
synapse_client: Optionally provide a Synapse client.
4482
Returns:
4583
A WikiOrderHint object for the entity.
84+
85+
Example: Get the WikiOrderHint for a project
86+
This example shows how to get a WikiOrderHint for existing wiki pages in a project.
87+
from synapseclient import Synapse
88+
from synapseclient.models import (
89+
Project,
90+
WikiOrderHint,
91+
)
92+
syn = Synapse()
93+
syn.login()
94+
95+
project = Project(name="My uniquely named project about Alzheimer's Disease").get()
96+
# get the WikiOrderHint for the project
97+
wiki_order_hint = WikiOrderHint(owner_id=project.id).get()
98+
99+
print(wiki_order_hint)
46100
"""
47101
return self
48102

@@ -71,6 +125,10 @@ def get(
71125
synapse_client: Optionally provide a Synapse client.
72126
Returns:
73127
A list of WikiHistorySnapshot objects for the wiki page.
128+
129+
Example: Get the history of a wiki page
130+
history = WikiHistorySnapshot.get(owner_id=project.id, id=wiki_page.id)
131+
print(f"History: {history}")
74132
"""
75133
return list({})
76134

@@ -97,6 +155,10 @@ def get(
97155
synapse_client: Optionally provide a Synapse client.
98156
Returns:
99157
A list of WikiHeader objects for the entity.
158+
159+
Example: Get the header tree (hierarchy) of wiki pages for an entity
160+
headers = WikiHeader.get(owner_id=project.id)
161+
print(f"Headers: {headers}")
100162
"""
101163
return list({})
102164

@@ -113,6 +175,20 @@ def store(self, *, synapse_client: Optional["Synapse"] = None) -> "WikiPage":
113175
synapse_client: Optionally provide a Synapse client.
114176
Returns:
115177
The created WikiPage object.
178+
179+
Example: Store a wiki page
180+
This example shows how to store a wiki page.
181+
from synapseclient import Synapse
182+
from synapseclient.models import (
183+
Project,
184+
WikiPage,
185+
)
186+
syn = Synapse()
187+
syn.login()
188+
189+
project = Project(name="My uniquely named project about Alzheimer's Disease").get()
190+
wiki_page = WikiPage(owner_id=project.id, title="My wiki page").store()
191+
print(wiki_page)
116192
"""
117193
return self
118194

@@ -123,6 +199,11 @@ def restore(self, *, synapse_client: Optional["Synapse"] = None) -> "WikiPage":
123199
synapse_client: Optionally provide a Synapse client.
124200
Returns:
125201
The restored WikiPage object.
202+
203+
Example: Restore a specific version of a wiki page
204+
This example shows how to restore a specific version of a wiki page.
205+
wiki_page_restored = WikiPage(owner_id=project.id, id=root_wiki_page.id, wiki_version="0").restore()
206+
print(wiki_page_restored)
126207
"""
127208
return self
128209

@@ -133,6 +214,11 @@ def get(self, *, synapse_client: Optional["Synapse"] = None) -> "WikiPage":
133214
synapse_client: Optionally provide a Synapse client.
134215
Returns:
135216
The WikiPage object.
217+
218+
Example: Get a wiki page from Synapse
219+
This example shows how to get a wiki page from Synapse.
220+
wiki_page = WikiPage(owner_id=project.id, id=wiki_page.id).get()
221+
print(wiki_page)
136222
"""
137223
return self
138224

@@ -143,6 +229,11 @@ def delete(self, *, synapse_client: Optional["Synapse"] = None) -> None:
143229
synapse_client: Optionally provide a Synapse client.
144230
Returns:
145231
None
232+
233+
Example: Delete a wiki page
234+
This example shows how to delete a wiki page.
235+
wiki_page = WikiPage(owner_id=project.id, id=wiki_page.id).delete()
236+
print(f"Wiki page {wiki_page.title} deleted successfully.")
146237
"""
147238
return None
148239

@@ -155,6 +246,11 @@ def get_attachment_handles(
155246
synapse_client: Optionally provide a Synapse client.
156247
Returns:
157248
The list of FileHandles for all file attachments of this WikiPage.
249+
250+
Example: Get the file handles of all attachments on a wiki page
251+
This example shows how to get the file handles of all attachments on a wiki page.
252+
attachment_handles = WikiPage(owner_id=project.id, id=wiki_page.id).get_attachment_handles()
253+
print(f"Attachment handles: {attachment_handles['list']}")
158254
"""
159255
return list({})
160256

@@ -177,6 +273,16 @@ def get_attachment(
177273
synapse_client: Optionally provide a Synapse client.
178274
Returns:
179275
If download_file is True, the attachment file will be downloaded to the download_location. Otherwise, the URL will be returned.
276+
277+
Example: Get the attachment URL for a wiki page
278+
This example shows how to get the attachment file or URL for a wiki page.
279+
attachment_file_or_url = WikiPage(owner_id=project.id, id=wiki_page.id).get_attachment(file_name="attachment.txt", download_file=False)
280+
print(f"Attachment URL: {attachment_file_or_url}")
281+
282+
Example: Download the attachment file for a wiki page
283+
This example shows how to download the attachment file for a wiki page.
284+
attachment_file_path = WikiPage(owner_id=project.id, id=wiki_page.id).get_attachment(file_name="attachment.txt", download_file=True, download_location="~/temp")
285+
print(f"Attachment file path: {attachment_file_path}")
180286
"""
181287
return ""
182288

@@ -197,6 +303,18 @@ def get_attachment_preview(
197303
synapse_client: Optionally provide a Synapse client.
198304
Returns:
199305
If download_file is True, the attachment preview file will be downloaded to the download_location. Otherwise, the URL will be returned.
306+
307+
Example: Get the attachment preview URL for a wiki page
308+
This example shows how to get the attachment preview URL for a wiki page.
309+
Instead of using the file_name from the attachmenthandle response when isPreview=True, you should use the original file name in the get_attachment_preview request.
310+
The downloaded file will still be named according to the file_name provided in the response when isPreview=True.
311+
attachment_preview_url = WikiPage(owner_id=project.id, id=wiki_page.id).get_attachment_preview(file_name="attachment.txt.gz", download_file=False)
312+
print(f"Attachment preview URL: {attachment_preview_url}")
313+
314+
Example: Download the attachment preview file for a wiki page
315+
This example shows how to download the attachment preview file for a wiki page.
316+
attachment_preview_file_path = WikiPage(owner_id=project.id, id=wiki_page.id).get_attachment_preview(file_name="attachment.txt.gz", download_file=True, download_location="~/temp")
317+
print(f"Attachment preview file path: {attachment_preview_file_path}")
200318
"""
201319
return ""
202320

@@ -213,5 +331,15 @@ def get_markdown(
213331
synapse_client: Optionally provide a Synapse client.
214332
Returns:
215333
If download_file is True, the markdown file will be downloaded to the download_location. Otherwise, the URL will be returned.
334+
335+
Example: Get the markdown URL for a wiki page
336+
This example shows how to get the markdown URL for a wiki page.
337+
markdown_url = WikiPage(owner_id=project.id, id=wiki_page.id).get_markdown(download_file=False)
338+
print(f"Markdown URL: {markdown_url}")
339+
340+
Example: Download the markdown file for a wiki page
341+
This example shows how to download the markdown file for a wiki page.
342+
markdown_file_path = WikiPage(owner_id=project.id, id=wiki_page.id).get_markdown(download_file=True, download_location="~/temp")
343+
print(f"Markdown file path: {markdown_file_path}")
216344
"""
217345
return ""

0 commit comments

Comments
 (0)