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
14 changes: 7 additions & 7 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
MIT License
The MIT License (MIT)

Copyright (C) 2020, Twilio SendGrid, Inc. <help@twilio.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
Expand Down
36 changes: 17 additions & 19 deletions smtpapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import decimal
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()
import decimal


class _CustomJSONEncoder(json.JSONEncoder):

def default(self, o):
if isinstance(o, decimal.Decimal):
return float(o)
# Provide a fallback to the default encoder if we haven't implemented special support for the object's class
# 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)


Expand Down Expand Up @@ -42,34 +38,36 @@ def add_substitution(self, key, value):
def set_substitutions(self, subs):
self.data['sub'] = subs

def _add_key_value(self, index, key, value):
if index not in self.data:
self.data[index] = {}
self.data[index][key] = value

def _add_key(self, index, key):
if index not in self.data:
self.data[index] = []
self.data[index].append(key)

def add_unique_arg(self, key, value):
if 'unique_args' not in self.data:
self.data['unique_args'] = {}
self.data['unique_args'][key] = value
self._add_key_value('unique_args', key, value)

def set_unique_args(self, value):
self.data['unique_args'] = value

def add_category(self, category):
if 'category' not in self.data:
self.data['category'] = []
self.data['category'].append(category)
self._add_key('category', category)

def set_categories(self, category):
self.data['category'] = category

def add_section(self, key, section):
if 'section' not in self.data:
self.data['section'] = {}
self.data['section'][key] = section
self._add_key_value('section', key, section)

def set_sections(self, value):
self.data['section'] = 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'].append(time)
self._add_key('send_each_at', time)

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