Skip to content

Commit

Permalink
v3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyephron committed Sep 13, 2020
1 parent 36cb29b commit 48f2905
Show file tree
Hide file tree
Showing 8 changed files with 687 additions and 478 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name="simplegmail",
version="2.1.0",
version="3.0.0",
url="https://github.com/jeremyephron/simple-gmail",
author="Jeremy Ephron",
author_email="[email protected]",
Expand Down
4 changes: 2 additions & 2 deletions simplegmail/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from simplegmail.gmail import Gmail
from simplegmail import query
from simplegmail import labels
from simplegmail import label

__all__ = ['Gmail', 'query', 'labels']
__all__ = ['Gmail', 'query', 'label']
62 changes: 41 additions & 21 deletions simplegmail/attachment.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
"""
File: attachment.py
-------------------
This module contains the implementation of the Attachment object.
"""

import base64 # for base64.urlsafe_b64decode
import os # for os.path.exists
from typing import Optional

class Attachment(object):
"""
The Attachment class for attachments to emails in your Gmail mailbox. This
class should not be manually instantiated.
Args:
service (googleapiclient.discovery.Resource): the Gmail service object.
user_id (str): the username of the account the message belongs to.
msg_id (str): the id of message the attachment belongs to.
att_id (str): the id of the attachment.
filename (str): the filename associated with the attachment.
filetype (str): the mime type of the file.
data (bytes): the raw data of the file. Default None.
service: The Gmail service object.
user_id: The username of the account the message belongs to.
msg_id: The id of message the attachment belongs to.
att_id: The id of the attachment.
filename: The filename associated with the attachment.
filetype: The mime type of the file.
data: The raw data of the file. Default None.
Attributes:
_service (googleapiclient.discovery.Resource): the Gmail service object.
user_id (str): the username of the account the message belongs to.
msg_id (str): the id of message the attachment belongs to.
id (str): the id of the attachment.
filename (str): the filename associated with the attachment.
filetype (str): the mime type of the file.
data (bytes): the raw data of the file.
_service (googleapiclient.discovery.Resource): The Gmail service object.
user_id (str): The username of the account the message belongs to.
msg_id (str): The id of message the attachment belongs to.
id (str): The id of the attachment.
filename (str): The filename associated with the attachment.
filetype (str): The mime type of the file.
data (bytes): The raw data of the file.
"""

def __init__(self, service, user_id, msg_id, att_id, filename, filetype,
data=None):
def __init__(
self,
service: 'googleapiclient.discovery.Resource',
user_id: str,
msg_id: str,
att_id: str,
filename: str,
filetype: str,
data: Optional[bytes] = None
) -> None:
self._service = service
self.user_id = user_id
self.msg_id = msg_id
Expand All @@ -41,10 +52,14 @@ def __init__(self, service, user_id, msg_id, att_id, filename, filetype,
self.filetype = filetype
self.data = data

def download(self):
def download(self) -> None:
"""
Downloads the data for an attachment if it does not exist.
Raises:
googleapiclient.errors.HttpError: There was an error executing the
HTTP request.
"""

if self.data is not None:
Expand All @@ -57,18 +72,23 @@ def download(self):
data = res['data']
self.data = base64.urlsafe_b64decode(data)

def save(self, filepath=None, overwrite=False):
def save(
self,
filepath: Optional[str] = None,
overwrite: bool = False
) -> None:
"""
Saves the attachment. Downloads file data if not downloaded.
Args:
filepath (str): where to save the attachment. Default None, which
uses the filename stored.
overwrite (bool): whether to overwrite existing files. Default False.
filepath: where to save the attachment. Default None, which uses
the filename stored.
overwrite: whether to overwrite existing files. Default False.
Raises:
FileExistsError: if the call would overwrite an existing file and
overwrite is not set to True.
"""

if filepath is None:
Expand Down
Loading

0 comments on commit 48f2905

Please sign in to comment.