How to use the boxsdk.object.base_object.BaseObject function in boxsdk

To help you get started, we’ve selected a few boxsdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github box / box-python-sdk / test / unit / object / test_base_object.py View on Github external
def test_delete_handles_params_and_headers_correctly(mock_box_session, make_mock_box_request, params, headers, success):
    # pylint:disable=redefined-outer-name, protected-access
    fake_id = 'a_fake_id'
    base_object = BaseObject(mock_box_session, fake_id)

    mock_box_response, _ = make_mock_box_request(response_ok=success)
    mock_box_session.delete.return_value = mock_box_response
    expected_url = '{0}/{1}s/{2}'.format(API.BASE_API_URL, None, fake_id)
    update_response = base_object.delete(params=params, headers=headers)
    mock_box_session.delete.assert_called_once_with(
        expected_url,
        expect_json_response=False,
        params=params or {},
        headers=headers,
    )
    assert update_response is success
github box / box-python-sdk / boxsdk / object / upload_session.py View on Github external
# coding: utf-8
from __future__ import unicode_literals, absolute_import

import base64
import hashlib
import json
import os

from boxsdk.util.chunked_uploader import ChunkedUploader
from .base_object import BaseObject
from ..pagination.limit_offset_based_dict_collection import LimitOffsetBasedDictCollection


class UploadSession(BaseObject):
    _item_type = 'upload_session'
    _parent_item_type = 'file'

    def get_url(self, *args):
        """
        Base class override. Endpoint is a little different - it's /files/upload_sessions.

        :rtype:
            `unicode`
        """
        return self._session.get_url(
            '{0}s/{1}s'.format(self._parent_item_type, self._item_type),
            self._object_id,
            *args
        ).replace(self.session.api_config.BASE_API_URL, self.session.api_config.UPLOAD_URL)
github box / box-python-sdk / boxsdk / object / legal_hold_policy.py View on Github external
# coding: utf-8
from __future__ import unicode_literals

import json

from .base_object import BaseObject
from ..pagination.marker_based_object_collection import MarkerBasedObjectCollection
from ..util.api_call_decorator import api_call


class LegalHoldPolicy(BaseObject):
    """Represents a Box legal_hold_policy"""

    _item_type = 'legal_hold_policy'

    def get_url(self, *args):
        return self._session.get_url('legal_hold_policies', self._object_id, *args)

    @api_call
    def assign(self, assignee):
        """Assign legal hold policy

        :param assignee:
            The `file_version`, `file`, `folder`, or `user` to assign the legal hold policy to.
        :type assignee:
            :class:`FileVersion` :class:`File` or :class:`Folder` or :class:`User`
        :returns:
github box / box-python-sdk / boxsdk / object / enterprise.py View on Github external
# coding: utf-8
from __future__ import unicode_literals, absolute_import

import json

from .base_object import BaseObject
from ..util.api_call_decorator import api_call


class Enterprise(BaseObject):

    """Represents a single enterprise."""
    _item_type = 'enterprise'

    @api_call
    def invite_user(self, user_email):
        """
        Invites an existing user to an Enterprise. The user must already have a Box account.

        :param user_email:
            The login email address of the user that will receive the invitation.
        :type user_email:
            `unicode`
        :returns:
            The invitation record for the user
        :rtype:
github box / box-python-sdk / boxsdk / object / group.py View on Github external
import json

from boxsdk.util.text_enum import TextEnum
from .base_object import BaseObject
from ..pagination.limit_offset_based_object_collection import LimitOffsetBasedObjectCollection
from ..util.api_call_decorator import api_call
from ..util.default_arg_value import SDK_VALUE_NOT_SET


class GroupRole(TextEnum):
    """The role in the group."""
    ADMIN = 'admin'
    MEMBER = 'member'


class Group(BaseObject):
    """Represents a Box group."""

    _item_type = 'group'

    @api_call
    def get_memberships(self, limit=None, offset=None, fields=None):
        """
        Get the membership records for the group, which indicate which users are included in the group.

        :param offset:
            The index at which to begin.
        :type offset:
            `int` or None
        :param limit:
            The maximum number of items to return in a page.
        :type limit:
github box / box-python-sdk / boxsdk / object / webhook.py View on Github external
# coding: utf-8
from __future__ import unicode_literals

from .base_object import BaseObject


class Webhook(BaseObject):
    """Represents a Box Webhook."""

    _item_type = 'webhook'
github box / box-python-sdk / boxsdk / object / item.py View on Github external
from .metadata import Metadata
from ..util.api_call_decorator import api_call
from ..util.default_arg_value import SDK_VALUE_NOT_SET
from ..pagination.marker_based_dict_collection import MarkerBasedDictCollection
from ..pagination.marker_based_object_collection import MarkerBasedObjectCollection


class ClassificationType(TextEnum):
    """An enum of possible classification types"""
    PUBLIC = 'Public'
    INTERNAL = 'Internal'
    CONFIDENTIAL = 'Confidential'
    NONE = 'None'


class Item(BaseObject):
    """Box API endpoint for interacting with files and folders."""

    _classification_template_key = 'securityClassification-6VMVochwUWo'

    def _get_accelerator_upload_url(self, file_id=None):
        """
        Make an API call to get the Accelerator upload url for either upload a new file or updating an existing file.

        :param file_id:
            Box id of the file to be uploaded. Not required for new file uploads.
        :type file_id:
            `unicode` or None
        :return:
            The Accelerator upload url or None if cannot get the Accelerator upload url.
        :rtype:
            `unicode` or None
github box / box-python-sdk / boxsdk / object / user.py View on Github external
# coding: utf-8
from __future__ import unicode_literals

import json

from .base_object import BaseObject
from ..pagination.limit_offset_based_object_collection import LimitOffsetBasedObjectCollection
from ..pagination.marker_based_object_collection import MarkerBasedObjectCollection
from ..util.api_call_decorator import api_call


class User(BaseObject):
    """Represents a Box user."""

    _item_type = 'user'

    @api_call
    def add_email_alias(self, email):
        """
        Adds a new email alias to the given user's account.

        :param email:
            The email alias to add to the user.
        :type email:
            `unicode`
        :returns:
            The new email alias object
        :rtype:
github box / box-python-sdk / boxsdk / object / base_object.py View on Github external
def get_url(self, *args):
        """
        Base class override.
        Return the given object's URL, appending any optional parts as specified by args.
        """
        # pylint:disable=arguments-differ
        return super(BaseObject, self).get_url('{0}s'.format(self._item_type), self._object_id, *args)
github box / box-python-sdk / boxsdk / object / base_object.py View on Github external
def __eq__(self, other):
        """Equality as determined by object id and type"""
        if isinstance(other, BaseObject):
            # Two objects are considered the same if they have the same address in the API
            return self.get_url() == other.get_url()

        return NotImplemented