forked from googleapis/google-cloud-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This turned out to be much easier... or much harder than expected.
Simply put, there is no way to query the contact API via email address. So I can't make contacts from just addresses. I may change that in the future, but right now that is not so necessary. So with this commit aI have tended to issue googleapis#8.
- Loading branch information
Toben Archer
committed
May 25, 2015
1 parent
687d4c8
commit c7906cb
Showing
2 changed files
with
68 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,9 +227,9 @@ def getAttendees(self): | |
'''Gets list of event attendees.''' | ||
return self.json['Attendees'] | ||
|
||
def addAttendee(self,val): | ||
'''adds an attendee to the event. must call update for notification to send.''' | ||
self.json['Attendees'].append(val) | ||
# def addAttendee(self,val): | ||
# '''adds an attendee to the event. must call update for notification to send.''' | ||
# self.json['Attendees'].append(val) | ||
|
||
def setSubject(self,val): | ||
'''sets event subject line.''' | ||
|
@@ -247,8 +247,52 @@ def setEnd(self,val): | |
'''sets event end struct_time.''' | ||
self.json['End'] = time.strftime(self.time_string,val) | ||
|
||
def setAttendees(self,val): | ||
'''sets event attendees list.''' | ||
self.json['Attendees'] = val | ||
def setAttendee(self,val): | ||
''' | ||
set the recipient list. | ||
val: the one argument this method takes can be very flexible. you can send: | ||
a dictionary: this must to be a dictionary formated as such: | ||
{"EmailAddress":{"Address":"[email protected]"}} | ||
with other options such ass "Name" with address. but at minimum it must have this. | ||
a list: this must to be a list of libraries formatted the way specified above, | ||
or it can be a list of libraries objects of type Contact. The method will sort | ||
out the libraries from the contacts. | ||
a string: this is if you just want to throw an email address. | ||
a contact: type Contact from this library. | ||
For each of these argument types the appropriate action will be taken to fit them to the | ||
needs of the library. | ||
''' | ||
if isinstance(val,list): | ||
self.json['Attendees'] = val | ||
elif isinstance(val,dict): | ||
self.json['Attendees'] = [val] | ||
elif isinstance(val,str): | ||
if '@' in val: | ||
self.json['Attendees'] = [] | ||
self.addRecipient(val) | ||
elif isinstance(val,Contact): | ||
self.json['Attendees'] = [] | ||
self.addRecipient(val) | ||
else: | ||
return False | ||
return True | ||
|
||
def addAttendee(self,address,name=None): | ||
''' | ||
Adds a recipient to the attendee list. | ||
Arguments: | ||
address -- the email address of the person you are sending to. <<< Important that. | ||
Address can also be of type contact. if it is name is superflous. Else, it | ||
uses the name passed if you sent it one. | ||
name -- the name of the person you are sending to. mostly just a decorator. | ||
''' | ||
if isinstance(address,Contact): | ||
self.json['Attendees'].append(address.getFirstEmailAddress()) | ||
else: | ||
if name is None: | ||
name = address[:address.index('@')] | ||
self.json['Attendees'].append({'EmailAddress':{'Address':address,'Name':name}}) | ||
|
||
#To the King! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,8 +101,6 @@ def sendMessage(self): | |
|
||
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} | ||
|
||
# data = json.dumps(self.json) | ||
|
||
try: | ||
data = {'Message':{'Body':{}}} | ||
data['Message']['Subject'] = self.json['Subject'] | ||
|
@@ -169,8 +167,11 @@ def setRecipients(self,val): | |
a dictionary: this must to be a dictionary formated as such: | ||
{"EmailAddress":{"Address":"[email protected]"}} | ||
with other options such ass "Name" with address. but at minimum it must have this. | ||
a list: this must to be a list of libraries formatted the way specified above. | ||
a list: this must to be a list of libraries formatted the way specified above, | ||
or it can be a list of libraries objects of type Contact. The method will sort | ||
out the libraries from the contacts. | ||
a string: this is if you just want to throw an email address. | ||
a contact: type Contact from this library. | ||
For each of these argument types the appropriate action will be taken to fit them to the | ||
needs of the library. | ||
''' | ||
|
@@ -181,22 +182,30 @@ def setRecipients(self,val): | |
elif isinstance(val,str): | ||
if '@' in val: | ||
self.json['ToRecipients'] = [] | ||
self.addRecipient(None,val) | ||
self.addRecipient(val) | ||
elif isinstance(val,Contact): | ||
self.json['ToRecipients'] = [] | ||
self.addRecipient(val) | ||
else: | ||
return False | ||
return True | ||
|
||
def addRecipient(self,name,address): | ||
def addRecipient(self,address,name=None): | ||
''' | ||
Adds a recipient to the recipients list. | ||
Arguments: | ||
name -- the name of the person you are sending to. mostly just a decorator. | ||
address -- the email address of the person you are sending to. <<< Important that. | ||
Address can also be of type contact. if it is name is superflous. Else, it | ||
uses the name passed if you sent it one. | ||
name -- the name of the person you are sending to. mostly just a decorator. | ||
''' | ||
if name is None: | ||
name = address[:address.index('@')] | ||
self.json['ToRecipients'].append({'EmailAddress':{'Address':address,'Name':name}}) | ||
if isinstance(address,Contact): | ||
self.json['ToRecipients'].append(address.getFirstEmailAddress()) | ||
else: | ||
if name is None: | ||
name = address[:address.index('@')] | ||
self.json['ToRecipients'].append({'EmailAddress':{'Address':address,'Name':name}}) | ||
|
||
def setSubject(self,val): | ||
'''Sets the subect line of the email.''' | ||
|