diff --git a/boxsdk/object/item.py b/boxsdk/object/item.py index 2a7d9f017..38835463a 100644 --- a/boxsdk/object/item.py +++ b/boxsdk/object/item.py @@ -159,7 +159,7 @@ def move(self, parent_folder): } return self.update_info(data) - def get_shared_link(self, access=None, etag=None, unshared_at=None, allow_download=None, allow_preview=None): + def get_shared_link(self, access=None, etag=None, unshared_at=None, allow_download=None, allow_preview=None, password=None): """Get a shared link for the item with the given access permissions. :param access: @@ -186,6 +186,11 @@ def get_shared_link(self, access=None, etag=None, unshared_at=None, allow_downlo If this parameter is None, the default setting will be used. :type allow_preview: `bool` or None + :param password: + The password required to view this link. If no password is specified then no password will be set. + Please notice that this is a premium feature, which might not be available to your app. + :type password: + `unicode` or None :returns: The URL of the shared link. :rtype: @@ -208,6 +213,9 @@ def get_shared_link(self, access=None, etag=None, unshared_at=None, allow_downlo if allow_preview is not None: permissions['can_preview'] = allow_preview + if password is not None: + data['shared_link']['password'] = password + item = self.update_info(data, etag=etag) return item.shared_link['url'] diff --git a/test/unit/object/test_item.py b/test/unit/object/test_item.py index 4b485c6e3..5a468ed77 100644 --- a/test/unit/object/test_item.py +++ b/test/unit/object/test_item.py @@ -71,6 +71,11 @@ def shared_link_access(request): return request.param +@pytest.fixture(params=('hunter2', None)) +def shared_link_password(request): + return request.param + + @pytest.fixture(params=(date(2015, 5, 5), None)) def shared_link_unshared_at(request): return request.param @@ -81,6 +86,7 @@ def test_get_shared_link( mock_box_session, shared_link_access, shared_link_unshared_at, + shared_link_password, shared_link_can_download, shared_link_can_preview, test_url, @@ -96,6 +102,8 @@ def test_get_shared_link( expected_data['shared_link']['access'] = shared_link_access if shared_link_unshared_at is not None: expected_data['shared_link']['unshared_at'] = shared_link_unshared_at.isoformat() + if shared_link_password is not None: + expected_data['shared_link']['password'] = shared_link_password if shared_link_can_download is not None or shared_link_can_preview is not None: expected_data['shared_link']['permissions'] = permissions = {} if shared_link_can_download is not None: @@ -106,6 +114,7 @@ def test_get_shared_link( etag=etag, access=shared_link_access, unshared_at=shared_link_unshared_at, + password=shared_link_password, allow_download=shared_link_can_download, allow_preview=shared_link_can_preview, )