Skip to content

Commit 895f09c

Browse files
lukaszsocha2DaveSawyer
authored andcommitted
feat: Add vanity_name param for creating shared link to a file or folder (box#637)
Closes: SDK-1815
1 parent cb0bf6c commit 895f09c

File tree

8 files changed

+60
-18
lines changed

8 files changed

+60
-18
lines changed

HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Next release
99
**New Features and Enhancements:**
1010

1111
- Add `admin_logs_streaming` support for events stream (`#623 <https://github.com/box/box-python-sdk/pull/623>`_)
12+
- Add `vanity_name` param for creating shared link to a file or folder (`#637 <https://github.com/box/box-python-sdk/pull/637>`_)
1213

1314
2.13.0 (2021-09-30)
1415
++++++++

boxsdk/object/file.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ def get_shared_link_download_url(
430430
unshared_at=None,
431431
allow_preview=None,
432432
password=None,
433+
vanity_name=None
433434
):
434435
"""
435436
Get a shared link download url for the file with the given access permissions.
@@ -461,6 +462,11 @@ def get_shared_link_download_url(
461462
Please notice that this is a premium feature, which might not be available to your app.
462463
:type password:
463464
`unicode` or None
465+
:param vanity_name:
466+
Defines a custom vanity name to use in the shared link URL, eg. https://app.box.com/v/my-custom-vanity-name.
467+
If this parameter is None, the standard shared link URL will be used.
468+
:type vanity_name:
469+
`unicode` or None
464470
:returns:
465471
The URL of the shared link that allows direct download.
466472
:rtype:
@@ -473,6 +479,7 @@ def get_shared_link_download_url(
473479
unshared_at=unshared_at,
474480
allow_preview=allow_preview,
475481
password=password,
482+
vanity_name=vanity_name
476483
)
477484
return item.shared_link['download_url'] # pylint:disable=no-member
478485

boxsdk/object/item.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ def create_shared_link(
219219
allow_download=None,
220220
allow_preview=None,
221221
password=None,
222+
vanity_name=None
222223
):
223224
"""
224225
Create a shared link for the item with the given access permissions.
@@ -254,6 +255,11 @@ def create_shared_link(
254255
Please notice that this is a premium feature, which might not be available to your app.
255256
:type password:
256257
`unicode` or None
258+
:param vanity_name:
259+
Defines a custom vanity name to use in the shared link URL, eg. https://app.box.com/v/my-custom-vanity-name.
260+
If this parameter is None, the standard shared link URL will be used.
261+
:type vanity_name:
262+
`unicode` or None
257263
:return:
258264
The updated object with s shared link.
259265
Returns a new object of the same type, without modifying the original object passed as self.
@@ -280,6 +286,9 @@ def create_shared_link(
280286
if password is not None:
281287
data['shared_link']['password'] = password
282288

289+
if vanity_name is not None:
290+
data['shared_link']['vanity_name'] = vanity_name
291+
283292
return self.update_info(data, etag=etag)
284293

285294
@api_call
@@ -291,6 +300,7 @@ def get_shared_link(
291300
allow_download=None,
292301
allow_preview=None,
293302
password=None,
303+
vanity_name=None
294304
):
295305
"""
296306
Get a shared link for the item with the given access permissions.
@@ -325,6 +335,11 @@ def get_shared_link(
325335
Please notice that this is a premium feature, which might not be available to your app.
326336
:type password:
327337
`unicode` or None
338+
:param vanity_name:
339+
Defines a custom vanity name to use in the shared link URL, eg. https://app.box.com/v/my-custom-vanity-name.
340+
If this parameter is None, the standard shared link URL will be used.
341+
:type vanity_name:
342+
`unicode` or None
328343
:returns:
329344
The URL of the shared link.
330345
:rtype:
@@ -338,6 +353,7 @@ def get_shared_link(
338353
allow_download=allow_download,
339354
allow_preview=allow_preview,
340355
password=password,
356+
vanity_name=vanity_name
341357
)
342358
return item.shared_link['url'] # pylint:disable=no-member
343359

docs/usage/files.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ file's contents, upload new versions, and perform other common file operations
3434
- [Delete a Previous Version of a File](#delete-a-previous-version-of-a-file)
3535
- [Lock a File](#lock-a-file)
3636
- [Unlock a File](#unlock-a-file)
37-
- [Create a Shared Link](#create-a-shared-link)
37+
- [Create a Shared Link Download URL](#create-a-shared-link-download-url)
3838
- [Find a File for a Shared Link](#find-a-file-for-a-shared-link)
39-
- [Create a Shared Link](#create-a-shared-link-1)
39+
- [Create a Shared Link](#create-a-shared-link)
4040
- [Update a Shared Link](#update-a-shared-link)
4141
- [Get a Shared Link](#get-a-shared-link)
4242
- [Remove a Shared Link](#remove-a-shared-link)
@@ -627,23 +627,24 @@ print('File "{0}" has been unlocked!'.format(updated_file.name))
627627

628628
[unlock]: https://box-python-sdk.readthedocs.io/en/latest/boxsdk.object.html#boxsdk.object.file.File.unlock
629629

630-
Create a Shared Link
630+
Create a Shared Link Download URL
631631
--------------------
632632

633633
A shared link for a file can be generated by calling
634-
[`file.get_shared_link(access=None, etag=None, unshared_at=None, allow_download=None, allow_preview=None, password=None)`][get_shared_link].
634+
[`file.get_shared_link(access=None, etag=None, unshared_at=None, allow_download=None, allow_preview=None,
635+
password=None, vanity_name=None)`][get_shared_link_download_url].
635636
This method returns a `unicode` string containing the shared link URL.
636637

637638
<!-- sample put_files_id add_shared_link -->
638639
```python
639640
file_id = '11111'
640641

641-
url = client.file(file_id).get_shared_link()
642-
print('The file shared link URL is: {0}'.format(url))
642+
url = client.file(file_id).get_shared_link_download_url(access='open', vanity_name="my-unique-vanity-name")
643+
print('The file shared link download URL is: {0}'.format(url))
643644
```
644645

645-
[get_shared_link]:
646-
https://box-python-sdk.readthedocs.io/en/latest/boxsdk.object.html#boxsdk.object.item.Item.get_shared_link
646+
[get_shared_link_download_url]:
647+
https://box-python-sdk.readthedocs.io/en/latest/boxsdk.object.html#boxsdk.object.file.File.get_shared_link_download_url
647648

648649
Find a File for a Shared Link
649650
-----------------------------
@@ -661,7 +662,8 @@ Create a Shared Link
661662
--------------------
662663

663664
A shared link for a file can be generated by calling
664-
[`file.get_shared_link(access=None, etag=None, unshared_at=None, allow_download=None, allow_preview=None, password=None)`][get_shared_link].
665+
[`file.get_shared_link(access=None, etag=None, unshared_at=None, allow_download=None, allow_preview=None,
666+
password=None, vanity_name=None)`][get_shared_link].
665667
This method returns a `unicode` string containing the shared link URL.
666668

667669
<!-- sample put_files_id add_shared_link -->
@@ -678,8 +680,8 @@ Update a Shared Link
678680
--------------------
679681

680682
A shared link for a file can be updated by calling
681-
[`file.get_shared_link(access=None, etag=None, unshared_at=None,
682-
allow_download=None, allow_preview=None, password=None)`][update_shared_link]
683+
[`file.get_shared_link(access=None, etag=None, unshared_at=None, allow_download=None, allow_preview=None,
684+
password=None, vanity_name=None)`][update_shared_link]
683685
with an updated list of properties.
684686

685687
This method returns a `unicode` string containing the shared link URL.

docs/usage/folders.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,17 @@ folder = client.get_shared_item('https://app.box.com/s/gjasdasjhasd', password='
195195
Create a Shared Link
196196
--------------------
197197

198-
A shared link for a file can be generated by calling
199-
[`file.get_shared_link(access=None, etag=None, unshared_at=None, allow_download=None, allow_preview=None, password=None)`][get_shared_link].
198+
A shared link for a folder can be generated by calling
199+
[`folder.get_shared_link(access=None, etag=None, unshared_at=None, allow_download=None, allow_preview=None,
200+
password=None, vanity_name=None)`][get_shared_link].
200201
This method returns a `unicode` string containing the shared link URL.
201202

202203
<!-- sample put_folders_id add_shared_link -->
203204
```python
204-
file_id = '11111'
205+
folder_id = '11111'
205206

206-
url = client.file(file_id).get_shared_link(access='open', allow_download=False)
207-
print('The file shared link URL is: {0}'.format(url))
207+
url = client.folder(folder_id).get_shared_link(access='open', allow_download=False)
208+
print('The folder shared link URL is: {0}'.format(url))
208209
```
209210

210211
[get_shared_link]: https://box-python-sdk.readthedocs.io/en/latest/boxsdk.object.html#boxsdk.object.item.Item.get_shared_link
@@ -213,8 +214,8 @@ Update a Shared Link
213214
--------------------
214215

215216
A shared link for a folder can be updated by calling
216-
[`folder.get_shared_link(access=None, etag=None, unshared_at=None,
217-
allow_download=None, allow_preview=None, password=None)`][update_shared_link]
217+
[`folder.get_shared_link(access=None, etag=None, unshared_at=None, allow_download=None, allow_preview=None,
218+
password=None, vanity_name=None)`][update_shared_link]
218219
with an updated list of properties.
219220

220221
This method returns a `unicode` string containing the shared link URL.

test/unit/object/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@ def shared_link_unshared_at(request):
369369
return request.param
370370

371371

372+
@pytest.fixture(params=('my-custom-vanity-name', None))
373+
def shared_link_vanity_name(request):
374+
return request.param
375+
376+
372377
@pytest.fixture(params=[
373378
# Test case for plain message
374379
(

test/unit/object/test_file.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ def test_get_shared_link_download_url(
580580
shared_link_unshared_at,
581581
shared_link_password,
582582
shared_link_can_preview,
583+
shared_link_vanity_name,
583584
test_url,
584585
etag,
585586
if_match_header,
@@ -606,12 +607,16 @@ def test_get_shared_link_download_url(
606607
permissions['can_preview'] = shared_link_can_preview
607608
if shared_link_password is not None:
608609
expected_data['shared_link']['password'] = shared_link_password
610+
if shared_link_vanity_name is not None:
611+
expected_data['shared_link']['vanity_name'] = shared_link_vanity_name
612+
609613
url = test_file.get_shared_link_download_url(
610614
etag=etag,
611615
access=shared_link_access,
612616
unshared_at=shared_link_unshared_at,
613617
password=shared_link_password,
614618
allow_preview=shared_link_can_preview,
619+
vanity_name=shared_link_vanity_name,
615620
)
616621
mock_box_session.put.assert_called_once_with(
617622
expected_url,

test/unit/object/test_item.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def test_get_shared_link(
133133
shared_link_password,
134134
shared_link_can_download,
135135
shared_link_can_preview,
136+
shared_link_vanity_name,
136137
test_url,
137138
etag,
138139
if_match_header,
@@ -160,13 +161,17 @@ def test_get_shared_link(
160161
permissions['can_preview'] = shared_link_can_preview
161162
if shared_link_password is not None:
162163
expected_data['shared_link']['password'] = shared_link_password
164+
if shared_link_vanity_name is not None:
165+
expected_data['shared_link']['vanity_name'] = shared_link_vanity_name
166+
163167
url = test_item.get_shared_link(
164168
etag=etag,
165169
access=shared_link_access,
166170
unshared_at=shared_link_unshared_at,
167171
password=shared_link_password,
168172
allow_download=shared_link_can_download,
169173
allow_preview=shared_link_can_preview,
174+
vanity_name=shared_link_vanity_name,
170175
)
171176
mock_box_session.put.assert_called_once_with(
172177
expected_url,

0 commit comments

Comments
 (0)