Skip to content
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
5 changes: 3 additions & 2 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

if __name__ == '__main__' and __package__ is None:
from os import sys, path

sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
from smtpapi import SMTPAPIHeader

Expand All @@ -21,7 +22,7 @@

# [Unique Arguments](http://sendgrid.com/docs/API_Reference/SMTP_API/unique_arguments.html)
# header.add_unique_arg('key', 'value')
header.set_unique_args({'key':'value'})
header.set_unique_args({'key': 'value'})

# [Categories](http://sendgrid.com/docs/API_Reference/SMTP_API/categories.html)
# header.add_category('category')
Expand All @@ -43,6 +44,6 @@
# [Scheduling Parameters](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html)
# header.add_send_each_at(unix_timestamp) # must be a unix timestamp
# header.set_send_each_at([]) # must be a unix timestamp
header.set_send_at(int(time.time())) # must be a unix timestamp
header.set_send_at(int(time.time())) # must be a unix timestamp

print(header.json_string())
9 changes: 5 additions & 4 deletions smtpapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import json
import os


dir_path = os.path.dirname(os.path.realpath(__file__))
if os.path.isfile(os.path.join(dir_path, 'VERSION.txt')):
__version__ = open(os.path.join(dir_path, 'VERSION.txt')).read().strip()


class _CustomJSONEncoder(json.JSONEncoder):

def default(self, o):
Expand All @@ -15,6 +15,7 @@ def default(self, o):
# Provide a fallback to the default encoder if we haven't implemented special support for the object's class
return super(_CustomJSONEncoder, self).default(o)


class SMTPAPIHeader(object):

def __init__(self):
Expand Down Expand Up @@ -67,14 +68,14 @@ def set_sections(self, value):

def add_send_each_at(self, time):
if 'send_each_at' not in self.data:
self.data['send_each_at'] = []
self.data['send_each_at'] = []
self.data['send_each_at'].append(time)

def set_send_each_at(self, time):
self.data['send_each_at'] = time
self.data['send_each_at'] = time

def set_send_at(self, time):
self.data['send_at'] = time
self.data['send_at'] = time

def add_filter(self, app, setting, val):
if 'filters' not in self.data:
Expand Down
2 changes: 2 additions & 0 deletions test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def test_license_year(self):
break
self.assertEqual('Copyright (c) 2013-%s SendGrid, Inc.' % datetime.datetime.now().year, copyright_line)


class TestRepository(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -122,5 +123,6 @@ def test_repository_files_exists(self):
else:
self.assertTrue(os.path.exists(file_path), msg=self.file_not_found_message.format(file_path))


if __name__ == '__main__':
unittest.main()
2 changes: 2 additions & 0 deletions test/test_lisence.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sendgrid
from sendgrid.helpers.mail import *
from sendgrid.version import __version__

try:
import unittest2 as unittest
except ImportError:
Expand All @@ -13,6 +14,7 @@

host = "http://localhost:4010"


def test_license_year(self):
LICENSE_FILE = 'license.txt'
with open(LICENSE_FILE, 'r') as f:
Expand Down
2 changes: 2 additions & 0 deletions test/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
except ImportError:
import unittest


class ProjectTests(unittest.TestCase):

# ./Docker or docker/Docker
Expand Down Expand Up @@ -71,5 +72,6 @@ def test_usage(self):
def test_use_cases(self):
self.assertEqual(True, os.path.isfile('./VERSION.txt'))


if __name__ == '__main__':
unittest.main()