smartsheet-python-sdk 3.5.5__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.
Files changed (195) hide show
  1. smartsheet/__init__.py +37 -0
  2. smartsheet/attachments.py +565 -0
  3. smartsheet/cells.py +164 -0
  4. smartsheet/contacts.py +78 -0
  5. smartsheet/discussions.py +411 -0
  6. smartsheet/events.py +79 -0
  7. smartsheet/exceptions.py +130 -0
  8. smartsheet/favorites.py +116 -0
  9. smartsheet/folders.py +438 -0
  10. smartsheet/groups.py +186 -0
  11. smartsheet/home.py +180 -0
  12. smartsheet/images.py +61 -0
  13. smartsheet/models/__init__.py +126 -0
  14. smartsheet/models/access_token.py +95 -0
  15. smartsheet/models/account.py +77 -0
  16. smartsheet/models/alternate_email.py +88 -0
  17. smartsheet/models/asset_share.py +165 -0
  18. smartsheet/models/asset_shares_paginated_result.py +84 -0
  19. smartsheet/models/attachment.py +181 -0
  20. smartsheet/models/auto_number_format.py +81 -0
  21. smartsheet/models/automation_action.py +162 -0
  22. smartsheet/models/automation_rule.py +164 -0
  23. smartsheet/models/boolean_object_value.py +38 -0
  24. smartsheet/models/bulk_item_failure.py +77 -0
  25. smartsheet/models/bulk_item_result.py +111 -0
  26. smartsheet/models/cell.py +193 -0
  27. smartsheet/models/cell_data_item.py +152 -0
  28. smartsheet/models/cell_history.py +67 -0
  29. smartsheet/models/cell_link.py +91 -0
  30. smartsheet/models/cell_link_widget_content.py +101 -0
  31. smartsheet/models/chart_widget_content.py +124 -0
  32. smartsheet/models/column.py +253 -0
  33. smartsheet/models/comment.py +126 -0
  34. smartsheet/models/contact.py +88 -0
  35. smartsheet/models/contact_object_value.py +59 -0
  36. smartsheet/models/container_destination.py +74 -0
  37. smartsheet/models/copy_or_move_row_destination.py +54 -0
  38. smartsheet/models/copy_or_move_row_directive.py +64 -0
  39. smartsheet/models/copy_or_move_row_result.py +67 -0
  40. smartsheet/models/criteria.py +82 -0
  41. smartsheet/models/cross_sheet_reference.py +134 -0
  42. smartsheet/models/currency.py +64 -0
  43. smartsheet/models/date_object_value.py +56 -0
  44. smartsheet/models/datetime_object_value.py +56 -0
  45. smartsheet/models/discussion.py +183 -0
  46. smartsheet/models/downloaded_file.py +106 -0
  47. smartsheet/models/duration.py +112 -0
  48. smartsheet/models/email.py +82 -0
  49. smartsheet/models/enums/__init__.py +56 -0
  50. smartsheet/models/enums/access_level.py +26 -0
  51. smartsheet/models/enums/asset_type.py +10 -0
  52. smartsheet/models/enums/attachment_parent_type.py +23 -0
  53. smartsheet/models/enums/attachment_sub_type.py +26 -0
  54. smartsheet/models/enums/attachment_type.py +29 -0
  55. smartsheet/models/enums/automation_action_frequency.py +24 -0
  56. smartsheet/models/enums/automation_action_type.py +23 -0
  57. smartsheet/models/enums/automation_rule_disabled_reason.py +27 -0
  58. smartsheet/models/enums/cell_link_status.py +28 -0
  59. smartsheet/models/enums/column_type.py +31 -0
  60. smartsheet/models/enums/criteria_target.py +21 -0
  61. smartsheet/models/enums/cross_sheet_reference_status.py +28 -0
  62. smartsheet/models/enums/currency_code.py +43 -0
  63. smartsheet/models/enums/day_descriptors.py +30 -0
  64. smartsheet/models/enums/day_ordinal.py +25 -0
  65. smartsheet/models/enums/event_action.py +76 -0
  66. smartsheet/models/enums/event_obejct_type.py +34 -0
  67. smartsheet/models/enums/event_source.py +27 -0
  68. smartsheet/models/enums/global_template.py +23 -0
  69. smartsheet/models/enums/operator.py +62 -0
  70. smartsheet/models/enums/paper_type.py +29 -0
  71. smartsheet/models/enums/predecessor_type.py +24 -0
  72. smartsheet/models/enums/publish_accessible_by.py +22 -0
  73. smartsheet/models/enums/schedule_type.py +25 -0
  74. smartsheet/models/enums/seat_type.py +17 -0
  75. smartsheet/models/enums/share_scope.py +22 -0
  76. smartsheet/models/enums/share_type.py +22 -0
  77. smartsheet/models/enums/sheet_email_format.py +23 -0
  78. smartsheet/models/enums/sheet_filter_operator.py +22 -0
  79. smartsheet/models/enums/sheet_filter_type.py +23 -0
  80. smartsheet/models/enums/sort_direction.py +22 -0
  81. smartsheet/models/enums/symbol.py +45 -0
  82. smartsheet/models/enums/system_column_type.py +25 -0
  83. smartsheet/models/enums/update_request_status.py +23 -0
  84. smartsheet/models/enums/user_status.py +23 -0
  85. smartsheet/models/enums/widget_type.py +32 -0
  86. smartsheet/models/error.py +74 -0
  87. smartsheet/models/error_result.py +117 -0
  88. smartsheet/models/event.py +153 -0
  89. smartsheet/models/event_result.py +86 -0
  90. smartsheet/models/explicit_null.py +24 -0
  91. smartsheet/models/favorite.py +81 -0
  92. smartsheet/models/folder.py +177 -0
  93. smartsheet/models/font_family.py +63 -0
  94. smartsheet/models/format_details.py +55 -0
  95. smartsheet/models/format_tables.py +191 -0
  96. smartsheet/models/group.py +134 -0
  97. smartsheet/models/group_member.py +104 -0
  98. smartsheet/models/home.py +110 -0
  99. smartsheet/models/hyperlink.py +81 -0
  100. smartsheet/models/image.py +101 -0
  101. smartsheet/models/image_url.py +91 -0
  102. smartsheet/models/image_url_map.py +68 -0
  103. smartsheet/models/image_widget_content.py +117 -0
  104. smartsheet/models/index_result.py +118 -0
  105. smartsheet/models/json_object.py +59 -0
  106. smartsheet/models/multi_contact_object_value.py +49 -0
  107. smartsheet/models/multi_picklist_object_value.py +48 -0
  108. smartsheet/models/multi_row_email.py +60 -0
  109. smartsheet/models/number_object_value.py +38 -0
  110. smartsheet/models/o_auth_error.py +86 -0
  111. smartsheet/models/object_value.py +130 -0
  112. smartsheet/models/paginated_children_result.py +80 -0
  113. smartsheet/models/predecessor.py +102 -0
  114. smartsheet/models/predecessor_list.py +49 -0
  115. smartsheet/models/primitive_object_value.py +59 -0
  116. smartsheet/models/profile_image.py +72 -0
  117. smartsheet/models/project_settings.py +89 -0
  118. smartsheet/models/recipient.py +63 -0
  119. smartsheet/models/report.py +90 -0
  120. smartsheet/models/report_cell.py +59 -0
  121. smartsheet/models/report_column.py +67 -0
  122. smartsheet/models/report_publish.py +95 -0
  123. smartsheet/models/report_row.py +68 -0
  124. smartsheet/models/report_widget_content.py +78 -0
  125. smartsheet/models/result.py +105 -0
  126. smartsheet/models/row.py +336 -0
  127. smartsheet/models/row_email.py +83 -0
  128. smartsheet/models/row_mapping.py +77 -0
  129. smartsheet/models/schedule.py +140 -0
  130. smartsheet/models/scope.py +70 -0
  131. smartsheet/models/search_result.py +67 -0
  132. smartsheet/models/search_result_item.py +150 -0
  133. smartsheet/models/selection_range.py +86 -0
  134. smartsheet/models/sent_update_request.py +172 -0
  135. smartsheet/models/server_info.py +67 -0
  136. smartsheet/models/share.py +183 -0
  137. smartsheet/models/sheet.py +462 -0
  138. smartsheet/models/sheet_email.py +81 -0
  139. smartsheet/models/sheet_filter.py +106 -0
  140. smartsheet/models/sheet_filter_details.py +76 -0
  141. smartsheet/models/sheet_publish.py +184 -0
  142. smartsheet/models/sheet_summary.py +59 -0
  143. smartsheet/models/sheet_user_permissions.py +58 -0
  144. smartsheet/models/sheet_user_settings.py +72 -0
  145. smartsheet/models/shortcut_data_item.py +102 -0
  146. smartsheet/models/shortcut_widget_content.py +61 -0
  147. smartsheet/models/sight.py +175 -0
  148. smartsheet/models/sight_publish.py +77 -0
  149. smartsheet/models/sort_criterion.py +64 -0
  150. smartsheet/models/sort_specifier.py +55 -0
  151. smartsheet/models/source.py +83 -0
  152. smartsheet/models/string_object_value.py +38 -0
  153. smartsheet/models/summary_field.py +256 -0
  154. smartsheet/models/template.py +171 -0
  155. smartsheet/models/title_rich_text_widget_content.py +68 -0
  156. smartsheet/models/token_paginated_result.py +79 -0
  157. smartsheet/models/update_request.py +110 -0
  158. smartsheet/models/user.py +58 -0
  159. smartsheet/models/user_model.py +280 -0
  160. smartsheet/models/user_plan.py +77 -0
  161. smartsheet/models/user_profile.py +89 -0
  162. smartsheet/models/version.py +57 -0
  163. smartsheet/models/web_content_widget_content.py +60 -0
  164. smartsheet/models/webhook.py +219 -0
  165. smartsheet/models/webhook_secret.py +58 -0
  166. smartsheet/models/webhook_stats.py +76 -0
  167. smartsheet/models/webhook_subscope.py +50 -0
  168. smartsheet/models/widget.py +211 -0
  169. smartsheet/models/widget_content.py +52 -0
  170. smartsheet/models/widget_hyperlink.py +74 -0
  171. smartsheet/models/workspace.py +185 -0
  172. smartsheet/object_value.py +72 -0
  173. smartsheet/passthrough.py +127 -0
  174. smartsheet/reports.py +382 -0
  175. smartsheet/search.py +100 -0
  176. smartsheet/server.py +48 -0
  177. smartsheet/session.py +70 -0
  178. smartsheet/sharing.py +163 -0
  179. smartsheet/sheets.py +2062 -0
  180. smartsheet/sights.py +370 -0
  181. smartsheet/smartsheet.py +684 -0
  182. smartsheet/templates.py +87 -0
  183. smartsheet/token.py +128 -0
  184. smartsheet/types.py +323 -0
  185. smartsheet/users.py +490 -0
  186. smartsheet/util.py +199 -0
  187. smartsheet/version.py +34 -0
  188. smartsheet/webhooks.py +161 -0
  189. smartsheet/workspaces.py +647 -0
  190. smartsheet_python_sdk-3.5.5.dist-info/METADATA +120 -0
  191. smartsheet_python_sdk-3.5.5.dist-info/RECORD +195 -0
  192. smartsheet_python_sdk-3.5.5.dist-info/WHEEL +5 -0
  193. smartsheet_python_sdk-3.5.5.dist-info/licenses/LICENSE.md +201 -0
  194. smartsheet_python_sdk-3.5.5.dist-info/licenses/NOTICE +10 -0
  195. smartsheet_python_sdk-3.5.5.dist-info/top_level.txt +1 -0
smartsheet/__init__.py ADDED
@@ -0,0 +1,37 @@
1
+ # pylint: disable=C0111,C0413
2
+ # Smartsheet Python SDK.
3
+ #
4
+ # Copyright 2016-2021 Smartsheet.com, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License"): you may
7
+ # not use this file except in compliance with the License. You may obtain
8
+ # a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
+ # License for the specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ from __future__ import absolute_import
19
+
20
+ __api_base__ = "https://api.smartsheet.com/2.0"
21
+ __eu_base__ = "https://api.smartsheet.eu/2.0"
22
+ __gov_base__ = "https://api.smartsheetgov.com/2.0"
23
+ __api_version__ = "2.0"
24
+
25
+ try:
26
+ from .version import version
27
+
28
+ __version__ = version
29
+ except ImportError:
30
+ from setuptools_scm import get_version
31
+
32
+ __version__ = get_version()
33
+
34
+ from .smartsheet import (AbstractUserCalcBackoff, Smartsheet, # NOQA
35
+ fresh_operation)
36
+
37
+ from . import models
@@ -0,0 +1,565 @@
1
+ # pylint: disable=C0111,R0902,R0913,E1137,W3101
2
+ # Smartsheet Python SDK.
3
+ #
4
+ # Copyright 2016 Smartsheet.com, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License"): you may
7
+ # not use this file except in compliance with the License. You may obtain
8
+ # a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
+ # License for the specific language governing permissions and limitations
16
+ # under the License.
17
+
18
+ from __future__ import absolute_import
19
+
20
+ import logging
21
+ import os.path
22
+
23
+ import requests
24
+
25
+ from . import fresh_operation
26
+ from .models import DownloadedFile, Error, ErrorResult
27
+
28
+
29
+ class Attachments:
30
+
31
+ """Class for handling Attachments operations."""
32
+
33
+ def __init__(self, smartsheet_obj):
34
+ """Init Attachments with base Smartsheet object."""
35
+ self._base = smartsheet_obj
36
+ self._log = logging.getLogger(__name__)
37
+
38
+ def attach_file_to_comment(self, sheet_id, comment_id, _file):
39
+ """Add a file to a Comment.
40
+
41
+ Args:
42
+ sheet_id (int): Sheet ID
43
+ comment_id (int): Comment ID
44
+ _file (file): String or file stream object.
45
+
46
+ Returns:
47
+ Result
48
+ """
49
+ if not all(val is not None for val in ["sheet_id", "comment_id", "_file"]):
50
+ raise ValueError(
51
+ ("One or more required values are missing from call to " + __name__)
52
+ )
53
+
54
+ _op = fresh_operation("attach_file_to_comment")
55
+ _op["method"] = "POST"
56
+ _op["path"] = (
57
+ "/sheets/" + str(sheet_id) + "/comments/" + str(comment_id) + "/attachments"
58
+ )
59
+ _op["files"] = {}
60
+ _op["files"]["file"] = _file
61
+
62
+ expected = ["Result", "Attachment"]
63
+
64
+ prepped_request = self._base.prepare_request(_op)
65
+ response = self._base.request(prepped_request, expected, _op)
66
+
67
+ return response
68
+
69
+ def attach_file_to_row(self, sheet_id, row_id, _file):
70
+ """Add a file to the row.
71
+
72
+ Args:
73
+ sheet_id (int): Sheet ID
74
+ row_id (int): Row ID
75
+ _file (file): String or file stream object.
76
+
77
+ Returns:
78
+ Result
79
+ """
80
+ if not all(val is not None for val in ["sheet_id", "row_id", "_file"]):
81
+ raise ValueError(
82
+ ("One or more required values are missing from call to " + __name__)
83
+ )
84
+
85
+ _op = fresh_operation("attach_file_to_row")
86
+ _op["method"] = "POST"
87
+ _op["path"] = (
88
+ "/sheets/" + str(sheet_id) + "/rows/" + str(row_id) + "/attachments"
89
+ )
90
+ _op["files"] = {}
91
+ _op["files"]["file"] = _file
92
+
93
+ expected = ["Result", "Attachment"]
94
+
95
+ prepped_request = self._base.prepare_request(_op)
96
+ response = self._base.request(prepped_request, expected, _op)
97
+
98
+ return response
99
+
100
+ def attach_file_to_sheet(self, sheet_id, _file):
101
+ """Attach a file to the specified Sheet.
102
+
103
+ Args:
104
+ sheet_id (int): Sheet ID
105
+ _file (file): String or file stream object.
106
+
107
+ Returns:
108
+ Result
109
+ """
110
+ _op = fresh_operation("attach_file_to_sheet")
111
+ _op["method"] = "POST"
112
+ _op["path"] = "/sheets/" + str(sheet_id) + "/attachments"
113
+ _op["files"] = {}
114
+ _op["files"]["file"] = _file
115
+
116
+ expected = ["Result", "Attachment"]
117
+
118
+ prepped_request = self._base.prepare_request(_op)
119
+ response = self._base.request(prepped_request, expected, _op)
120
+
121
+ return response
122
+
123
+ def attach_new_version(self, sheet_id, attachment_id, _file):
124
+ """Upload a new version of a file to a Sheet or Row.
125
+
126
+ Args:
127
+ sheet_id (int): Sheet ID
128
+ attachment_id (int): Attachment ID
129
+ _file (file): String or file stream object.
130
+
131
+ Returns:
132
+ Result
133
+ """
134
+ if not all(val is not None for val in ["sheet_id", "attachment_id", "_file"]):
135
+ raise ValueError(
136
+ ("One or more required values are missing from call to " + __name__)
137
+ )
138
+
139
+ _op = fresh_operation("attach_new_version")
140
+ _op["method"] = "POST"
141
+ _op["path"] = (
142
+ "/sheets/"
143
+ + str(sheet_id)
144
+ + "/attachments/"
145
+ + str(attachment_id)
146
+ + "/versions"
147
+ )
148
+ _op["files"] = {}
149
+ _op["files"]["file"] = _file
150
+
151
+ expected = ["Result", "Attachment"]
152
+
153
+ prepped_request = self._base.prepare_request(_op)
154
+ response = self._base.request(prepped_request, expected, _op)
155
+
156
+ return response
157
+
158
+ def attach_url_to_comment(self, sheet_id, comment_id, attachment_obj):
159
+ """Add a URL to a Comment.
160
+
161
+ Attachment object for this request should be limited to the
162
+ following attributes: name, description, url, attachmentType,
163
+ attachmentSubType.
164
+
165
+ The URL and attachmentType can be any of the following:
166
+
167
+ A Normal URL. attachmentType is LINK.
168
+
169
+ A Google Drive URL. attachmentType is LINK. Supports
170
+ attachmentSubType values of DOCUMENT, SPREADSHEET, PRESENTATION,
171
+ PDF and DRAWING.
172
+
173
+ A Box.com URL. attachmentType is BOX_COM.
174
+
175
+ A Dropbox URL. attachmentType is DROPBOX.
176
+
177
+ An Evernote URL. attachmentType is EVERNOTE.
178
+
179
+ An Egnyte URL. attachmentType is EGNYTE. Supports attachmentSubType
180
+ of FOLDER.
181
+
182
+ Args:
183
+ sheet_id (int): Sheet ID
184
+ comment_id (int): Comment ID
185
+ attachment_obj (Attachment): Attachment object.
186
+
187
+ Returns:
188
+ Result
189
+ """
190
+ if not all(
191
+ val is not None for val in ["sheet_id", "comment_id", "attachment_obj"]
192
+ ):
193
+ raise ValueError(
194
+ ("One or more required values are missing from call to " + __name__)
195
+ )
196
+
197
+ _op = fresh_operation("attach_url_to_comment")
198
+ _op["method"] = "POST"
199
+ _op["path"] = (
200
+ "/sheets/" + str(sheet_id) + "/comments/" + str(comment_id) + "/attachments"
201
+ )
202
+ _op["json"] = attachment_obj
203
+
204
+ expected = ["Result", "Attachment"]
205
+
206
+ prepped_request = self._base.prepare_request(_op)
207
+ response = self._base.request(prepped_request, expected, _op)
208
+
209
+ return response
210
+
211
+ def attach_url_to_row(self, sheet_id, row_id, attachment_obj):
212
+ """Add a URL to a Row.
213
+
214
+ Attachment object for this request should be limited to the
215
+ following attributes: name, description, url, attachmentType,
216
+ attachmentSubType.
217
+
218
+ The URL and attachmentType can be any of the following:
219
+
220
+ A Normal URL. attachmentType is LINK.
221
+
222
+ A Google Drive URL. attachmentType is LINK. Supports
223
+ attachmentSubType values of DOCUMENT, SPREADSHEET, PRESENTATION,
224
+ PDF and DRAWING.
225
+
226
+ A Box.com URL. attachmentType is BOX_COM.
227
+
228
+ A Dropbox URL. attachmentType is DROPBOX.
229
+
230
+ An Evernote URL. attachmentType is EVERNOTE.
231
+
232
+ An Egnyte URL. attachmentType is EGNYTE. Supports attachmentSubType
233
+ of FOLDER.
234
+
235
+ Args:
236
+ sheet_id (int): Sheet ID
237
+ row_id (int): Row ID
238
+ attachment_obj (Attachment): Attachment object.
239
+
240
+ Returns:
241
+ Result
242
+ """
243
+ if not all(val is not None for val in ["sheet_id", "row_id", "attachment_obj"]):
244
+ raise ValueError(
245
+ ("One or more required values are missing from call to " + __name__)
246
+ )
247
+
248
+ _op = fresh_operation("attach_url_to_row")
249
+ _op["method"] = "POST"
250
+ _op["path"] = (
251
+ "/sheets/" + str(sheet_id) + "/rows/" + str(row_id) + "/attachments"
252
+ )
253
+ _op["json"] = attachment_obj
254
+
255
+ expected = ["Result", "Attachment"]
256
+
257
+ prepped_request = self._base.prepare_request(_op)
258
+ response = self._base.request(prepped_request, expected, _op)
259
+
260
+ return response
261
+
262
+ def attach_url_to_sheet(self, sheet_id, attachment_obj):
263
+ """Add a URL to a Sheet.
264
+
265
+ Attachment object for this request should be limited to the
266
+ following attributes: name, description, url, attachmentType,
267
+ attachmentSubType.
268
+
269
+ The URL and attachmentType can be any of the following:
270
+
271
+ A Normal URL. attachmentType is LINK.
272
+
273
+ A Google Drive URL. attachmentType is LINK. Supports
274
+ attachmentSubType values of DOCUMENT, SPREADSHEET, PRESENTATION,
275
+ PDF and DRAWING.
276
+
277
+ A Box.com URL. attachmentType is BOX_COM.
278
+
279
+ A Dropbox URL. attachmentType is DROPBOX.
280
+
281
+ An Evernote URL. attachmentType is EVERNOTE.
282
+
283
+ An Egnyte URL. attachmentType is EGNYTE. Supports attachmentSubType
284
+ of FOLDER.
285
+
286
+ Args:
287
+ sheet_id (int): Sheet ID
288
+ attachment_obj (Attachment): Attachment object.
289
+
290
+ Returns:
291
+ Result
292
+ """
293
+ _op = fresh_operation("attach_url_to_sheet")
294
+ _op["method"] = "POST"
295
+ _op["path"] = "/sheets/" + str(sheet_id) + "/attachments"
296
+ _op["json"] = attachment_obj
297
+
298
+ expected = ["Result", "Attachment"]
299
+
300
+ prepped_request = self._base.prepare_request(_op)
301
+ response = self._base.request(prepped_request, expected, _op)
302
+
303
+ return response
304
+
305
+ def delete_attachment(self, sheet_id, attachment_id):
306
+ """Delete the specified Attachment.
307
+
308
+ Args:
309
+ sheet_id (int): Sheet ID
310
+ attachment_id (int): Attachment ID
311
+
312
+ Returns:
313
+ Result
314
+ """
315
+ _op = fresh_operation("delete_attachment")
316
+ _op["method"] = "DELETE"
317
+ _op["path"] = "/sheets/" + str(sheet_id) + "/attachments/" + str(attachment_id)
318
+
319
+ expected = ["Result", None]
320
+ prepped_request = self._base.prepare_request(_op)
321
+ response = self._base.request(prepped_request, expected, _op)
322
+
323
+ return response
324
+
325
+ def delete_attachment_versions(self, sheet_id, attachment_id):
326
+ """Delete all versions of the specified Attachment.
327
+
328
+ Delete all versions of the attachment corresponding to the
329
+ specified Attachment ID.
330
+
331
+ Args:
332
+ sheet_id (int): Sheet ID
333
+ attachment_id (int): Attachment ID
334
+
335
+ Returns:
336
+ Result
337
+ """
338
+ _op = fresh_operation("delete_attachment_versions")
339
+ _op["method"] = "DELETE"
340
+ _op["path"] = (
341
+ "/sheets/"
342
+ + str(sheet_id)
343
+ + "/attachments/"
344
+ + str(attachment_id)
345
+ + "/versions"
346
+ )
347
+
348
+ expected = ["Result", None]
349
+ prepped_request = self._base.prepare_request(_op)
350
+ response = self._base.request(prepped_request, expected, _op)
351
+
352
+ return response
353
+
354
+ def get_attachment(self, sheet_id, attachment_id):
355
+ """Fetch the specified Attachment.
356
+
357
+ Args:
358
+ sheet_id (int): Sheet ID
359
+ attachment_id (int): Attachment ID
360
+
361
+ Returns:
362
+ Attachment
363
+ """
364
+ _op = fresh_operation("get_attachment")
365
+ _op["method"] = "GET"
366
+ _op["path"] = "/sheets/" + str(sheet_id) + "/attachments/" + str(attachment_id)
367
+
368
+ expected = "Attachment"
369
+ prepped_request = self._base.prepare_request(_op)
370
+ response = self._base.request(prepped_request, expected, _op)
371
+
372
+ return response
373
+
374
+ def list_all_attachments(
375
+ self, sheet_id, page_size=None, page=None, include_all=None
376
+ ):
377
+ """Get a list of Attachments for a Sheet.
378
+
379
+ Get a list of all Attachments for the specified Sheet,
380
+ including Sheet, Row, and Discussion level Attachments.
381
+
382
+ Args:
383
+ sheet_id (int): Sheet ID
384
+ page_size (int): The maximum number of items to
385
+ return per page.
386
+ page (int): Which page to return.
387
+ include_all (bool): If true, include all results
388
+ (i.e. do not paginate).
389
+
390
+ Returns:
391
+ IndexResult
392
+ """
393
+ _op = fresh_operation("list_all_attachments")
394
+ _op["method"] = "GET"
395
+ _op["path"] = "/sheets/" + str(sheet_id) + "/attachments"
396
+ _op["query_params"]["pageSize"] = page_size
397
+ _op["query_params"]["page"] = page
398
+ _op["query_params"]["includeAll"] = include_all
399
+
400
+ expected = ["IndexResult", "Attachment"]
401
+
402
+ prepped_request = self._base.prepare_request(_op)
403
+ response = self._base.request(prepped_request, expected, _op)
404
+
405
+ return response
406
+
407
+ def list_attachment_versions(
408
+ self, sheet_id, attachment_id, page_size=None, page=None, include_all=None
409
+ ):
410
+ """Get a list of versions for an Attachment.
411
+
412
+ Get a list of all versions of the given Attachment ID, in
413
+ order from newest to oldest.
414
+
415
+ Args:
416
+ sheet_id (int): Sheet ID
417
+ attachment_id (int): Attachment ID
418
+ page_size (int): The maximum number of items to
419
+ return per page.
420
+ page (int): Which page to return.
421
+ include_all (bool): If true, include all results
422
+ (i.e. do not paginate).
423
+
424
+ Returns:
425
+ IndexResult
426
+ """
427
+ _op = fresh_operation("list_attachment_versions")
428
+ _op["method"] = "GET"
429
+ _op["path"] = (
430
+ "/sheets/"
431
+ + str(sheet_id)
432
+ + "/attachments/"
433
+ + str(attachment_id)
434
+ + "/versions"
435
+ )
436
+ _op["query_params"]["pageSize"] = page_size
437
+ _op["query_params"]["page"] = page
438
+ _op["query_params"]["includeAll"] = include_all
439
+
440
+ expected = ["IndexResult", "Attachment"]
441
+
442
+ prepped_request = self._base.prepare_request(_op)
443
+ response = self._base.request(prepped_request, expected, _op)
444
+
445
+ return response
446
+
447
+ def list_discussion_attachments(
448
+ self, sheet_id, discussion_id, page_size=None, page=None, include_all=None
449
+ ):
450
+ """Get a list of Attachments for the Sheet Discussion.
451
+
452
+ Get a list of all Attachments for the specified Sheet
453
+ Discussion.
454
+
455
+ Args:
456
+ sheet_id (int): Sheet ID
457
+ discussion_id (int): Discussion ID
458
+ page_size (int): The maximum number of items to
459
+ return per page.
460
+ page (int): Which page to return.
461
+ include_all (bool): If true, include all results
462
+ (i.e. do not paginate).
463
+
464
+ Returns:
465
+ IndexResult
466
+ """
467
+ _op = fresh_operation("list_discussion_attachments")
468
+ _op["method"] = "GET"
469
+ _op["path"] = (
470
+ "/sheets/"
471
+ + str(sheet_id)
472
+ + "/discussions/"
473
+ + str(discussion_id)
474
+ + "/attachments"
475
+ )
476
+ _op["query_params"]["pageSize"] = page_size
477
+ _op["query_params"]["page"] = page
478
+ _op["query_params"]["includeAll"] = include_all
479
+
480
+ expected = ["IndexResult", "Attachment"]
481
+
482
+ prepped_request = self._base.prepare_request(_op)
483
+ response = self._base.request(prepped_request, expected, _op)
484
+
485
+ return response
486
+
487
+ def list_row_attachments(
488
+ self, sheet_id, row_id, page_size=None, page=None, include_all=None
489
+ ):
490
+ """Get a list of all Attachments for the specified Sheet Row.
491
+
492
+ Args:
493
+ sheet_id (int): Sheet ID
494
+ row_id (int): Row ID
495
+ page_size (int): The maximum number of items to
496
+ return per page.
497
+ page (int): Which page to return.
498
+ include_all (bool): If true, include all results
499
+ (i.e. do not paginate).
500
+
501
+ Returns:
502
+ IndexResult
503
+ """
504
+ _op = fresh_operation("list_row_attachments")
505
+ _op["method"] = "GET"
506
+ _op["path"] = (
507
+ "/sheets/" + str(sheet_id) + "/rows/" + str(row_id) + "/attachments"
508
+ )
509
+ _op["query_params"]["pageSize"] = page_size
510
+ _op["query_params"]["page"] = page
511
+ _op["query_params"]["includeAll"] = include_all
512
+
513
+ expected = ["IndexResult", "Attachment"]
514
+
515
+ prepped_request = self._base.prepare_request(_op)
516
+ response = self._base.request(prepped_request, expected, _op)
517
+
518
+ return response
519
+
520
+ def download_attachment(
521
+ self, attachment_obj, download_path, alternate_file_name=None
522
+ ):
523
+ """Download the specified attachment as a file.
524
+
525
+ This method wraps the Requests module and performs
526
+ a streaming file download to the specified location.
527
+
528
+ Args:
529
+ attachment_obj (Attachment): Attachment object
530
+ download_path (str): Directory path on local
531
+ machine to save file.
532
+ alternate_file_name (str): Filename to use
533
+ instead of name suggested by Content-Disposition.
534
+
535
+ Returns:
536
+ DownloadedFile
537
+ """
538
+ if not os.path.isdir(download_path):
539
+ raise ValueError("download_path must be a directory.")
540
+
541
+ resp = requests.get(attachment_obj.url, stream=True)
542
+
543
+ if 200 <= resp.status_code <= 299:
544
+ response = DownloadedFile(
545
+ {
546
+ "result_code": 0,
547
+ "message": "SUCCESS",
548
+ "resp": resp,
549
+ "filename": attachment_obj.name,
550
+ "download_directory": download_path,
551
+ }
552
+ )
553
+
554
+ if alternate_file_name is not None:
555
+ response.filename = alternate_file_name
556
+
557
+ response.save_to_file()
558
+ return response
559
+ else:
560
+ return Error(
561
+ {
562
+ "result": ErrorResult({"status_code": resp.status_code}),
563
+ "request_response": resp,
564
+ }
565
+ )