Skip to content

Commit 2bf6f41

Browse files
authored
Merge pull request #15 from BlockScience/types
Google Drive File, FileAuthor, & Export RIDs
2 parents e0b49ba + af305ea commit 2bf6f41

4 files changed

Lines changed: 98 additions & 1 deletion

File tree

src/rid_lib/types/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@
1010
from .discord_guild import DiscordGuild
1111
from .discord_channel import DiscordChannel
1212
from .discord_message import DiscordMessage
13-
from .discord_user import DiscordUser
13+
from .discord_user import DiscordUser
14+
from .gdrive_file import GoogleDriveFile
15+
from .gdrive_file_authors import GoogleDriveFileAuthors
16+
from .gdrive_export import GoogleDriveExport

src/rid_lib/types/gdrive_export.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from rid_lib.core import ORN
2+
3+
4+
class GoogleDriveExport(ORN):
5+
namespace = 'google_drive.export'
6+
7+
def __init__(self, type: str, subtype: str, fileId: str):
8+
self.type = type
9+
self.subtype = subtype
10+
self.fileId = fileId
11+
12+
@property
13+
def mimeType(self):
14+
return f'{self.type}/{self.subtype}'
15+
16+
@property
17+
def reference(self):
18+
return f'{self.mimeType}/{self.fileId}'
19+
20+
@classmethod
21+
def from_reference(cls, reference):
22+
if type(reference) is str:
23+
components = reference.split("/")
24+
if len(components) == 3:
25+
return cls(*components)
26+
else:
27+
raise ValueError(
28+
"Google Drive File Export reference must contain 3 '/'-separated components: '<type>/<subtype>/<fileId>'"
29+
)
30+
else:
31+
raise ValueError("Google Drive File Export reference must be a string")

src/rid_lib/types/gdrive_file.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from rid_lib.core import ORN
2+
from rid_lib.types.gdrive_export import GoogleDriveExport
3+
4+
5+
class GoogleDriveFile(ORN):
6+
namespace = 'google_drive.file'
7+
mimeType = 'application/vnd.google-apps.file'
8+
9+
def __init__(self, id: str):
10+
self.id = id
11+
12+
@property
13+
def url(self):
14+
return f'https://drive.google.com/file/d/{self.id}'
15+
16+
@property
17+
def export(self, type: str, subtype: str) -> GoogleDriveExport:
18+
return GoogleDriveExport(
19+
type=type,
20+
subtype=subtype,
21+
fileId=self.id
22+
)
23+
24+
@property
25+
def reference(self):
26+
return self.id
27+
28+
@classmethod
29+
def from_reference(cls, id: str):
30+
if type(id) is str:
31+
if len(id) >= 1:
32+
return cls(id)
33+
else:
34+
raise ValueError("Google Drive File reference MUST NOT be an empty string")
35+
else:
36+
raise ValueError("Google Drive File reference MUST be a string")
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from rid_lib.core import ORN
2+
from rid_lib.types.gdrive_file import GoogleDriveFile
3+
4+
5+
class GoogleDriveFileAuthors(ORN):
6+
namespace = 'google_drive.file.authors'
7+
8+
def __init__(self, fileId: str):
9+
self.fileId = fileId
10+
11+
@property
12+
def file(self) -> GoogleDriveFile:
13+
return GoogleDriveFile(self.fileId)
14+
15+
@property
16+
def reference(self):
17+
return self.fileId
18+
19+
@classmethod
20+
def from_reference(cls, fileId: str):
21+
if type(fileId) is str:
22+
if len(fileId) >= 1:
23+
return cls(fileId)
24+
else:
25+
raise ValueError("Google Drive File Authors reference must not be an empty string")
26+
else:
27+
raise ValueError("Google Drive File Authors reference must be a string")

0 commit comments

Comments
 (0)