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

Improve code quality #250

Merged
merged 5 commits into from
Mar 29, 2017
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions sendgrid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .version import __version__
#v3 API
from .sendgrid import SendGridAPIClient
from .helpers.mail.mail import Email
from .version import __version__ # noqa
# v3 API
from .sendgrid import SendGridAPIClient # noqa
from .helpers.mail.mail import Email # noqa
4 changes: 2 additions & 2 deletions sendgrid/helpers/inbound/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .config import *
from .parse import *
from .config import * # noqa
from .parse import * # noqa
6 changes: 4 additions & 2 deletions sendgrid/helpers/inbound/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
class Config(object):
"""All configuration for this app is loaded here"""
def __init__(self, **opts):
if (os.environ.get('ENV') != 'prod'): # We are not in Heroku
if os.environ.get('ENV') != 'prod': # We are not in Heroku
self.init_environment()

"""Allow variables assigned in config.yml available the following variables
via properties"""
self.path = opts.get('path', os.path.abspath(os.path.dirname(__file__)))
self.path = opts.get(
'path', os.path.abspath(os.path.dirname(__file__))
)
with open(self.path + '/config.yml') as stream:
config = yaml.load(stream)
self._debug_mode = config['debug_mode']
Expand Down
16 changes: 10 additions & 6 deletions sendgrid/helpers/inbound/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,25 @@ def __init__(self, config, request):
self._raw_payload = request.data

def key_values(self):
"""Return a dictionary of key/values in the payload received from
the webhook"""
"""
Return a dictionary of key/values in the payload received from
the webhook
"""
key_values = {}
for key in self.keys:
if key in self.payload:
key_values[key] = self.payload[key]
return key_values

def get_raw_email(self):
"""This only applies to raw payloads:
https://sendgrid.com/docs/Classroom/Basics/Inbound_Parse_Webhook/setting_up_the_inbound_parse_webhook.html#-Raw-Parameters"""
if 'email' in self.payload:
"""
This only applies to raw payloads:
https://sendgrid.com/docs/Classroom/Basics/Inbound_Parse_Webhook/setting_up_the_inbound_parse_webhook.html#-Raw-Parameters
"""
if 'email' in self.payload:
raw_email = email.message_from_string(self.payload['email'])
return raw_email
else:
else:
return None

def attachments(self):
Expand Down
3 changes: 1 addition & 2 deletions sendgrid/helpers/inbound/send.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
"""A module for sending test SendGrid Inbound Parse messages
Usage: ./send.py [path to file containing test data]"""
import argparse
import os
import sys
try:
from config import Config
except:
except ImportError:
# Python 3+, Travis
from sendgrid.helpers.inbound.config import Config
from python_http_client import Client
Expand Down
2 changes: 1 addition & 1 deletion sendgrid/helpers/mail/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .mail import *
from .mail import * # noqa
Loading