Skip to content

Commit

Permalink
This turned out to be much easier... or much harder than expected.
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 15 deletions.
56 changes: 50 additions & 6 deletions O365/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.'''
Expand All @@ -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":"recipient@example.com"}}
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!
27 changes: 18 additions & 9 deletions O365/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -169,8 +167,11 @@ def setRecipients(self,val):
a dictionary: this must to be a dictionary formated as such:
{"EmailAddress":{"Address":"recipient@example.com"}}
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.
'''
Expand All @@ -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.'''
Expand Down

0 comments on commit c7906cb

Please sign in to comment.