diff --git a/README.md b/README.md index 2daab376..22ffd94d 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,10 @@ A REST/OData based client library for Office 365. ### Usage 1. [Installation](#Installation) -1. [Working with SharePoint API](#Working-with-SharePoint-API) -2. [Working with Outlook API](#Working-with-Outlook-API) -3. [Working with OneDrive API](#Working-with-OneDrive-API) +2. [Working with SharePoint API](#Working-with-SharePoint-API) +3. [Working with Teams API](#Working-with-Teams-API) +4. [Working with Outlook API](#Working-with-Outlook-API) +5. [Working with OneDrive API](#Working-with-OneDrive-API) ### Status @@ -195,6 +196,9 @@ $client->executeQuery(); ``` +### Working with Teams API + + ### Working with Outlook API diff --git a/src/Common/Alert.php b/src/Common/Alert.php index 84a696cc..acb4799f 100644 --- a/src/Common/Alert.php +++ b/src/Common/Alert.php @@ -118,18 +118,18 @@ public function setComments($value) */ public function getConfidence() { - if (!$this->isPropertyAvailable("Confidence")) { - return null; - } return $this->getProperty("Confidence"); } + /** * Confidence of the detection logic (percentage between 1-100). + * + * @return self * @var integer */ public function setConfidence($value) { - $this->setProperty("Confidence", $value, true); + return $this->setProperty("Confidence", $value, true); } /** * Alert description. diff --git a/src/Common/Invitation.php b/src/Common/Invitation.php index e43df0ec..c882fff2 100644 --- a/src/Common/Invitation.php +++ b/src/Common/Invitation.php @@ -5,9 +5,9 @@ */ namespace Office365\Common; -use Office365\Runtime\ClientObject; +use Office365\Entity; use Office365\Runtime\ResourcePath; -class Invitation extends ClientObject +class Invitation extends Entity { /** * The display name of the user being invited. @@ -15,9 +15,6 @@ class Invitation extends ClientObject */ public function getInvitedUserDisplayName() { - if (!$this->isPropertyAvailable("InvitedUserDisplayName")) { - return null; - } return $this->getProperty("InvitedUserDisplayName"); } /** @@ -34,9 +31,6 @@ public function setInvitedUserDisplayName($value) */ public function getInvitedUserType() { - if (!$this->isPropertyAvailable("InvitedUserType")) { - return null; - } return $this->getProperty("InvitedUserType"); } /** @@ -53,9 +47,6 @@ public function setInvitedUserType($value) */ public function getInvitedUserEmailAddress() { - if (!$this->isPropertyAvailable("InvitedUserEmailAddress")) { - return null; - } return $this->getProperty("InvitedUserEmailAddress"); } /** @@ -72,9 +63,6 @@ public function setInvitedUserEmailAddress($value) */ public function getSendInvitationMessage() { - if (!$this->isPropertyAvailable("SendInvitationMessage")) { - return null; - } return $this->getProperty("SendInvitationMessage"); } /** @@ -91,9 +79,6 @@ public function setSendInvitationMessage($value) */ public function getInviteRedirectUrl() { - if (!$this->isPropertyAvailable("InviteRedirectUrl")) { - return null; - } return $this->getProperty("InviteRedirectUrl"); } /** @@ -110,9 +95,6 @@ public function setInviteRedirectUrl($value) */ public function getInviteRedeemUrl() { - if (!$this->isPropertyAvailable("InviteRedeemUrl")) { - return null; - } return $this->getProperty("InviteRedeemUrl"); } /** @@ -129,18 +111,18 @@ public function setInviteRedeemUrl($value) */ public function getStatus() { - if (!$this->isPropertyAvailable("Status")) { - return null; - } return $this->getProperty("Status"); } + /** * The status of the invitation. Possible values: PendingAcceptance, Completed, InProgress, and Error + * + * @return self * @var string */ public function setStatus($value) { - $this->setProperty("Status", $value, true); + return $this->setProperty("Status", $value, true); } /** * Additional configuration for the message being sent to the invited user, including customizing message text, language and cc recipient list. @@ -148,10 +130,7 @@ public function setStatus($value) */ public function getInvitedUserMessageInfo() { - if (!$this->isPropertyAvailable("InvitedUserMessageInfo")) { - return null; - } - return $this->getProperty("InvitedUserMessageInfo"); + return $this->getProperty("InvitedUserMessageInfo",new InvitedUserMessageInfo()); } /** * Additional configuration for the message being sent to the invited user, including customizing message text, language and cc recipient list. @@ -167,9 +146,7 @@ public function setInvitedUserMessageInfo($value) */ public function getInvitedUser() { - if (!$this->isPropertyAvailable("InvitedUser")) { - $this->setProperty("InvitedUser", new User($this->getContext(), new ResourcePath("InvitedUser", $this->getResourcePath()))); - } - return $this->getProperty("InvitedUser"); + return $this->getProperty("InvitedUser", + new User($this->getContext(), new ResourcePath("InvitedUser", $this->getResourcePath()))); } } \ No newline at end of file diff --git a/src/EntityCollection.php b/src/EntityCollection.php index 01028500..39d24269 100644 --- a/src/EntityCollection.php +++ b/src/EntityCollection.php @@ -25,12 +25,12 @@ public function __construct(ClientRuntimeContext $ctx, ResourcePath $resourcePat } /** - * @param string $id - * @return Entity + * @param string $id Entity Id + * @return ClientObject */ function getById($id) { - return new Entity($this->getContext(),new ResourcePath($id, $this->getResourcePath())); + return $this->createType(new ResourcePath($id, $this->getResourcePath())); } /** @@ -58,7 +58,7 @@ public function offsetGet($offset) { if(is_int($offset)) return parent::offsetGet($offset); - return new Entity($this->getContext(),new ResourcePath($offset, $this->getResourcePath())); + return $this->getById($offset); } } \ No newline at end of file diff --git a/src/OneNote/CopyNotebookModel.php b/src/OneNote/CopyNotebookModel.php index 728d55c5..98e5a27f 100644 --- a/src/OneNote/CopyNotebookModel.php +++ b/src/OneNote/CopyNotebookModel.php @@ -1,7 +1,7 @@ isPropertyAvailable("IsDefault")) { - return null; - } return $this->getProperty("IsDefault"); } /** @@ -36,9 +33,6 @@ public function setIsDefault($value) */ public function getIsShared() { - if (!$this->isPropertyAvailable("IsShared")) { - return null; - } return $this->getProperty("IsShared"); } /** @@ -55,9 +49,6 @@ public function setIsShared($value) */ public function getSectionsUrl() { - if (!$this->isPropertyAvailable("SectionsUrl")) { - return null; - } return $this->getProperty("SectionsUrl"); } /** @@ -74,18 +65,18 @@ public function setSectionsUrl($value) */ public function getSectionGroupsUrl() { - if (!$this->isPropertyAvailable("SectionGroupsUrl")) { - return null; - } return $this->getProperty("SectionGroupsUrl"); } + /** * The URL for the `sectionGroups` navigation property, which returns all the section groups in the notebook. Read-only. + * + * @return self * @var string */ public function setSectionGroupsUrl($value) { - $this->setProperty("SectionGroupsUrl", $value, true); + return $this->setProperty("SectionGroupsUrl", $value, true); } /** * Links for opening the notebook. The `oneNoteClientURL` link opens the notebook in the OneNote native client if it's installed. The `oneNoteWebURL` link opens the notebook in OneNote on the web. @@ -93,17 +84,17 @@ public function setSectionGroupsUrl($value) */ public function getLinks() { - if (!$this->isPropertyAvailable("Links")) { - return null; - } - return $this->getProperty("Links"); + return $this->getProperty("Links", new NotebookLinks()); } + /** * Links for opening the notebook. The `oneNoteClientURL` link opens the notebook in the OneNote native client if it's installed. The `oneNoteWebURL` link opens the notebook in OneNote on the web. + * + * @return self * @var NotebookLinks */ public function setLinks($value) { - $this->setProperty("Links", $value, true); + return $this->setProperty("Links", $value, true); } } \ No newline at end of file diff --git a/src/OneNote/NotebookLinks.php b/src/OneNote/NotebookLinks.php index ff4d5a47..bbe387c7 100644 --- a/src/OneNote/NotebookLinks.php +++ b/src/OneNote/NotebookLinks.php @@ -1,7 +1,7 @@ isPropertyAvailable("IsDefault")) { - return null; - } return $this->getProperty("IsDefault"); } + /** + * + * @return self * @var bool */ public function setIsDefault($value) { - $this->setProperty("IsDefault", $value, true); + return $this->setProperty("IsDefault", $value, true); } /** * @return string */ public function getPagesUrl() { - if (!$this->isPropertyAvailable("PagesUrl")) { - return null; - } return $this->getProperty("PagesUrl"); } /** @@ -48,10 +45,7 @@ public function setPagesUrl($value) */ public function getLinks() { - if (!$this->isPropertyAvailable("Links")) { - return null; - } - return $this->getProperty("Links"); + return $this->getProperty("Links", new SectionLinks()); } /** * @var SectionLinks @@ -65,29 +59,24 @@ public function setLinks($value) */ public function getParentNotebook() { - if (!$this->isPropertyAvailable("ParentNotebook")) { - $this->setProperty("ParentNotebook", new Notebook($this->getContext(), new ResourcePath("ParentNotebook", $this->getResourcePath()))); - } - return $this->getProperty("ParentNotebook"); + return $this->getProperty("ParentNotebook", + new Notebook($this->getContext(), new ResourcePath("ParentNotebook", $this->getResourcePath()))); } /** * @return SectionGroup */ public function getParentSectionGroup() { - if (!$this->isPropertyAvailable("ParentSectionGroup")) { - $this->setProperty("ParentSectionGroup", new SectionGroup($this->getContext(), new ResourcePath("ParentSectionGroup", $this->getResourcePath()))); - } - return $this->getProperty("ParentSectionGroup"); + return $this->getProperty("ParentSectionGroup", + new SectionGroup($this->getContext(), + new ResourcePath("ParentSectionGroup", $this->getResourcePath()))); } /** * @return OnenotePageCollection */ public function getPages() { - if (!$this->isPropertyAvailable("Pages")) { - $this->setProperty("Pages", new OnenotePageCollection($this->getContext(), new ResourcePath("Pages", $this->getResourcePath()))); - } - return $this->getProperty("Pages"); + return $this->getProperty("Pages", + new OnenotePageCollection($this->getContext(), new ResourcePath("Pages", $this->getResourcePath()))); } } \ No newline at end of file diff --git a/src/OneNote/PageLinks.php b/src/OneNote/PageLinks.php index 62e6204a..6d4c6846 100644 --- a/src/OneNote/PageLinks.php +++ b/src/OneNote/PageLinks.php @@ -1,7 +1,7 @@ isPropertyAvailable("SectionsUrl")) { - return null; - } return $this->getProperty("SectionsUrl"); } /** @@ -37,18 +35,18 @@ public function setSectionsUrl($value) */ public function getSectionGroupsUrl() { - if (!$this->isPropertyAvailable("SectionGroupsUrl")) { - return null; - } return $this->getProperty("SectionGroupsUrl"); } + /** * The URL for the `sectionGroups` navigation property, which returns all the section groups in the section group. Read-only. + * + * @return self * @var string */ public function setSectionGroupsUrl($value) { - $this->setProperty("SectionGroupsUrl", $value, true); + return $this->setProperty("SectionGroupsUrl", $value, true); } /** * The notebook that contains the section group. Read-only. @@ -66,6 +64,7 @@ public function getParentNotebook() public function getParentSectionGroup() { return $this->getProperty("ParentSectionGroup", - new SectionGroup($this->getContext(), new ResourcePath("ParentSectionGroup", $this->getResourcePath()))); + new SectionGroup($this->getContext(), + new ResourcePath("ParentSectionGroup", $this->getResourcePath()))); } } \ No newline at end of file diff --git a/src/OneNote/SectionLinks.php b/src/OneNote/SectionLinks.php index e23f1ec4..0eeddea4 100644 --- a/src/OneNote/SectionLinks.php +++ b/src/OneNote/SectionLinks.php @@ -1,7 +1,7 @@ isPropertyAvailable("OrderHint")) { - return null; - } return $this->getProperty("OrderHint"); } + /** * Hint used to order tasks in the Bucket view of the Task Board. The format is defined as outlined [here](planner-order-hint-format.md). + * + * @return PlannerBucketTaskBoardTaskFormat * @var string */ public function setOrderHint($value) { - $this->setProperty("OrderHint", $value, true); + return $this->setProperty("OrderHint", $value, true); } } \ No newline at end of file diff --git a/src/Planner/PlannerProgressTaskBoardTaskFormat.php b/src/Planner/PlannerProgressTaskBoardTaskFormat.php index 6cde4b73..922cac76 100644 --- a/src/Planner/PlannerProgressTaskBoardTaskFormat.php +++ b/src/Planner/PlannerProgressTaskBoardTaskFormat.php @@ -18,17 +18,17 @@ class PlannerProgressTaskBoardTaskFormat extends Entity */ public function getOrderHint() { - if (!$this->isPropertyAvailable("OrderHint")) { - return null; - } return $this->getProperty("OrderHint"); } + /** * Hint value used to order the task on the Progress view of the Task Board. The format is defined as outlined [here](planner-order-hint-format.md). + * + * @return self * @var string */ public function setOrderHint($value) { - $this->setProperty("OrderHint", $value, true); + return $this->setProperty("OrderHint", $value, true); } } \ No newline at end of file diff --git a/src/Runtime/ClientObjectCollection.php b/src/Runtime/ClientObjectCollection.php index f58866c4..331ebee5 100644 --- a/src/Runtime/ClientObjectCollection.php +++ b/src/Runtime/ClientObjectCollection.php @@ -227,12 +227,13 @@ public function skiptoken($value) /** * Creates resource for a collection + * @param ResourcePath|null $resourcePath * @return ClientObject */ - public function createType() + public function createType($resourcePath=null) { $itemTypeName = $this->getItemTypeName(); - $clientObject = new $itemTypeName($this->getContext()); + $clientObject = new $itemTypeName($this->getContext(),$resourcePath); $clientObject->parentCollection = $this; return $clientObject; } diff --git a/src/Runtime/ClientRuntimeContext.php b/src/Runtime/ClientRuntimeContext.php index c62a3c73..70054ce2 100644 --- a/src/Runtime/ClientRuntimeContext.php +++ b/src/Runtime/ClientRuntimeContext.php @@ -102,23 +102,19 @@ public function executeQuery() * @param int $delaySecs * @throws Exception */ - public function executeQueryRetry($retryCount,$delaySecs) + public function executeQueryRetry($retryCount,$delaySecs, $currentRetry=0) { - $currentRetry = 0; - for(;;){ - try{ - $this->executeQuery(); - break; - } - catch(Exception $ex) { - $this->addQuery($this->getPendingRequest()->getCurrentQuery(),true); - $currentRetry++; - if ($currentRetry > $retryCount || !($ex instanceof RequestException)) - { - throw $ex; - } - sleep($delaySecs); + try{ + $this->executeQuery(); + } + catch(Exception $ex) { + if ($currentRetry > $retryCount || !($ex instanceof RequestException)) + { + throw $ex; } + sleep($delaySecs); + $this->addQuery($this->getPendingRequest()->getCurrentQuery(),true); + $this->executeQueryRetry($retryCount,$delaySecs, $currentRetry+1); } } diff --git a/src/SharePoint/ListItem.php b/src/SharePoint/ListItem.php index 08f5f791..5c69411f 100644 --- a/src/SharePoint/ListItem.php +++ b/src/SharePoint/ListItem.php @@ -324,9 +324,6 @@ public function setId($value) */ public function getServerRedirectedEmbedUri() { - if (!$this->isPropertyAvailable("ServerRedirectedEmbedUri")) { - return null; - } return $this->getProperty("ServerRedirectedEmbedUri"); } /** @@ -348,9 +345,6 @@ public function setServerRedirectedEmbedUri($value) */ public function getServerRedirectedEmbedUrl() { - if (!$this->isPropertyAvailable("ServerRedirectedEmbedUrl")) { - return null; - } return $this->getProperty("ServerRedirectedEmbedUrl"); } /** @@ -371,9 +365,6 @@ public function setServerRedirectedEmbedUrl($value) */ public function getClient_Title() { - if (!$this->isPropertyAvailable("Client_Title")) { - return null; - } return $this->getProperty("Client_Title"); } /** diff --git a/src/SharePoint/RecycleBinItem.php b/src/SharePoint/RecycleBinItem.php index b504667a..d54f1def 100644 --- a/src/SharePoint/RecycleBinItem.php +++ b/src/SharePoint/RecycleBinItem.php @@ -99,9 +99,6 @@ public function setDeletedByEmail($value) */ public function getDeletedByName() { - if (!$this->isPropertyAvailable("DeletedByName")) { - return null; - } return $this->getProperty("DeletedByName"); } /** @@ -124,9 +121,6 @@ public function setDeletedByName($value) */ public function getDeletedDate() { - if (!$this->isPropertyAvailable("DeletedDate")) { - return null; - } return $this->getProperty("DeletedDate"); } /** @@ -175,9 +169,6 @@ public function setDeletedDateLocalFormatted($value) */ public function getDirName() { - if (!$this->isPropertyAvailable("DirName")) { - return null; - } return $this->getProperty("DirName"); } /** @@ -201,9 +192,6 @@ public function setDirName($value) */ public function getId() { - if (!$this->isPropertyAvailable("Id")) { - return null; - } return $this->getProperty("Id"); } /** @@ -225,9 +213,6 @@ public function setId($value) */ public function getItemState() { - if (!$this->isPropertyAvailable("ItemState")) { - return null; - } return $this->getProperty("ItemState"); } /** @@ -249,9 +234,6 @@ public function setItemState($value) */ public function getItemType() { - if (!$this->isPropertyAvailable("ItemType")) { - return null; - } return $this->getProperty("ItemType"); } /** @@ -302,9 +284,6 @@ public function setLeafName($value) */ public function getSize() { - if (!$this->isPropertyAvailable("Size")) { - return null; - } return $this->getProperty("Size"); } /** @@ -326,9 +305,6 @@ public function setSize($value) */ public function getTitle() { - if (!$this->isPropertyAvailable("Title")) { - return null; - } return $this->getProperty("Title"); } /** @@ -349,10 +325,8 @@ public function setTitle($value) */ public function getAuthor() { - if (!$this->isPropertyAvailable("Author")) { - $this->setProperty("Author", new User($this->getContext(), new ResourcePath("Author", $this->getResourcePath()))); - } - return $this->getProperty("Author"); + return $this->getProperty("Author", + new User($this->getContext(), new ResourcePath("Author", $this->getResourcePath()))); } /** * Gets the email @@ -363,10 +337,8 @@ public function getAuthor() */ public function getDeletedBy() { - if (!$this->isPropertyAvailable("DeletedBy")) { - $this->setProperty("DeletedBy", new User($this->getContext(), new ResourcePath("DeletedBy", $this->getResourcePath()))); - } - return $this->getProperty("DeletedBy"); + return $this->getProperty("DeletedBy", + new User($this->getContext(), new ResourcePath("DeletedBy", $this->getResourcePath()))); } /** * Returns @@ -377,10 +349,7 @@ public function getDeletedBy() */ public function getDirNamePath() { - if (!$this->isPropertyAvailable("DirNamePath")) { - return null; - } - return $this->getProperty("DirNamePath"); + return $this->getProperty("DirNamePath", new SPResourcePath()); } /** * Returns @@ -402,10 +371,7 @@ public function setDirNamePath($value) */ public function getLeafNamePath() { - if (!$this->isPropertyAvailable("LeafNamePath")) { - return null; - } - return $this->getProperty("LeafNamePath"); + return $this->getProperty("LeafNamePath", new SPResourcePath()); } /** * Returns diff --git a/src/Teams/ShiftItem.php b/src/Teams/ShiftItem.php index 1d66815f..cb33d712 100644 --- a/src/Teams/ShiftItem.php +++ b/src/Teams/ShiftItem.php @@ -5,8 +5,8 @@ */ namespace Office365\Teams; -use Office365\Runtime\ClientValue; -class ShiftItem extends ClientValue + +class ShiftItem extends ScheduleEntity { /** * @var string diff --git a/src/Teams/Team.php b/src/Teams/Team.php index 27107c43..f455a976 100644 --- a/src/Teams/Team.php +++ b/src/Teams/Team.php @@ -6,6 +6,8 @@ namespace Office365\Teams; use Office365\Entity; +use Office365\Runtime\Http\RequestOptions; + /** * "A team in Microsoft Teams is a collection of channels. " @@ -113,7 +115,7 @@ public function setMessagingSettings($value) */ public function getFunSettings() { - return $this->getProperty("FunSettings"); + return $this->getProperty("FunSettings", new TeamFunSettings()); } /** @@ -126,4 +128,18 @@ public function setFunSettings($value) { return $this->setProperty("FunSettings", $value, true); } + + /** + * Deletes a Team + * @return Team + */ + public function deleteObject() + { + parent::deleteObject(); + $this->getContext()->getPendingRequest()->beforeExecuteRequestOnce(function (RequestOptions $request){ + $request->Url = str_replace ( "teams" , "groups", $request->Url ); + }); + return $this; + } + } \ No newline at end of file diff --git a/tests/outlookservices/OutlookMailTest.php b/tests/outlookservices/OutlookMailTest.php index f09f80f4..2eb751d8 100644 --- a/tests/outlookservices/OutlookMailTest.php +++ b/tests/outlookservices/OutlookMailTest.php @@ -93,6 +93,7 @@ public function testGetMessage(Message $message){ //verify $foundMessage = self::$graphClient->getMe()->getMessages()->getById($message->getId())->get()->executeQuery(); self::assertNotNull($foundMessage); + self::assertInstanceOf(Message::class, $foundMessage); } diff --git a/tests/teams/TeamsTest.php b/tests/teams/TeamsTest.php index e8391aa4..6d4723da 100644 --- a/tests/teams/TeamsTest.php +++ b/tests/teams/TeamsTest.php @@ -3,7 +3,9 @@ namespace Office365; +use Office365\Runtime\Http\RequestException; use Office365\Teams\Team; +use Office365\Teams\TeamGuestSettings; class TeamsTest extends GraphTestCase { @@ -31,12 +33,46 @@ public function testCreateTeam() /** * @depends testCreateTeam * @param Team $team + * @return Team + * @throws \Exception + */ + public function testGetTeam(Team $team) + { + /** @var Team $team */ + $team = self::$graphClient->getTeams()->getById($team->getId())->get()->executeQueryRetry(); + self::assertNotNull($team->getResourcePath()); + self::assertInstanceOf(Team::class, $team); + return $team; + } + + /** + * @depends testGetTeam + * @param Team $team + * @throws \Exception + */ + public function testUpdateTeam(Team $team) + { + $settings = new TeamGuestSettings(); + $settings->AllowDeleteChannels = true; + $team->setGuestSettings($settings)->update()->executeQuery(); + self::assertNotNull($team->getResourcePath()); + } + + /** + * @depends testGetTeam + * @param Team $team * @throws \Exception */ public function testDeleteTeam(Team $team) { - $teamToDel = $team->get()->executeQueryRetry(); - $teamToDel->deleteObject()->executeQuery(); + $deletedId = $team->getId(); + $team->deleteObject()->executeQuery(); + try { + self::$graphClient->getGroups()->getById($deletedId)->get()->executeQuery(); + } + catch (RequestException $ex){ + self::assertEquals(404, $ex->getCode()); + } } } \ No newline at end of file