Skip to content

Commit

Permalink
load transports on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
Kane Kim committed Mar 1, 2012
1 parent 6a533e7 commit d8d0a0c
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions sendgrid/sendgrid.py
@@ -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
Expand All @@ -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)

0 comments on commit d8d0a0c

Please sign in to comment.