Skip to content

Commit

Permalink
#103 : fix for properly encode whitespaces once list & view is refere…
Browse files Browse the repository at this point in the history
…nced by title
  • Loading branch information
vgrem committed Apr 18, 2018
1 parent 3318c78 commit 17b36ff
Show file tree
Hide file tree
Showing 24 changed files with 262 additions and 114 deletions.
35 changes: 0 additions & 35 deletions examples/GraphConsole/ClientApp.php

This file was deleted.

54 changes: 54 additions & 0 deletions examples/GraphConsole/ConsoleTasks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php


use Office365\PHP\Client\GraphClient\GraphServiceClient;
use Office365\PHP\Client\Runtime\Auth\AuthenticationContext;
use Office365\PHP\Client\Runtime\Auth\OAuthTokenProvider;
use Office365\PHP\Client\Runtime\Utilities\UserCredentials;

require_once '../bootstrap.php';

try
{
$client = getAuthenticatedClient();
//downloadPhoto($client,"./myprofile.jpg");
getDriveInfo($client);

}
catch (Exception $e) {
echo 'Error: ', $e->getMessage(), "\n";
}


function getDriveInfo(GraphServiceClient $client){
$drive = $client->getMe()->getDrive();
$client->load($drive);
$client->executeQuery();
print $drive->getProperty("webUrl");
}


function downloadPhoto(GraphServiceClient $client,$targetFilePath){
$fp = fopen($targetFilePath, 'w+');
//$url = $client->getServiceRootUrl() . "me/photo\$value";
$url = $client->getServiceRootUrl() . "me/photo";
$options = new \Office365\PHP\Client\Runtime\Utilities\RequestOptions($url);
//$options->StreamHandle = $fp;
$content = $client->executeQueryDirect($options);
fclose($fp);
}


function getAuthenticatedClient(){
global $AppSettings;
global $Settings;
$resource = "https://graph.microsoft.com";
$authorityUrl = OAuthTokenProvider::$AuthorityUrl . $AppSettings['TenantName'];
$authCtx = new AuthenticationContext($authorityUrl);
$authCtx->acquireTokenForUserCredential($resource,$AppSettings['ClientId'],new UserCredentials($Settings['UserName'],$Settings['Password']));
$client = new GraphServiceClient($authCtx);
return $client;
}



9 changes: 6 additions & 3 deletions examples/GraphExplorer/ProcessQuery.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
use Office365\PHP\Client\GraphClient\ActiveDirectoryClient;
use Office365\PHP\Client\GraphClient\GraphServiceClient;
use Office365\PHP\Client\Runtime\Utilities\RequestOptions;

require_once '../bootstrap.php';
Expand All @@ -14,11 +14,14 @@
if (isset($_GET['text'])) {
$requestUrl = $_GET['text'];
$authorityUrl = "https://graph.windows.net/";
$client = new ActiveDirectoryClient($authorityUrl,$_SESSION['auth_ctx']);
$client = new GraphServiceClient($_SESSION['auth_ctx']);
$request = new RequestOptions($requestUrl);
//$request->Url .= "?api-version=1.0";
$request->Url .= "?api-version=beta";
$response = $client->executeQueryDirect($request);
try {
$response = $client->executeQueryDirect($request);
} catch (Exception $e) {
}
echo $response;
}
else
Expand Down
12 changes: 6 additions & 6 deletions examples/Settings.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

$Settings = array(
'Url' => "https://mediadev20.sharepoint.com/sites/contoso",
'OneDriveUrl' => "https://mediadev20-my.SharePoint.com",
'Url' => "https://mediadev23.sharepoint.com",
'OneDriveUrl' => "https://mediadev23-my.SharePoint.com",
'Password' => "P@ssw0rd",
'UserName' => "mattim@mediadev20.onmicrosoft.com"
'UserName' => "mattim@mediadev23.onmicrosoft.com"
);

$AppSettings = array(
'TenantName' => "mediadev20.onmicrosoft.com",
'ClientId' => "13d4cd98-1761-4416-b01c-a641c08d0737",
'ClientSecret' => "oYM9GUiE4uejyaQ0GuuHj7U",
'TenantName' => "mediadev23.onmicrosoft.com",
'ClientId' => "d426369e-c84b-47db-b6b1-b9c824ac2ea2",
'ClientSecret' => "wrizJBW41]|=@govNEDR059",
'Title' => "Office365 Graph explorer",
'RedirectUrl' => "http://localhost:8078/GraphExplorer/SignIn.php"
);
Expand Down
10 changes: 9 additions & 1 deletion examples/SharePoint/file_examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@
$targetLibraryTitle = "Documents";
$targetFolderUrl = "/sites/contoso/Documents/Archive/2017/08";

$list = ListExtensions::ensureList($ctx->getWeb(),$targetLibraryTitle, \Office365\PHP\Client\SharePoint\ListTemplateType::DocumentLibrary);
//$list = ListExtensions::ensureList($ctx->getWeb(),$targetLibraryTitle, \Office365\PHP\Client\SharePoint\ListTemplateType::DocumentLibrary);


$fileUrl = "/sites/contoso/Shared Documents/Guide #123.docx";
$file = $ctx->getWeb()->getFileByServerRelativeUrl($fileUrl);
$ctx->load($file);
$ctx->executeQuery();


$folderUrl = "Shared Documents";
$fileUrl = "Guide #123.docx";
Expand Down Expand Up @@ -58,6 +65,7 @@ function createSubFolder(ClientContext $ctx,$parentFolderUrl,$folderName){
$ctx->load($files);
$ctx->executeQuery();
//print files info
/* @var $file \Office365\PHP\Client\SharePoint\File */
foreach ($files->getData() as $file) {
print "File name: '{$file->getProperty("ServerRelativeUrl")}'\r\n";
}
Expand Down
8 changes: 8 additions & 0 deletions examples/SharePoint/list_examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
$ctx = new ClientContext($Settings['Url'],$authCtx);


$listTitle = 'Archive 2017';
//$listTitle = 'Archive%202017';
$list = $ctx->getWeb()->getLists()->getByTitle($listTitle);
$ctx->load($list);
$ctx->executeQuery();

echo $list->getProperty('Title');

$listTitle = "Orders_" . rand(1,1000);
//$listTitle = "Tasks" ;

Expand Down
1 change: 1 addition & 0 deletions examples/SharePoint/web_examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
global $Settings;

try {

$authCtx = new AuthenticationContext($Settings['Url']);
$authCtx->acquireTokenForUser($Settings['UserName'],$Settings['Password']);

Expand Down
58 changes: 0 additions & 58 deletions src/GraphClient/ActiveDirectoryClient.php

This file was deleted.

44 changes: 44 additions & 0 deletions src/GraphClient/GraphServiceClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Office365\PHP\Client\GraphClient;

use Office365\PHP\Client\OneDrive\CurrentUserRequestContext;
use Office365\PHP\Client\Runtime\Auth\IAuthenticationContext;
use Office365\PHP\Client\Runtime\ClientAction;
use Office365\PHP\Client\Runtime\ClientRuntimeContext;
use Office365\PHP\Client\Runtime\OData\JsonFormat;
use Office365\PHP\Client\Runtime\OData\ODataMetadataLevel;
use Office365\PHP\Client\Runtime\Office365Version;
use Office365\PHP\Client\Runtime\ResourcePathEntity;
use Office365\PHP\Client\Runtime\Utilities\RequestOptions;

class GraphServiceClient extends ClientRuntimeContext
{
public function __construct(IAuthenticationContext $authContext)
{
$serviceRootUrl = "https://graph.microsoft.com/" . Office365Version::V1 . "/";
parent::__construct($serviceRootUrl, $authContext,new JsonFormat(ODataMetadataLevel::Verbose));
}


public function executeQuery()
{
$this->getPendingRequest()->beforeExecuteQuery(function (RequestOptions $request,ClientAction $query){
});
parent::executeQuery();
}

/**
* @return CurrentUserRequestContext
*/
public function getMe(){
if(!isset($this->me))
$this->me = new CurrentUserRequestContext($this,new ResourcePathEntity($this,null,"me"));
return $this->me;
}





}
4 changes: 2 additions & 2 deletions src/OneDrive/Drive.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function getOwner(){
* @param string $value
*/
public function setOwner($value){
return $this->setProperty("owner",$value);
$this->setProperty("owner",$value);
}


Expand All @@ -49,7 +49,7 @@ public function getFiles(){
* @param string $value
*/
public function setFiles($value){
return $this->setProperty("files",$value);
$this->setProperty("files",$value);
}

}
4 changes: 1 addition & 3 deletions src/Runtime/Auth/AuthenticationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,14 @@ public function exchangeRefreshToken($resource, $clientId, $clientSecret, $refre
/**
* @param string $resource
* @param string $clientId
* @param string $clientSecret
* @param UserCredentials $credentials
*/
public function acquireTokenForUserCredential($resource, $clientId, $clientSecret, $credentials)
public function acquireTokenForUserCredential($resource, $clientId, $credentials)
{
$this->provider = new OAuthTokenProvider($this->authorityUrl);
$parameters = array(
'grant_type' => 'password',
'client_id' => $clientId,
'client_secret' => $clientSecret,
'username' => $credentials->Username,
'password' => $credentials->Password,
'scope' => 'openid',
Expand Down
1 change: 1 addition & 0 deletions src/Runtime/ClientRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public function addQueryAndResultObject(ClientObject $clientObject, ODataQueryOp
* @param RequestOptions $request
* @param array $responseInfo
* @return string
* @throws \Exception
*/
public function executeQueryDirect(RequestOptions $request,&$responseInfo=array())
{
Expand Down
15 changes: 15 additions & 0 deletions src/Runtime/ClientRuntimeContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Office365\PHP\Client\Runtime\OData\ODataFormat;
use Office365\PHP\Client\Runtime\OData\ODataQueryOptions;
use Office365\PHP\Client\Runtime\Utilities\RequestOptions;
use Office365\PHP\Client\Runtime\Utilities\Version;


/**
* OData Runtime context for Office365 APIs
Expand Down Expand Up @@ -40,6 +42,12 @@ class ClientRuntimeContext
*/
public $Format;


/**
* @var Version $RequestSchemaVersion
*/
public $RequestSchemaVersion;

/**
* REST client context ctor
* @param string $serviceUrl
Expand Down Expand Up @@ -137,6 +145,7 @@ public function executeQuery()
/**
* @param RequestOptions $options
* @return string
* @throws \Exception
*/
public function executeQueryDirect(RequestOptions $options)
{
Expand Down Expand Up @@ -176,5 +185,11 @@ public function getPendingRequest()
return $this->pendingRequest;
}

/**
* @return Version
*/
public function getServerLibraryVersion(){
return new Version();
}

}
Loading

0 comments on commit 17b36ff

Please sign in to comment.