Skip to content

Commit

Permalink
Merge pull request googleapis#92 from SmartBase-SK/master
Browse files Browse the repository at this point in the history
Added order_by and error handling for getMessages

Thank you sir.
  • Loading branch information
Narcolapser authored Apr 9, 2018
2 parents 39bc0bf + 529fa84 commit 4b707d6
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion O365/inbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ def __init__(self, auth, getNow=True, verify=True):
log.debug('creating inbox for the email %s',auth[0])
self.auth = auth
self.messages = []
self.errors = ''

self.filters = ''
self.order_by = ''
self.verify = verify

if getNow:
Expand All @@ -53,7 +55,14 @@ def getMessages(self, number = 10):
'''

log.debug('fetching messages.')
response = requests.get(self.inbox_url,auth=self.auth,params={'$filter':self.filters, '$top':number},verify=self.verify)
response = requests.get(self.inbox_url,auth=self.auth,params={'$orderby':self.order_by, '$filter':self.filters, '$top':number},verify=self.verify)
if response.status_code in [400, 500]:
self.errors = response.text
return False
elif response.status_code in [401]:
self.errors = response.reason
return False

log.info('Response from O365: %s', str(response))

#check that there are messages
Expand Down Expand Up @@ -82,6 +91,19 @@ def getMessages(self, number = 10):
log.debug('all messages retrieved and put in to the list.')
return True

def getErrors(self):
return self.errors

def getOrderBy(self):
return self.order_by

def setOrderBy(self, f_string):
'''
For example 'DateTimeReceived desc'
'''
self.order_by = f_string
return True

def getFilter(self):
'''get the value set for a specific filter, if exists, else None'''
return self.filters
Expand Down

0 comments on commit 4b707d6

Please sign in to comment.