Skip to content

Commit

Permalink
Tended to the requestion in issue googleapis#14 where the desired fun…
Browse files Browse the repository at this point in the history
…ctinality

was to be able to send groups to event and message to set or add
them as recipients or contacts. This should now work.
  • Loading branch information
Narcolapser committed Oct 23, 2015
1 parent 1b46e80 commit dfde536
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
27 changes: 15 additions & 12 deletions O365/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ 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 setSubject(self,val):
'''sets event subject line.'''
self.json['Subject'] = val
Expand All @@ -236,7 +232,7 @@ def setEnd(self,val):

def setAttendee(self,val):
'''
set the recipient list.
set the attendee 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:
Expand All @@ -250,17 +246,18 @@ def setAttendee(self,val):
For each of these argument types the appropriate action will be taken to fit them to the
needs of the library.
'''
self.json['Attendees'] = []
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)
self.addAttendee(val)
elif isinstance(val,Contact):
self.json['Attendees'] = []
self.addRecipient(val)
self.addAttendee(val)
elif isinstance(val,Group):
self.addAttendee(val)
else:
return False
return True
Expand All @@ -271,12 +268,18 @@ def addAttendee(self,address,name=None):
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.
Address can also be of type Contact or type Group.
name -- the name of the person you are sending to. mostly just a decorator. If you
send an email address for the address arg, this will give you the ability
to set the name properly, other wise it uses the email address up to the
at sign for the name. But if you send a type Contact or type Group, this
argument is completely ignored.
'''
if isinstance(address,Contact):
self.json['Attendees'].append(address.getFirstEmailAddress())
elif isinstance(address,Group):
for con in address.contacts:
self.json['Attendees'].append(address.getFirstEmailAddress())
else:
if name is None:
name = address[:address.index('@')]
Expand Down
16 changes: 11 additions & 5 deletions O365/message.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from O365.attachment import Attachment
from O365.contact import Contact
from O365.group import Group
import logging
import json
import requests
Expand Down Expand Up @@ -166,8 +167,8 @@ def setRecipients(self,val):
For each of these argument types the appropriate action will be taken to fit them to the
needs of the library.
'''
self.json['ToRecipients'] = []
if isinstance(val,list):
self.json['ToRecipients'] = []
for con in val:
if isinstance(con,Contact):
self.addRecipient(con)
Expand All @@ -177,7 +178,6 @@ def setRecipients(self,val):
self.json['ToRecipients'] = [val]
elif isinstance(val,str):
if '@' in val:
self.json['ToRecipients'] = []
self.addRecipient(val)
elif isinstance(val,Contact):
self.addRecipient(val)
Expand All @@ -194,12 +194,18 @@ def addRecipient(self,address,name=None):
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.
Address can also be of type Contact or type Group.
name -- the name of the person you are sending to. mostly just a decorator. If you
send an email address for the address arg, this will give you the ability
to set the name properly, other wise it uses the email address up to the
at sign for the name. But if you send a type Contact or type Group, this
argument is completely ignored.
'''
if isinstance(address,Contact):
self.json['ToRecipients'].append(address.getFirstEmailAddress())
elif isinstance(address,Group):
for con in address.contacts:
self.json['ToRecipients'].append(address.getFirstEmailAddress())
else:
if name is None:
name = address[:address.index('@')]
Expand Down
8 changes: 8 additions & 0 deletions tests/run_test.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
echo "python test_attachment.py"
python test_attachment.py
echo "python test_cal.py"
python test_cal.py
echo "python test_event.py"
python test_event.py
echo "python test_inbox.py"
python test_inbox.py
echo "python test_message.py"
python test_message.py
echo "python test_schedule.py"
python test_schedule.py
echo "python test_group.py"
python test_group.py
echo "python test_contact.py"
python test_contact.py

echo "all tests done."
8 changes: 8 additions & 0 deletions tests/run_test3.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
echo "python3 test_attachment.py"
python3 test_attachment.py
echo "python3 test_cal.py"
python3 test_cal.py
echo "python3 test_event.py"
python3 test_event.py
echo "python3 test_inbox.py"
python3 test_inbox.py
echo "python3 test_message.py"
python3 test_message.py
echo "python3 test_schedule.py"
python3 test_schedule.py
echo "python3 test_group.py"
python3 test_group.py
echo "python3 test_contact.py"
python3 test_contact.py

echo "all tests done."

0 comments on commit dfde536

Please sign in to comment.