mirror of
https://github.com/subutux/rmapy.git
synced 2025-12-08 14:43:24 +00:00
Updated documentation
This commit is contained in:
14
rmapi/api.py
14
rmapi/api.py
@@ -31,6 +31,7 @@ class Client(object):
|
||||
token_set: the authentication tokens
|
||||
|
||||
"""
|
||||
|
||||
token_set = {
|
||||
"devicetoken": None,
|
||||
"usertoken": None
|
||||
@@ -63,8 +64,8 @@ class Client(object):
|
||||
Returns:
|
||||
A Response instance containing most likely the response from
|
||||
the server.
|
||||
|
||||
"""
|
||||
|
||||
if not path.startswith("http"):
|
||||
if not path.startswith('/'):
|
||||
path = '/' + path
|
||||
@@ -107,8 +108,8 @@ class Client(object):
|
||||
Raises:
|
||||
AuthError: We didn't recieved an devicetoken from the Remarkable
|
||||
Cloud.
|
||||
|
||||
"""
|
||||
|
||||
uuid = str(uuid4())
|
||||
body = {
|
||||
"code": code,
|
||||
@@ -158,6 +159,7 @@ class Client(object):
|
||||
Returns:
|
||||
bool: True if the client is authenticated
|
||||
"""
|
||||
|
||||
if self.token_set["devicetoken"] and self.token_set["usertoken"]:
|
||||
return True
|
||||
else:
|
||||
@@ -172,8 +174,8 @@ class Client(object):
|
||||
Returns:
|
||||
Collection: a collection of Documents & Folders from the Remarkable
|
||||
Cloud
|
||||
|
||||
"""
|
||||
|
||||
response = self.request("GET", "/document-storage/json/2/docs")
|
||||
collection = Collection()
|
||||
log.debug(response.text)
|
||||
@@ -259,8 +261,8 @@ class Client(object):
|
||||
Args:
|
||||
docorfolder: A document or folder to update the meta information
|
||||
from.
|
||||
|
||||
"""
|
||||
|
||||
req = docorfolder.to_dict()
|
||||
req["Version"] = self.get_current_version(docorfolder) + 1
|
||||
req["ModifiedClient"] = datetime.utcnow().strftime(RFC3339Nano)
|
||||
@@ -284,6 +286,7 @@ class Client(object):
|
||||
DocumentNotFound: cannot find the requested Document or Folder.
|
||||
ApiError: An error occured while processing the request.
|
||||
"""
|
||||
|
||||
try:
|
||||
d = self.get_doc(docorfolder.ID)
|
||||
except DocumentNotFound:
|
||||
@@ -305,8 +308,8 @@ class Client(object):
|
||||
folder: A folder instance.
|
||||
Returns:
|
||||
True if the folder is created.
|
||||
|
||||
"""
|
||||
|
||||
zipFolder, req = folder.create_request()
|
||||
res = self.request("PUT", "/document-storage/json/2/upload/request",
|
||||
body=[req])
|
||||
@@ -341,6 +344,7 @@ class Client(object):
|
||||
Raises:
|
||||
ApiError: When the response contains an error
|
||||
"""
|
||||
|
||||
if response.ok:
|
||||
if len(response.json()) > 0:
|
||||
if response.json()[0]["Success"]:
|
||||
|
||||
@@ -10,9 +10,11 @@ class Collection(object):
|
||||
"""A collection of meta items
|
||||
|
||||
This is basicly the content of the Remarkable Cloud.
|
||||
|
||||
Attributes:
|
||||
items: A list containing the items.
|
||||
"""
|
||||
|
||||
items = []
|
||||
|
||||
def __init__(self, *items):
|
||||
@@ -42,6 +44,7 @@ class Collection(object):
|
||||
Args:
|
||||
docdict: A dict respresenting a document.
|
||||
"""
|
||||
|
||||
self.items.append(Document(**docdict))
|
||||
|
||||
def add_folder(self, dirdict: dict) -> NoReturn:
|
||||
@@ -50,6 +53,7 @@ class Collection(object):
|
||||
Args:
|
||||
dirdict: A dict respresenting a folder.
|
||||
"""
|
||||
|
||||
self.items.append(Folder(**dirdict))
|
||||
|
||||
def parent(self, docorfolder: DocOrFolder) -> Folder:
|
||||
@@ -77,6 +81,7 @@ class Collection(object):
|
||||
Returns:
|
||||
a list of documents an folders.
|
||||
"""
|
||||
|
||||
if folder:
|
||||
return [i for i in self.items if i.Parent == folder.ID]
|
||||
else:
|
||||
|
||||
@@ -4,8 +4,7 @@ from yaml import dump as yml_dump
|
||||
|
||||
|
||||
def load() -> dict:
|
||||
"""Load the .rmapi config file
|
||||
"""
|
||||
"""Load the .rmapi config file"""
|
||||
|
||||
config_file_path = Path.joinpath(Path.home(), ".rmapi")
|
||||
config = {}
|
||||
|
||||
@@ -11,6 +11,7 @@ class ZipFolder(object):
|
||||
|
||||
This is needed to create a folder on the Remarkable Cloud
|
||||
"""
|
||||
|
||||
def __init__(self, ID: str):
|
||||
"""Creates a zipfile in memory
|
||||
|
||||
@@ -64,6 +65,7 @@ class Folder(Document):
|
||||
|
||||
This sets some parameters in the datastructure to submit to the API.
|
||||
"""
|
||||
|
||||
data = self.to_dict()
|
||||
data["Version"] = data.get("Version", 0) + 1
|
||||
data["ModifiedClient"] = datetime.utcnow().strftime(RFC3339Nano)
|
||||
|
||||
Reference in New Issue
Block a user