acdcli.api package¶
Submodules¶
acdcli.api.account module¶
ACD account information
acdcli.api.backoff_req module¶
-
class
acdcli.api.backoff_req.
BackOffRequest
(auth_callback: 'requests.auth.AuthBase', timeout: 'Tuple[int, int]', proxies: dict={})[source]¶ Bases:
object
Wrapper for requests that implements timed back-off algorithm https://developer.amazon.com/public/apis/experience/cloud-drive/content/best-practices Caution: this catches all connection errors and may stall for a long time. It is necessary to init this module before use.
-
__init__
(auth_callback: 'requests.auth.AuthBase', timeout: 'Tuple[int, int]', proxies: dict={})[source]¶ Parameters: - auth_callback – callable object that attaches auth info to a request
- timeout – tuple of connection timeout and idle timeout (http://docs.python-requests.org/en/latest/user/advanced/#timeouts)
- proxies – dict of protocol to proxy, see http://docs.python-requests.org/en/master/user/advanced/#proxies
-
acdcli.api.client module¶
acdcli.api.common module¶
-
exception
acdcli.api.common.
RequestError
(status_code: int, msg: str)[source]¶ Bases:
Exception
Catch-all exception class for various connection and ACD server errors.
-
class
CODE
[source]¶ Bases:
object
-
CONN_EXCEPTION
= 1000¶
-
FAILED_SUBREQUEST
= 1002¶
-
INCOMPLETE_RESULT
= 1003¶
-
INVALID_TOKEN
= 1005¶
-
REFRESH_FAILED
= 1004¶
-
-
RequestError.
codes
= <lookup 'status_codes'>¶
-
class
acdcli.api.content module¶
acdcli.api.metadata module¶
Node metadata operations
-
acdcli.api.metadata.
ChangeSet
¶ alias of
Changes
-
class
acdcli.api.metadata.
MetadataMixin
[source]¶ Bases:
object
-
add_child
(parent_id: str, child_id: str) → dict[source]¶ Adds node with ID child_id to folder with ID parent_id.
Returns: updated child node dict
-
add_property
(node_id: str, owner_id: str, key: str, value: str) → dict[source]¶ Adds or overwrites key property with content. Maximum number of keys per owner is 10.
Parameters: value¶ – string of length <= 500 Raises: RequestError: 404, <UnknownOperationException/> if owner is empty RequestError: 400, {...} if maximum of allowed properties is reached Returns dict: {‘key’: ‘<KEY>’, ‘location’: ‘<NODE_ADDRESS>/properties/<OWNER_ID/<KEY>’, ‘value’: ‘<VALUE>’}
-
delete_properties
(node_id: str, owner_id: str)[source]¶ Deletes all of the owner’s properties. Uses multiple requests.
-
delete_property
(node_id: str, owner_id: str, key: str)[source]¶ Deletes key property from node with ID node_id.
-
get_changes
(checkpoint='', include_purged=False, silent=True, file=None)[source]¶ Writes changes into a (temporary) file. See https://developer.amazon.com/public/apis/experience/cloud-drive/content/changes.
-
get_metadata
(node_id: str, assets=False, temp_link=True) → dict[source]¶ Gets a node’s metadata.
Parameters: - assets – also include asset info (e.g. thumbnails) if the node is a file
- temp_link – include a temporary download link if the node is a file
-
get_owner_id
()[source]¶ Provisional function for retrieving the security profile’s name, a.k.a. owner id.
-
list_properties
(node_id: str, owner_id: str) → dict[source]¶ This will always return an empty dict if the accessor is not the owner. :param _sphinx_paramlinks_acdcli.api.metadata.MetadataMixin.list_properties.owner_id: owner ID (return status 404 if empty)
-
acdcli.api.oauth module¶
-
class
acdcli.api.oauth.
AppspotOAuthHandler
(path)[source]¶ Bases:
acdcli.api.oauth.OAuthHandler
-
APPSPOT_URL
= 'https://tensile-runway-92512.appspot.com/'¶
-
-
class
acdcli.api.oauth.
LocalOAuthHandler
(path)[source]¶ Bases:
acdcli.api.oauth.OAuthHandler
A local OAuth handler that works with a whitelisted security profile. The profile must not be created prior to June 2015. Profiles created prior to this month are not able to use the new scope “clouddrive:read_all” that replaces “clouddrive:read”. https://developer.amazon.com/public/apis/experience/cloud-drive/content/getting-started
-
AMAZON_OA_LOGIN_URL
= 'https://amazon.com/ap/oa'¶
-
AMAZON_OA_TOKEN_URL
= 'https://api.amazon.com/auth/o2/token'¶
-
CLIENT_DATA_FILE
= 'client_data'¶
-
REDIRECT_URI
= 'http://localhost'¶
-
-
class
acdcli.api.oauth.
OAuthHandler
(path)[source]¶ Bases:
requests.auth.AuthBase
-
class
KEYS
[source]¶ Bases:
object
-
ACC_TOKEN
= 'access_token'¶
-
EXP_IN
= 'expires_in'¶
-
EXP_TIME
= 'exp_time'¶
-
REDIRECT_URI
= 'redirect_uri'¶
-
REFR_TOKEN
= 'refresh_token'¶
-
-
OAuthHandler.
OAUTH_DATA_FILE
= 'oauth_data'¶
-
OAuthHandler.
check_oauth_file_exists
()[source]¶ Checks for OAuth file existence and one-time initialize if necessary. Throws on error.
-
OAuthHandler.
exp_time
¶
-
OAuthHandler.
get_access_token_info
() → dict[source]¶ Returns: int exp: expiration time in sec, str aud: client id user_id, app_id, iat (exp time)
-
OAuthHandler.
get_auth_token
(reload=True) → str[source]¶ Gets current access token, refreshes if necessary.
Parameters: reload¶ – whether the oauth token file should be reloaded (external update)
-
OAuthHandler.
load_oauth_data
()[source]¶ Loads oauth data file, validate and add expiration time if necessary
-
OAuthHandler.
treat_auth_token
(time_: float)[source]¶ Adds expiration time to member OAuth dict using specified begin time.
-
class
acdcli.api.trash module¶
Node trashing and restoration. https://developer.amazon.com/public/apis/experience/cloud-drive/content/trash
Module contents¶
ACD API¶
Usage¶
from api import client
acd_client = client.ACDClient()
root = acd_client.get_root_id()
children = acd_client.list_children(root)
for child in children:
print(child['name'])
# ...
Node JSON Format¶
This is the usual node JSON format for a file:
{
'contentProperties': {'contentType': 'text/plain',
'extension': 'txt',
'md5': 'd41d8cd98f00b204e9800998ecf8427e',
'size': 0,
'version': 1},
'createdBy': '<security-profile-nm>-<user>',
'createdDate': '2015-01-01T00:00:00.00Z',
'description': '',
'eTagResponse': 'AbCdEfGhI01',
'id': 'AbCdEfGhIjKlMnOpQr0123',
'isShared': False,
'kind': 'FILE',
'labels': [],
'modifiedDate': '2015-01-01T00:00:00.000Z',
'name': 'empty.txt',
'parents': ['0123AbCdEfGhIjKlMnOpQr'],
'restricted': False,
'status': 'AVAILABLE',
'version': 1
}
The modifiedDate
and version
keys get updated each time the content or metadata is updated.
contentProperties['version']
gets updated on overwrite.
A folder’s JSON looks similar, but it lacks the contentProperties
dictionary.
isShared
is set to False
even when a node is actually shared.
Caution
ACD allows hard links for folders!