Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
file 313 lines (155 sloc) 8.596 kb
  • class onedrive.api_v5.OneDriveHTTPClient

    Bases: "object"

    • request(url, method='get', data=None, files=None, raw=False, headers={}, raise_for={}, session=None)

      Make synchronous HTTP request.

      Can be overidden to use different http module (e.g. urllib2, twisted, etc).

  • class onedrive.api_v5.OneDriveAuth(**config)

    Bases: "onedrive.api_v5.OneDriveHTTPClient"

    • client_id = None

      Client id/secret should be static on per-application basis.

      Can be received from LiveConnect by any registered user at https://manage.dev.live.com/

      API ToS can be found at http://msdn.microsoft.com/en-US/library/live/ff765012

    • client_secret = None

      Client id/secret should be static on per-application basis.

      Can be received from LiveConnect by any registered user at https://manage.dev.live.com/

      API ToS can be found at http://msdn.microsoft.com/en-US/library/live/ff765012

    • auth_url_user = 'https://login.live.com/oauth20_authorize.srf'

    • auth_url_token = 'https://login.live.com/oauth20_token.srf'

    • auth_scope = ('wl.skydrive', 'wl.skydrive_update', 'wl.offline_access')

    • auth_redirect_uri_mobile = 'https://login.live.com/oauth20_desktop.srf'

    • auth_access_expires = None

      Set by auth_get_token() method, not used internally.

      Might be useful for debugging or extension purposes.

    • auth_access_data_raw = None

      Set by auth_get_token() method, not used internally.

      Might be useful for debugging or extension purposes.

    • auth_code = None

      At least one of auth_code, auth_refresh_token or auth_access_token should be set before data requests.

    • auth_refresh_token = None

      At least one of auth_code, auth_refresh_token or auth_access_token should be set before data requests.

    • auth_access_token = None

      At least one of auth_code, auth_refresh_token or auth_access_token should be set before data requests.

    • auth_redirect_uri = 'https://login.live.com/oauth20_desktop.srf'

      This (default) redirect_uri is special - app must be marked as "mobile" to use it.

    • __init__(**config)

      Initialize API wrapper class with specified properties set.

    • auth_user_get_url(scope=None)

      Build authorization URL for User Agent.

    • auth_user_process_url(url)

      Process tokens and errors from redirect_uri.

    • auth_get_token(check_scope=True)

      Refresh or acquire access_token.

  • class onedrive.api_v5.OneDriveAPIWrapper(**config)

    Bases: "onedrive.api_v5.OneDriveAuth"

    Less-biased OneDrive API wrapper class.

    All calls made here return result of self.request() call directly, so it can easily be made async (e.g. return twisted deferred object) by overriding http request method in subclass.

    • api_url_base = 'https://apis.live.net/v5.0/'

    • __call__(url='me/skydrive', query={}, query_filter=True, auth_header=False, auto_refresh_token=True, **request_kwz)

      Make an arbitrary call to LiveConnect API.

      Shouldn't be used directly under most circumstances.

    • get_quota()

      Get OneDrive object, representing quota.

    • listdir(folder_id='me/skydrive', limit=None)

      Get OneDrive object, representing list of objects in a folder.

    • info(obj_id='me/skydrive')

      Return metadata of a specified object.

      See http://msdn.microsoft.com/en-us/library/live/hh243648.aspx for the list and description of metadata keys for each object type.

    • get(obj_id, byte_range=None)

      Download and return a file object or a specified byte_range from it.

      See HTTP Range header (rfc2616) for possible byte_range formats,

      Examples: "0-499" - byte offsets 0-499 (inclusive), "-500" - final 500 bytes.

    • put(path_or_tuple, folder_id='me/skydrive', overwrite=True)

      Upload a file (object), possibly overwriting (default behavior) a file with the same "name" attribute, if it exists.

      First argument can be either path to a local file or tuple of "(name, file)", where "file" can be either a file-like object or just a string of bytes.

      overwrite option can be set to False to allow two identically- named files or "ChooseNewName" to let OneDrive derive some similar unique name. Behavior of this option mimics underlying API.

    • mkdir(name=None, folder_id='me/skydrive', metadata={})

      Create a folder with a specified "name" attribute.

      folder_id allows to specify a parent folder. metadata mapping may contain additional folder properties to pass to an API.

    • delete(obj_id)

      Delete specified object.

    • info_update(obj_id, data)

      Update metadata with of a specified object.

      See http://msdn.microsoft.com/en-us/library/live/hh243648.aspx for the list of RW keys for each object type.

    • link(obj_id, link_type='shared_read_link')

      Return a preauthenticated (usable by anyone) link to a specified object. Object will be considered "shared" by OneDrive, even if link is never actually used.

      link_type can be either "embed" (returns html), "shared_read_link" or "shared_edit_link".

    • copy(obj_id, folder_id, move=False)

      Copy specified file (object) to a folder with a given ID. Well- known folder names (like "me/skydrive") don't seem to work here.

      Folders cannot be copied; this is an API limitation.

    • move(obj_id, folder_id)

      Move specified file (object) to a folder.

      Note that folders cannot be moved, this is API limitation.

    • comments(obj_id)

      Get OneDrive object, representing a list of comments for an object.

    • comment_add(obj_id, message)

      Add comment message to a specified object.

    • comment_delete(comment_id)

      Delete specified comment.

      comment_id can be acquired by listing comments for an object.

  • class onedrive.api_v5.OneDriveAPI(**config)

    Bases: "onedrive.api_v5.OneDriveAPIWrapper"

    Biased synchronous OneDrive API interface.

    Adds some derivative convenience methods over OneDriveAPIWrapper.

    • resolve_path(path, root_id='me/skydrive', objects=False)

      Return id (or metadata) of an object, specified by chain (iterable or fs-style path string) of "name" attributes of its ancestors, or raises DoesNotExists error.

      Requires many calls to resolve each name in path, so use with care. root_id parameter allows to specify path relative to some folder_id (default: me/skydrive).

    • get_quota()

      Return tuple of (bytes_available, bytes_quota).

    • listdir(folder_id='me/skydrive', type_filter=None, limit=None)

      Return a list of objects in the specified folder_id.

      limit is passed to the API, so might be used as optimization.

      type_filter can be set to type (str) or sequence of object types to return, post-api-call processing.

    • copy(obj_id, folder_id, move=False)

      Copy specified file (object) to a folder.

      Note that folders cannot be copied, this is API limitation.

    • comments(obj_id)

      Get a list of comments (message + metadata) for an object.

  • class onedrive.api_v5.PersistentOneDriveAPI(**config)

    Bases: "onedrive.api_v5.OneDriveAPI", "onedrive.conf.ConfigMixin"

    • conf_path_default = '~/.lcrc'

    • conf_update_keys = {'client': set(['secret', 'id']), 'auth': set(['access_token', 'code', 'access_expires', 'refresh_token'])}

    • classmethod from_conf(path=None, **overrides)

      Initialize instance from YAML configuration file, writing updates (only to keys, specified by "conf_update_keys") back to it.

  • exception onedrive.api_v5.OneDriveInteractionError

    Bases: "exceptions.Exception"

  • exception onedrive.api_v5.ProtocolError(code, msg)

    Bases: "onedrive.api_v5.OneDriveInteractionError"

    • __init__(code, msg)
  • exception onedrive.api_v5.AuthenticationError

    Bases: "onedrive.api_v5.OneDriveInteractionError"

  • exception onedrive.api_v5.DoesNotExists

    Bases: "onedrive.api_v5.OneDriveInteractionError"

    Only raised from OneDriveAPI.resolve_path().

Something went wrong with that request. Please try again.