Skip to content

Commit ae901e4

Browse files
Toben ArcherToben Archer
Toben Archer
authored and
Toben Archer
committed
Merge branch 'master' into tests
2 parents b447be6 + 4aeaf4b commit ae901e4

File tree

118 files changed

+43013
-365
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+43013
-365
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ coverage.xml
4949

5050
# Sphinx documentation
5151
docs/_build/
52+
doctrees/
5253

5354
# PyBuilder
5455
target/
@@ -64,3 +65,5 @@ trail.py
6465
sample_run.py
6566

6667

68+
69+
o365_token\.txt

O365/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
A simple python library to interact with Microsoft Graph and Office 365 API
33
"""
4+
from .__version__ import __version__
45

56
from .account import Account
67
from .connection import Connection, Protocol, MSGraphProtocol, MSOffice365Protocol, oauth_authentication_flow
@@ -10,3 +11,4 @@
1011
from .calendar import Schedule, Calendar, Event, EventResponse, AttendeeType, EventSensitivity, EventShowAs, CalendarColors, EventAttachment
1112
from .drive import Storage, Drive, Folder, File, Image, Photo
1213
from .utils import OneDriveWellKnowFolderNames, OutlookWellKnowFolderNames, ImportanceLevel
14+
from .sharepoint import Sharepoint, Site

O365/__version__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from pkg_resources import get_distribution, DistributionNotFound
2+
3+
4+
try:
5+
__version__ = get_distribution(__name__.split('.')[0]).version
6+
except DistributionNotFound:
7+
# Package is not installed.
8+
__version__ = None

O365/account.py

Lines changed: 94 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1-
from O365.connection import Connection, Protocol, MSGraphProtocol, oauth_authentication_flow
1+
from O365.address_book import AddressBook, GlobalAddressList
2+
from O365.calendar import Schedule
3+
from O365.connection import Connection, Protocol, MSGraphProtocol
4+
from O365.connection import oauth_authentication_flow
25
from O365.drive import Storage
6+
from O365.mailbox import MailBox
7+
from O365.message import Message
38
from O365.utils import ME_RESOURCE
49
from O365.message import Message
510
from O365.mailbox import MailBox
611
from O365.address_book import AddressBook, GlobalAddressList
712
from O365.calendar import Schedule
13+
from O365.sharepoint import Sharepoint
814

915

1016
class Account(object):
11-
""" Class helper to integrate all components into a single object """
1217

13-
def __init__(self, credentials, *, protocol=None, main_resource=ME_RESOURCE, **kwargs):
14-
"""
15-
Account constructor.
16-
:param credentials: a tuple containing the client_id and client_secret
17-
:param protocol: the protocol to be used in this account instance
18-
:param main_resource: the resource to be used by this account
18+
def __init__(self, credentials, *, protocol=None, main_resource=ME_RESOURCE,
19+
**kwargs):
20+
""" Creates an object which is used to access resources related to the
21+
specified credentials
22+
23+
:param tuple credentials: a tuple containing the client_id
24+
and client_secret
25+
:param Protocol protocol: the protocol to be used in this account
26+
:param str main_resource: the resource to be used by this account
27+
('me' or 'users')
1928
:param kwargs: any extra args to be passed to the Connection instance
29+
:raises ValueError: if an invalid protocol is passed
2030
"""
2131

22-
protocol = protocol or MSGraphProtocol # defaults to Graph protocol
23-
self.protocol = protocol(default_resource=main_resource, **kwargs) if isinstance(protocol, type) else protocol
32+
protocol = protocol or MSGraphProtocol # Defaults to Graph protocol
33+
self.protocol = protocol(default_resource=main_resource,
34+
**kwargs) if isinstance(protocol,
35+
type) else protocol
2436

2537
if not isinstance(self.protocol, Protocol):
2638
raise ValueError("'protocol' must be a subclass of Protocol")
@@ -35,62 +47,107 @@ def __repr__(self):
3547
return 'Unidentified Account'
3648

3749
def authenticate(self, *, scopes, **kwargs):
38-
"""
39-
Performs the oauth authentication flow resulting in a stored token.
50+
""" Performs the oauth authentication flow resulting in a stored token
4051
It uses the credentials passed on instantiation
41-
:param scopes: a list of protocol user scopes to be converted by the protocol
42-
:param kwargs: other configuration to be passed to the Connection instance
52+
53+
:param list[str] scopes: list of protocol user scopes to be converted
54+
by the protocol
55+
:param kwargs: other configurations to be passed to the
56+
Connection instance
57+
:return: Success / Failure
58+
:rtype: bool
4359
"""
4460
kwargs.setdefault('token_file_name', self.con.token_path.name)
4561

46-
return oauth_authentication_flow(*self.con.auth, scopes=scopes, protocol=self.protocol, **kwargs)
62+
return oauth_authentication_flow(*self.con.auth, scopes=scopes,
63+
protocol=self.protocol, **kwargs)
4764

4865
@property
4966
def connection(self):
50-
""" Alias for self.con """
67+
""" Alias for self.con
68+
69+
:rtype: Connection
70+
"""
5171
return self.con
5272

5373
def new_message(self, resource=None):
54-
"""
55-
Creates a new message to be send or stored
56-
:param resource: Custom resource to be used in this message. Defaults to parent main_resource.
74+
""" Creates a new message to be sent or stored
75+
76+
:param str resource: Custom resource to be used in this message
77+
(Defaults to parent main_resource)
78+
:return: New empty message
79+
:rtype: Message
5780
"""
5881
return Message(parent=self, main_resource=resource, is_draft=True)
5982

6083
def mailbox(self, resource=None):
61-
"""
62-
Creates MailBox Folder instance
63-
:param resource: Custom resource to be used in this mailbox. Defaults to parent main_resource.
84+
""" Get an instance to the mailbox for the specified account resource
85+
86+
:param str resource: Custom resource to be used in this mailbox
87+
(Defaults to parent main_resource)
88+
:return: a representation of account mailbox
89+
:rtype: MailBox
6490
"""
6591
return MailBox(parent=self, main_resource=resource, name='MailBox')
6692

6793
def address_book(self, *, resource=None, address_book='personal'):
94+
""" Get an instance to the specified address book for the
95+
specified account resource
96+
97+
:param str resource: Custom resource to be used in this address book
98+
(Defaults to parent main_resource)
99+
:param str address_book: Choose from 'Personal' or
100+
'GAL' (Global Address List)
101+
:return: a representation of the specified address book
102+
:rtype: AddressBook or GlobalAddressList
103+
:raises RuntimeError: if invalid address_book is specified
68104
"""
69-
Creates Address Book instance
70-
:param resource: Custom resource to be used in this address book. Defaults to parent main_resource.
71-
:param address_book: Choose from Personal or Gal (Global Address List)
72-
"""
73-
if address_book == 'personal':
74-
return AddressBook(parent=self, main_resource=resource, name='Personal Address Book')
75-
elif address_book == 'gal':
105+
if address_book.lower() == 'personal':
106+
return AddressBook(parent=self, main_resource=resource,
107+
name='Personal Address Book')
108+
elif address_book.lower() == 'gal':
76109
return GlobalAddressList(parent=self)
77110
else:
78-
raise RuntimeError('Addres_book must be either "personal" (resource address book) or "gal" (Global Address List)')
111+
raise RuntimeError(
112+
'address_book must be either "personal" '
113+
'(resource address book) or "gal" (Global Address List)')
79114

80115
def schedule(self, *, resource=None):
81-
"""
82-
Creates Schedule instance to handle calendars
83-
:param resource: Custom resource to be used in this schedule object. Defaults to parent main_resource.
116+
""" Get an instance to work with calendar events for the
117+
specified account resource
118+
119+
:param str resource: Custom resource to be used in this schedule object
120+
(Defaults to parent main_resource)
121+
:return: a representation of calendar events
122+
:rtype: Schedule
84123
"""
85124
return Schedule(parent=self, main_resource=resource)
86125

87126
def storage(self, *, resource=None):
127+
""" Get an instance to handle file storage like OneDrive or
128+
Sharepoint document libraries for the specified account resource
129+
130+
:param str resource: Custom resource to be used in this drive object
131+
(Defaults to parent main_resource)
132+
:return: a representation of File Storage
133+
:rtype: Storage
134+
:raises RuntimeError: if protocol doesn't support the feature
135+
"""
136+
if not isinstance(self.protocol, MSGraphProtocol):
137+
# TODO: Custom protocol accessing OneDrive/Sharepoint Api fails here
138+
raise RuntimeError(
139+
'Drive options only works on Microsoft Graph API')
140+
141+
return Storage(parent=self, main_resource=resource)
142+
143+
def sharepoint(self, *, resource=''):
88144
"""
89-
Creates a Storage instance to handle file storage like OneDrive or Sharepoint document libraries
90-
:param resource: Custom resource to be used in this drive object. Defaults to parent main_resource.
145+
Creates a new Sharepoint instance
146+
:param resource: Custom resource to be used in this sharepoint object. Defaults to blank.
91147
"""
148+
92149
if not isinstance(self.protocol, MSGraphProtocol):
93150
# TODO: a custom protocol accessing OneDrive or Sharepoint Api will fail here.
94-
raise RuntimeError('Drive options only works on Microsoft Graph API')
151+
raise RuntimeError('Sharepoint api only works on Microsoft Graph API')
95152

96-
return Storage(parent=self, main_resource=resource)
153+
return Sharepoint(parent=self, main_resource=resource)

0 commit comments

Comments
 (0)