Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use drivewsid and zone that work for app folders #417

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions pyicloud/services/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_node_data(self, node_id):
data=json.dumps(
[
{
"drivewsid": "FOLDER::com.apple.CloudDocs::%s" % node_id,
"drivewsid": node_id,
"partialData": False,
}
]
Expand All @@ -51,12 +51,12 @@ def get_node_data(self, node_id):
self._raise_if_error(request)
return request.json()[0]

def get_file(self, file_id, **kwargs):
def get_file(self, file_id, zone, **kwargs):
"""Returns iCloud Drive file."""
file_params = dict(self.params)
file_params.update({"document_id": file_id})
response = self.session.get(
self._document_root + "/ws/com.apple.CloudDocs/download/by_id",
self._document_root + ("/ws/%s/download/by_id" % zone),
params=file_params,
)
self._raise_if_error(response)
Expand All @@ -72,7 +72,8 @@ def get_file(self, file_id, **kwargs):
def get_app_data(self):
"""Returns the app library (previously ubiquity)."""
request = self.session.get(
self._service_root + "/retrieveAppLibraries", params=self.params
self._service_root + "/retrieveAppLibraries",
params=self.params
)
self._raise_if_error(request)
return request.json()["items"]
Expand Down Expand Up @@ -220,7 +221,7 @@ def move_items_to_trash(self, node_id, etag):
def root(self):
"""Returns the root node."""
if not self._root:
self._root = DriveNode(self, self.get_node_data("root"))
self._root = DriveNode(self, self.get_node_data("FOLDER::com.apple.CloudDocs::root"))
return self._root

def __getattr__(self, attr):
Expand Down Expand Up @@ -263,7 +264,7 @@ def get_children(self):
"""Gets the node children."""
if not self._children:
if "items" not in self.data:
self.data.update(self.connection.get_node_data(self.data["docwsid"]))
self.data.update(self.connection.get_node_data(self.data["drivewsid"]))
if "items" not in self.data:
raise KeyError("No items in folder, status: %s" % self.data["status"])
self._children = [
Expand Down Expand Up @@ -302,11 +303,11 @@ def open(self, **kwargs):
response = Response()
response.raw = io.BytesIO()
return response
return self.connection.get_file(self.data["docwsid"], **kwargs)
return self.connection.get_file(self.data["docwsid"], self.data["zone"], **kwargs)

def upload(self, file_object, **kwargs):
"""Upload a new file."""
return self.connection.send_file(self.data["docwsid"], file_object, **kwargs)
return self.connection.send_file(self.data["drivewsid"], file_object, **kwargs)

def dir(self):
"""Gets the node list of directories."""
Expand Down