Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

load transports on demand

  • Loading branch information...
commit d8d0a0cbd2a0fed8a9ffc0ccb534fb4a16f4bcea 1 parent 6a533e7
Vyacheslav Kim (Kane) Kane-Sendgrid authored
Showing with 33 additions and 4 deletions.
  1. +33 −4 sendgrid/sendgrid.py
37 sendgrid/sendgrid.py
View
@@ -1,10 +1,19 @@
-from transport import smtp, web
+def memoize(f):
+ """
+ Memoization decorator
+ """
+ cache= {}
+ def func(*args):
+ if args not in cache:
+ cache[args] = f(*args)
+ return cache[args]
+ return func
+
class Sendgrid(object):
"""
Sendgrid API
"""
-
def __init__(self, username, password, secure=True):
"""
Construct Sendgrid API object
@@ -14,6 +23,26 @@ def __init__(self, username, password, secure=True):
password: Sendgrid password
ssl: Use SSL
"""
+ self.username = username
+ self.password = password
+ self.secure = secure
+
- self.web = web.Http(username, password, secure)
- self.smtp = smtp.Smtp(username, password, secure)
+ @property
+ @memoize
+ def web(self):
+ """
+ Return web transport
+ """
+ from transport import web
+ return web.Http(self.username, self.password, self.secure)
+
+
+ @property
+ @memoize
+ def smtp(self):
+ """
+ Return smtp transport
+ """
+ from transport import smtp
+ return smtp.Smtp(self.username, self.password, self.secure)
Please sign in to comment.
Something went wrong with that request. Please try again.